Skip to content

Commit 26cf85d

Browse files
authored
Merge pull request #1082 from solarwinds/generateKubernetesServiceRoutesToRelations
Generate `KubernetesServiceRoutesTo` relations
2 parents 24e2723 + e46f255 commit 26cf85d

15 files changed

+1042
-148
lines changed

deploy/helm/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
name: swo-k8s-collector
3-
version: 4.8.0-alpha.4
4-
appVersion: 0.127.5
3+
version: 4.8.0-alpha.5
4+
appVersion: 0.127.7
55
description: SolarWinds Kubernetes Integration
66
keywords:
77
- monitoring

deploy/helm/events-collector-config.yaml

Lines changed: 154 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"clusterroles" "ClusterRole"
1919
"clusterrolebindings" "ClusterRoleBinding"
2020
"serviceaccounts" "ServiceAccount"
21+
"endpoints" "Endpoints"
22+
"endpointslices" "EndpointSlice"
2123

2224
}}
2325
{{- $arrayOfWatchedResources := keys $resourceMap | sortAlpha }}
@@ -41,6 +43,7 @@ exporters:
4143
storage: file_storage/sending_queue
4244
{{- end }}
4345
timeout: {{ .Values.otel.events.timeout }}
46+
4447
extensions:
4548
{{- if .Values.otel.events.sending_queue.offload_to_disk }}
4649
file_storage/sending_queue:
@@ -128,12 +131,83 @@ connectors:
128131
- sw.k8s.cluster.uid
129132
- k8s.namespace.name
130133
- k8s.service.name
131-
- entity: KubernetesStatefulSet
134+
- entity: KubernetesStatefulSet
132135
id:
133136
- sw.k8s.cluster.uid
134137
- k8s.namespace.name
135138
- k8s.statefulset.name
136139
{{- end }}
140+
solarwindsentity/serviceendpointsmapping:
141+
source_prefix: "source."
142+
destination_prefix: "dest."
143+
schema:
144+
entities:
145+
- entity: KubernetesService
146+
id:
147+
- sw.k8s.cluster.uid
148+
- k8s.namespace.name
149+
- k8s.service.name
150+
- entity: KubernetesDaemonSet
151+
id:
152+
- sw.k8s.cluster.uid
153+
- k8s.namespace.name
154+
- k8s.daemonset.name
155+
- entity: KubernetesDeployment
156+
id:
157+
- sw.k8s.cluster.uid
158+
- k8s.namespace.name
159+
- k8s.deployment.name
160+
- entity: KubernetesStatefulSet
161+
id:
162+
- sw.k8s.cluster.uid
163+
- k8s.namespace.name
164+
- k8s.statefulset.name
165+
- entity: KubernetesReplicaSet
166+
id:
167+
- sw.k8s.cluster.uid
168+
- k8s.namespace.name
169+
- k8s.replicaset.name
170+
events:
171+
relationships:
172+
- type: KubernetesServiceRoutesTo
173+
source_entity: KubernetesService
174+
destination_entity: KubernetesDaemonSet
175+
conditions: []
176+
context: "log"
177+
attributes: []
178+
action: "update"
179+
- type: KubernetesServiceRoutesTo
180+
source_entity: KubernetesService
181+
destination_entity: KubernetesDeployment
182+
conditions: []
183+
context: "log"
184+
attributes: []
185+
action: "update"
186+
- type: KubernetesServiceRoutesTo
187+
source_entity: KubernetesService
188+
destination_entity: KubernetesStatefulSet
189+
conditions: []
190+
context: "log"
191+
attributes: []
192+
action: "update"
193+
- type: KubernetesServiceRoutesTo
194+
source_entity: KubernetesService
195+
destination_entity: KubernetesReplicaSet
196+
conditions: []
197+
context: "log"
198+
attributes: []
199+
action: "update"
200+
201+
routing/manifests:
202+
default_pipelines: [logs/manifests-export]
203+
table:
204+
- context: resource
205+
pipelines:
206+
- logs/serviceendpointsmapping
207+
condition: |
208+
attributes["sw.k8s.log.type"] == "serviceendpointsmapping"
209+
210+
forward/exportserviceendpointsmapping: {}
137211

138212
processors:
139213
k8seventgeneration:
@@ -277,8 +351,12 @@ processors:
277351
{{- range $index, $resourceName := $arrayOfWatchedResources }}
278352
{{- $resourceKind := get $resourceMap $resourceName }}
279353
{{- $prefix := lower $resourceKind }}
280-
- set(log.attributes["k8s.{{$prefix}}.name"], log.body["metadata"]["name"]) where log.body["kind"] == "{{$resourceKind}}"
354+
- set(log.attributes["k8s.{{$prefix}}.name"], log.body["metadata"]["name"]) where log.body["metadata"]["name"] != nil and log.body["kind"] == "{{$resourceKind}}"
281355
{{- end }}
356+
# rename k8s.endpoints.name to k8s.endpoint.name if exists
357+
- set(log.attributes["k8s.endpoint.name"], log.attributes["k8s.endpoints.name"]) where log.attributes["k8s.endpoints.name"] != nil
358+
- delete_key(log.attributes, "k8s.endpoints.name") where log.attributes["k8s.endpoints.name"] != nil
359+
282360
- set(log.attributes["k8s.namespace.name"], log.body["metadata"]["namespace"])
283361
- set(log.attributes["k8s.ingress.name"], log.body["metadata"]["name"]) where log.body["kind"] == "Ingress" or log.body["kind"] == "VirtualService"
284362
- set(log.attributes["sw.k8s.ingress.type"], log.body["kind"]) where log.body["kind"] == "Ingress" or log.body["kind"] == "VirtualService"
@@ -289,6 +367,33 @@ processors:
289367
- delete_key(log.attributes, "k8s.resource.name")
290368
- delete_key(log.attributes, "event.name")
291369
- delete_key(log.attributes, "event.domain")
370+
371+
groupbyattrs/serviceendpointsmapping:
372+
keys:
373+
- sw.k8s.cluster.uid
374+
- sw.k8s.workload.ip
375+
- k8s.service.name
376+
- k8s.namespace.name
377+
378+
transform/serviceendpointsmapping-renamepodip:
379+
error_mode: ignore
380+
log_statements:
381+
- statements:
382+
- set(resource.attributes["k8s.pod.ip"], resource.attributes["sw.k8s.workload.ip"]) where resource.attributes["sw.k8s.log.type"] == "serviceendpointsmapping" and resource.attributes["sw.k8s.workload.ip"] != nil
383+
384+
transform/serviceendpointsmapping:
385+
error_mode: ignore
386+
log_statements:
387+
- statements:
388+
- set(resource.attributes["source.k8s.service.name"], resource.attributes["k8s.service.name"]) where resource.attributes["k8s.service.name"] != nil
389+
- set(resource.attributes["source.k8s.namespace.name"], resource.attributes["k8s.namespace.name"]) where resource.attributes["k8s.namespace.name"] != nil
390+
391+
- set(resource.attributes["dest.k8s.namespace.name"], resource.attributes["k8s.namespace.name"]) where resource.attributes["k8s.namespace.name"] != nil
392+
- set(resource.attributes["dest.k8s.deployment.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil
393+
- set(resource.attributes["dest.k8s.statefulset.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.statefulset.name"] != nil
394+
- set(resource.attributes["dest.k8s.replicaset.name"], resource.attributes["k8s.replicaset.name"]) where resource.attributes["k8s.replicaset.name"] != nil
395+
- set(resource.attributes["dest.k8s.daemonset.name"], resource.attributes["k8s.daemonset.name"]) where resource.attributes["k8s.daemonset.name"] != nil
396+
292397
transform/scope:
293398
log_statements:
294399
- statements:
@@ -316,6 +421,8 @@ processors:
316421
- k8s.clusterrole.name
317422
- k8s.clusterrolebinding.name
318423
- k8s.serviceaccount.name
424+
- k8s.endpoint.name
425+
- k8s.endpointslice.name
319426

320427
resource/events:
321428
attributes:
@@ -431,6 +538,18 @@ processors:
431538
k8sattributes:
432539
{{ include "common.k8s-instrumentation" . | indent 4 }}
433540

541+
logdedup/entitystateevents:
542+
interval: {{ quote .Values.otel.manifests.pull_every }}
543+
conditions:
544+
- instrumentation_scope.attributes["otel.entity.event_as_log"] == true
545+
include_fields:
546+
- attributes.otel.entity.event.type
547+
- attributes.otel.entity_relationship.source_entity.id
548+
- attributes.otel.entity_relationship.destination_entity.id
549+
- attributes.otel.entity_relationship.type
550+
- attributes.otel.entity_relationship.source_entity.type
551+
- attributes.otel.entity_relationship.destination_entity.type
552+
434553
receivers:
435554
k8s_events:
436555
{{- $root := . }}
@@ -517,6 +636,7 @@ service:
517636
exporters:
518637
- otlp
519638
{{- end }}
639+
520640
logs/manifests:
521641
receivers:
522642
- swok8sobjects
@@ -525,26 +645,47 @@ service:
525645
- transform/manifest
526646
- groupbyattrs/manifest
527647
- transform/set_labels_and_annotations_for_entities
648+
{{- if not (and .Values.otel.events.enabled .Values.otel.manifests.enabled) }}
649+
- filter/k8s_collector_config_include
650+
{{- end }}
528651
- transform/extract_resource_attrs_from_manifests
529652
- transform/stringify_body
530653
- resource/manifest
531654
- resourcedetection/providers
532-
- k8sattributes
533655
- k8seventgeneration
534-
{{- if not (and .Values.otel.events.enabled .Values.otel.manifests.enabled) }}
535-
- filter/k8s_collector_config_include
536-
{{- end }}
656+
- groupbyattrs/serviceendpointsmapping
657+
- transform/serviceendpointsmapping-renamepodip
658+
- k8sattributes
537659
{{- if eq (include "isNamespacesFilterEnabled" .) "true" }}
538660
- filter/namespaces
539-
{{- end }}
661+
{{- end }}
540662
{{- if .Values.otel.manifests.filter }}
541663
- filter/manifests
542664
{{- end }}
665+
exporters:
666+
- routing/manifests
667+
668+
logs/serviceendpointsmapping:
669+
receivers:
670+
- routing/manifests
671+
processors:
672+
- memory_limiter
673+
- transform/serviceendpointsmapping
674+
exporters:
675+
- solarwindsentity/serviceendpointsmapping
676+
677+
logs/manifests-export:
678+
receivers:
679+
- routing/manifests
680+
- solarwindsentity/serviceendpointsmapping
681+
processors:
682+
- memory_limiter
683+
- logdedup/entitystateevents
543684
- transform/scope
544685
- batch
545686
exporters:
546687
- otlp
547-
688+
548689
{{- if and .Values.otel.manifests.enabled .Values.otel.manifests.keepalive_events.enabled }}
549690
logs/manifests-keepalive:
550691
receivers:
@@ -553,15 +694,15 @@ service:
553694
- memory_limiter
554695
- transform/manifest
555696
- groupbyattrs/manifest
556-
- resource/manifest
557-
- k8sattributes
558-
- k8seventgeneration
559697
{{- if not (and .Values.otel.events.enabled .Values.otel.manifests.enabled) }}
560698
- filter/k8s_collector_config_include
561699
{{- end }}
700+
- resource/manifest
701+
- k8sattributes
702+
- k8seventgeneration
562703
{{- if eq (include "isNamespacesFilterEnabled" .) "true" }}
563704
- filter/namespaces
564-
{{- end }}
705+
{{- end }}
565706
{{- if .Values.otel.manifests.filter }}
566707
- filter/manifests
567708
{{- end }}
@@ -578,7 +719,7 @@ service:
578719
exporters:
579720
- otlp
580721
{{- end }}
581-
722+
582723
telemetry:
583724
{{- if .Values.otel.events.telemetry.logs.enabled }}
584725
logs:

deploy/helm/gateway-collector-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ connectors:
539539
- sw.server.address.fqdn
540540
events:
541541
entities:
542-
- type: "PublicNetworkLocation"
542+
- entity: "PublicNetworkLocation"
543543
context: "metric"
544544
action: "update"
545545

deploy/helm/templates/_common-discovery-config.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ solarwindsentity/istio-workload-service:
460460
- sw.server.address.fqdn
461461
events:
462462
entities:
463-
- type: "PublicNetworkLocation"
463+
- entity: "PublicNetworkLocation"
464464
context: "metric"
465465
action: "update"
466466
relationships:

deploy/helm/templates/_helpers.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ auth_type: "serviceAccount"
137137
passthrough: false
138138
extract:
139139
metadata:
140+
- k8s.pod.name
140141
- k8s.deployment.name
141142
- k8s.replicaset.name
142143
- k8s.daemonset.name
@@ -150,6 +151,11 @@ pod_association:
150151
name: k8s.pod.name
151152
- from: resource_attribute
152153
name: k8s.namespace.name
154+
- sources:
155+
- from: resource_attribute
156+
name: k8s.pod.ip
157+
- from: resource_attribute
158+
name: k8s.namespace.name
153159
{{- end -}}
154160

155161
{{/*

deploy/helm/templates/cluster-role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ rules:
9797
- get
9898
- list
9999
- watch
100+
- apiGroups:
101+
- "discovery.k8s.io"
102+
resources:
103+
- endpointslices
104+
verbs:
105+
- get
106+
- list
107+
- watch
100108
- nonResourceURLs:
101109
- /metrics
102110
verbs:

deploy/helm/tests/__snapshot__/discovery-collector_test.yaml.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Discovery collector spec should match snapshot when using default values:
8282
entities:
8383
- action: update
8484
context: metric
85-
type: PublicNetworkLocation
85+
entity: PublicNetworkLocation
8686
relationships:
8787
- action: update
8888
attributes:

0 commit comments

Comments
 (0)