@@ -26,6 +26,30 @@ interface ApiConfig {
26
26
environmentUrl : string ;
27
27
}
28
28
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
+
29
53
export const isValidDynatraceQueryKey = (
30
54
key : string ,
31
55
) : key is DynatraceQueryKeys => key in dynatraceQueries ;
@@ -70,7 +94,9 @@ export const dynatraceQueries: Record<
70
94
| sort upper(name) asc
71
95
| lookup [fetch dt.entity.kubernetes_cluster, from: -10m | fields id, clusterName = entity.name],sourceField:cluster.id, lookupField:id, fields:{clusterName}
72
96
| 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)})
74
100
| fieldsAdd Cluster = clusterName, Namespace = namespaceName
75
101
| fieldsRemove clusterName, namespaceName
76
102
| 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<
80
106
${ filterKubernetesId }
81
107
${ filterNamespace }
82
108
${ 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
+ ) } })
88
113
| fieldsRemove id, name, workload.labels, cluster.id, namespace.id
89
114
| fieldsAdd Environment = "${ apiConfig . environmentName } "` ;
90
115
} ,
0 commit comments