Skip to content

Add logs header details

Anna Vovchenko requested to merge anna/add-logs-header-details into master

What does this MR do and why?

This MR adds a details header to the logs viewer for the Kubernetes pods logs. It shows the pod name, namespace and container name (if provided).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
Screenshot_2024-06-07_at_17.23.34 Screenshot_2024-06-07_at_17.29.28
Screenshot_2024-06-11_at_11.55.20 Screenshot_2024-06-11_at_11.54.03

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Easy validation (without the agent and cluster setup)

  1. Navigate to Project -> Operate -> Environments and create an environment
  2. Navigate to https://gdk.test:3443/<group>/<project>/-/environments/<environment_id>/k8s/namespace/my-namespace/pods/my-pod/logs?container=my-container
  3. Apply this patch (copy and pbpaste | git apply)
Patch
diff --git a/app/assets/javascripts/environments/environment_details/components/kubernetes/kubernetes_logs.vue b/app/assets/javascripts/environments/environment_details/components/kubernetes/kubernetes_logs.vue
index 39a42e570b6d..36cbb5d4328e 100644
--- a/app/assets/javascripts/environments/environment_details/components/kubernetes/kubernetes_logs.vue
+++ b/app/assets/javascripts/environments/environment_details/components/kubernetes/kubernetes_logs.vue
@@ -84,6 +84,7 @@ export default {
       return this.k8sLogs?.error?.message || this.environmentError?.message;
     },
     gitlabAgentId() {
+      return '1';
       return (
         this.environment?.clusterAgent?.id &&
         getIdFromGraphQLId(this.environment.clusterAgent.id).toString()
diff --git a/app/assets/javascripts/environments/graphql/resolvers/kubernetes/k8s_logs.js b/app/assets/javascripts/environments/graphql/resolvers/kubernetes/k8s_logs.js
index fe1ffc388301..11fdc61d5894 100644
--- a/app/assets/javascripts/environments/graphql/resolvers/kubernetes/k8s_logs.js
+++ b/app/assets/javascripts/environments/graphql/resolvers/kubernetes/k8s_logs.js
@@ -58,6 +58,20 @@ export const k8sLogs = (_, { configuration, namespace, podName, containerName },
   const watchQuery = { follow: true };
   if (containerName) watchQuery.container = containerName;
 
+  const testLogsData = [
+    {
+      id: 1,
+      content:
+        '{"level":"info","ts":"2024-06-10T11:58:54.533Z","logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":8080"}',
+    },
+    {
+      id: 2,
+      content:
+        '{"level":"info","ts":"2024-06-10T11:58:54.534Z","logger":"setup","msg":"starting manager"}',
+    },
+  ];
+  cacheWrapper.writeLogsData(testLogsData);
+
   watchApi
     .subscribeToStream(watchPath, watchQuery)
     .then((watcher) => {
@@ -65,7 +79,6 @@ export const k8sLogs = (_, { configuration, namespace, podName, containerName },
         const logsData = cacheWrapper.readLogsData();
 
         const updatedLogsData = [...logsData, { id: logsData.length + 1, content: data }];
-
         cacheWrapper.writeLogsData(updatedLogsData);
       });
 
@@ -73,9 +86,9 @@ export const k8sLogs = (_, { configuration, namespace, podName, containerName },
         cacheWrapper.writeErrorData(err);
       });
 
-      watcher.on(EVENT_ERROR, (err) => {
-        cacheWrapper.writeErrorData(err);
-      });
+      // watcher.on(EVENT_ERROR, (err) => {
+      //   cacheWrapper.writeErrorData(err);
+      // });
     })
     .catch((err) => {
       cacheWrapper.writeErrorData(err);

Validate with real data

Prerequisites:

  1. Visit the Project -> Infrastructure -> Kubernetes clusters page and create an agent following the instructions from the modal.

    • Select the "Connect a cluster" button
    • The modal should pop up
    • In the modal select "Select an agent or enter a name to create new"
    • You probably won't have any configured agents to show up in the list, create a new one by typing the name of your choice
    • The button should appear at the bottom of the list saying "Create agent: <your-agent-name>"
    • Select the button and click "Register" in the next view.
    • Save the token to use it in the next point.
  2. Add the following configuration inside your project in .gitlab/agents/<your-agent-name>/config.yaml for the user_access agent:

    user_access:
      access_as: 
        agent: {}
      projects:
      - id: <your-group>/<your-project-to-share-agent-with>
  3. Note that the shared agents should be connected to the cluster in order to appear in the list. Please follow points 3-8 from the guide and then the Deploy the GitLab Agent (agentk) with k3d section to create a local cluster and connect your agent with the cluster.

  4. Visit Project -> Operate -> Environments

  5. Create/Edit an environment using the UI

  6. Select an agent from the dropdown in the Environments settings page and save the change.

  7. Visit the Environments page and visit the environment details page for the environment that has an associated agent.

  8. Navigate to https://gdk.test:3443/<group-name>/<project-name>/-/environments/<environment-id>/k8s/namespace/<namespace-name>/pods/<pod-name>/logs?container=<container-name> and validate the header of the logs viewer.

Related to &13793 (closed)

Edited by Anna Vovchenko

Merge request reports