Add logs header details
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 |
---|---|
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)
- Navigate to Project -> Operate -> Environments and create an environment
- Navigate to
https://gdk.test:3443/<group>/<project>/-/environments/<environment_id>/k8s/namespace/my-namespace/pods/my-pod/logs?container=my-container
- 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:
- NGINX, loopback interface, and HTTPS set up on your GDK
- Docker instance
- KAS enabled on GDK (steps 1-2 from the guide).
-
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.
-
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>
-
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.
-
Visit Project -> Operate -> Environments
-
Create/Edit an environment using the UI
-
Select an agent from the dropdown in the Environments settings page and save the change.
-
Visit the Environments page and visit the environment details page for the environment that has an associated agent.
-
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)