Skip to content

Commit ea653a7

Browse files
authored
chore: align Kubernetes log DQL (#168)
1 parent d602fa7 commit ea653a7

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

plugins/dql-backend/src/service/queries.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ interface ApiConfig {
2626
environmentUrl: string;
2727
}
2828

29+
const getKubernetesLogLink = (idField: string, apiConfig: ApiConfig) => {
30+
// Resulting DQL:
31+
// fetch logs
32+
// | filter dt.entity.cloud_application == "CLOUD_APPLICATION-XY" or in(dt.entity.cloud_application, "CLOUD_APPLICATION-XY") or in(dt.entity.cloud_application_instance, classicEntitySelector("type(CLOUD_APPLICATION_INSTANCE),fromRelationShip.IS_INSTANCE_OF(type(CLOUD_APPLICATION),entityId(\"CLOUD_APPLICATION-XY\"))"))
33+
// | sort timestamp desc
34+
const concatArray = [
35+
`concat("${apiConfig.environmentUrl}"`,
36+
`"/ui/apps/dynatrace.notebooks/intent/view-query#${encodeURIComponent(
37+
'{"dt.query":"fetch logs\\n| filter dt.entity.cloud_application == \\"',
38+
)}"`,
39+
idField,
40+
`"${encodeURIComponent('\\" or in(dt.entity.cloud_application, \\"')}"`,
41+
idField,
42+
`"${encodeURIComponent(
43+
'\\") or in(dt.entity.cloud_application_instance, classicEntitySelector(\\"type(CLOUD_APPLICATION_INSTANCE),fromRelationShip.IS_INSTANCE_OF(type(CLOUD_APPLICATION),entityId(\\\\\\"',
44+
)}"`,
45+
idField,
46+
`"${encodeURIComponent(
47+
'\\\\\\"))\\"))\\n| sort timestamp desc","title":"Logs"}',
48+
)}")`,
49+
];
50+
return concatArray.join(',');
51+
};
52+
2953
export const isValidDynatraceQueryKey = (
3054
key: string,
3155
): key is DynatraceQueryKeys => key in dynatraceQueries;
@@ -70,7 +94,9 @@ export const dynatraceQueries: Record<
7094
| sort upper(name) asc
7195
| lookup [fetch dt.entity.kubernetes_cluster, from: -10m | fields id, clusterName = entity.name],sourceField:cluster.id, lookupField:id, fields:{clusterName}
7296
| lookup [fetch dt.entity.cloud_application_namespace, from: -10m | fields id, namespaceName = entity.name], sourceField:namespace.id, lookupField:id, fields:{namespaceName}
73-
| fieldsAdd Workload = record({type="link", text=name, url=concat("${apiConfig.environmentUrl}/ui/apps/dynatrace.kubernetes/resources/workload?entityId=", id, "&cluster=", clusterName, "&namespace=", namespaceName, "&workload=", name)})
97+
| fieldsAdd Workload = record({type="link", text=name, url=concat("${
98+
apiConfig.environmentUrl
99+
}/ui/apps/dynatrace.kubernetes/resources/workload?entityId=", id, "&cluster=", clusterName, "&namespace=", namespaceName, "&workload=", name)})
74100
| fieldsAdd Cluster = clusterName, Namespace = namespaceName
75101
| fieldsRemove clusterName, namespaceName
76102
| lookup [fetch events, from: -30m | filter event.kind == "DAVIS_PROBLEM" | fieldsAdd affected_entity_id = affected_entity_ids[0] | summarize collectDistinct(event.status), by:{display_id, affected_entity_id}, alias:problem_status | filter NOT in(problem_status, "CLOSED") | summarize Problems = count(), by:{affected_entity_id}], sourceField:id, lookupField:affected_entity_id, fields:{Problems}
@@ -80,11 +106,10 @@ export const dynatraceQueries: Record<
80106
${filterKubernetesId}
81107
${filterNamespace}
82108
${filterLabel}
83-
| fieldsAdd Logs = record({type="link", text="Show logs", url=concat(
84-
"${apiConfig.environmentUrl}",
85-
"/ui/apps/dynatrace.notebooks/intent/view-query#%7B%22dt.query%22%3A%22fetch%20logs%20%7C%20filter%20matchesValue(dt.entity.cloud_application%2C%5C%22",
86-
id,
87-
"%5C%22)%20%7C%20sort%20timestamp%20desc%22%2C%22title%22%3A%22Logs%22%7D")})
109+
| fieldsAdd Logs = record({type="link", text="Show logs", url=${getKubernetesLogLink(
110+
'id',
111+
apiConfig,
112+
)}})
88113
| fieldsRemove id, name, workload.labels, cluster.id, namespace.id
89114
| fieldsAdd Environment = "${apiConfig.environmentName}"`;
90115
},

0 commit comments

Comments
 (0)