Skip to content

Commit

Permalink
feat: extra OPTEL collector configuration.
Browse files Browse the repository at this point in the history
Adds additional telemetry configuration fields to allow users to add
their custom OpenTelemetry collector configuration together with the
Kubewarden configuration.

Signed-off-by: José Guilherme Vanz <[email protected]>
  • Loading branch information
jvanz committed Nov 6, 2024
1 parent e7b70b1 commit 543123e
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,39 @@ metadata:
{{- include "kubewarden-controller.annotations" . | nindent 4 }}
spec:
mode: sidecar
{{- if .Values.telemetry.extraOptelConfig.envFrom }}
envFrom:
{{- toYaml .Values.telemetry.extraOptelConfig.envFrom | nindent 4 }}
{{- end }}
{{- if .Values.telemetry.extraOptelConfig.presets }}
presets:
{{- toYaml .Values.telemetry.extraOptelConfig.presets | nindent 4 }}
{{- end }}
{{- if .Values.telemetry.extraOptelConfig.ports }}
ports:
{{- toYaml .Values.telemetry.extraOptelConfig.ports | nindent 4 }}
{{- end }}
config:
{{- if .Values.telemetry.extraConfig.extensions }}
extensions:
{{- toYaml .Values.telemetry.extraConfig.extensions | nindent 6}}
{{- end }}
{{- if .Values.telemetry.extraConfig.connectors }}
connectors:
{{- toYaml .Values.telemetry.extraConfig.connectors | nindent 6}}
{{- end }}
receivers:
otlp:
protocols:
grpc: {}
{{- if .Values.telemetry.extraConfig.receivers}}
{{- toYaml .Values.telemetry.extraConfig.receivers | nindent 6 }}
{{- end }}
processors:
batch: {}
{{- if .Values.telemetry.extraConfig.processors }}
{{- toYaml .Values.telemetry.extraConfig.processors | nindent 6 }}
{{- end }}
exporters:
{{- if and .Values.telemetry.tracing.enabled .Values.telemetry.tracing.jaeger.endpoint }}
otlp/jaeger:
Expand All @@ -32,8 +58,18 @@ spec:
prometheus:
endpoint: ":{{ .Values.telemetry.metrics.port }}"
{{- end }}
{{- if .Values.telemetry.extraConfig.exporters }}
{{ toYaml .Values.telemetry.extraConfig.exporters | nindent 6 }}
{{- end }}
service:
{{- if .Values.telemetry.extraConfig.service.extensions }}
extensions:
{{- toYaml .Values.telemetry.extraConfig.service.extensions | nindent 8 }}
{{- end }}
pipelines:
{{- if .Values.telemetry.extraConfig.service.pipelines }}
{{- toYaml .Values.telemetry.extraConfig.service.pipelines | nindent 8 }}
{{- end }}
{{- if and .Values.telemetry.metrics.enabled .Values.telemetry.metrics.port }}
metrics:
receivers: [otlp]
Expand Down
303 changes: 303 additions & 0 deletions charts/kubewarden-controller/tests/optel_collector_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
suite: OpenTelemetry Collector tests
templates:
- opentelemetry-collector.yaml
tests:
- it: "should not add extra OPTEL collector configuration when not extra value is defined"
documentSelector:
path: metadata.name
value: kubewarden
set:
telemetry:
metrics:
enabled: true
port: 8080
tracing:
enabled: true
jaeger:
endpoint: "all-in-one-collector.jaeger.svc.cluster.local:4317"
tls:
insecure: true
asserts:
- equal:
path: spec.mode
value: sidecar
- isNull:
path: spec.presets
- isNull:
path: spec.ports
content:
metrics:
enabled: true
- isNull:
path: spec.envFrom
content:
secretRef:
name: open-telemetry-collector
- equal:
path: spec.config
value:
receivers:
otlp:
protocols:
grpc: {}
processors:
batch: {}
exporters:
otlp/jaeger:
endpoint: "all-in-one-collector.jaeger.svc.cluster.local:4317"
tls:
insecure: true
prometheus:
endpoint: ":8080"
service:
pipelines:
metrics:
receivers: [otlp]
processors: []
exporters: [prometheus]
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/jaeger]
- it: "should add extra OPTEL collector configuration when extra configuration is defined"
documentSelector:
path: metadata.name
value: kubewarden
set:
telemetry:
metrics:
enabled: true
port: 8080
tracing:
enabled: true
jaeger:
endpoint: "all-in-one-collector.jaeger.svc.cluster.local:4317"
tls:
insecure: true
extraOptelConfig:
ports:
metrics:
enabled: true
presets:
kubernetesAttributes:
enabled: true
extractAllPodLabels: true
envFrom:
- secretRef:
name: open-telemetry-collector
extraConfig:
receivers:
otlp/stackstate:
protocols:
grpc: {}
exporters:
otlp/stackstate:
auth:
authenticator: bearertokenauth
endpoint: "<otlp-stackstate-endpoint>:443"
extensions:
bearertokenauth:
scheme: StackState
token: "${env:API_KEY}"
processors:
tail_sampling:
decision_wait: 10s
policies:
- name: rate-limited-composite
type: composite
composite:
max_total_spans_per_second: 500
policy_order: [errors, slow-traces, rest]
composite_sub_policy:
- name: errors
type: status_code
status_code:
status_codes: [ ERROR ]
- name: slow-traces
type: latency
latency:
threshold_ms: 1000
- name: rest
type: always_sample
rate_allocation:
- policy: errors
percent: 33
- policy: slow-traces
percent: 33
- policy: rest
percent: 34
resource:
attributes:
- key: k8s.cluster.name
action: upsert
value: <your-cluster-name>
- key: service.instance.id
from_attribute: k8s.pod.uid
action: insert
filter/dropMissingK8sAttributes:
error_mode: ignore
traces:
span:
- resource.attributes["k8s.node.name"] == nil
- resource.attributes["k8s.pod.uid"] == nil
- resource.attributes["k8s.namespace.name"] == nil
- resource.attributes["k8s.pod.name"] == nil
connectors:
spanmetrics:
metrics_expiration: 5m
namespace: otel_span
routing/traces:
error_mode: ignore
match_once: false
table:
- statement: route()
pipelines: [traces/sampling, traces/spanmetrics]
service:
extensions:
- health_check
- bearertokenauth
pipelines:
ststraces:
receivers: [otlp]
processors: [filter/dropMissingK8sAttributes, memory_limiter, resource]
exporters: [routing/traces]
traces/spanmetrics:
receivers: [routing/traces]
processors: []
exporters: [spanmetrics]
traces/sampling:
receivers: [routing/traces]
processors: [tail_sampling, batch]
exporters: [debug, otlp/stackstate]
stsmetrics:
receivers: [otlp, spanmetrics, prometheus]
processors: [memory_limiter, resource, batch]
exporters: [debug, otlp/stackstate]
asserts:
- equal:
path: spec.mode
value: sidecar
- isSubset:
path: spec.presets
content:
kubernetesAttributes:
enabled: true
extractAllPodLabels: true
- isSubset:
path: spec.ports
content:
metrics:
enabled: true
- contains:
path: spec.envFrom
content:
secretRef:
name: open-telemetry-collector
- isSubset:
path: spec.config.receivers
content:
otlp/stackstate:
protocols:
grpc: {}
- isSubset:
path: spec.config.connectors
content:
spanmetrics:
metrics_expiration: 5m
namespace: otel_span
routing/traces:
error_mode: ignore
match_once: false
table:
- statement: route()
pipelines: [traces/sampling, traces/spanmetrics]
- equal:
path: spec.config.service.extensions
value:
- health_check
- bearertokenauth
- isSubset:
path: spec.config.service.pipelines
content:
ststraces:
receivers: [otlp]
processors: [filter/dropMissingK8sAttributes, memory_limiter, resource]
exporters: [routing/traces]
traces/spanmetrics:
receivers: [routing/traces]
processors: []
exporters: [spanmetrics]
traces/sampling:
receivers: [routing/traces]
processors: [tail_sampling, batch]
exporters: [debug, otlp/stackstate]
stsmetrics:
receivers: [otlp, spanmetrics, prometheus]
processors: [memory_limiter, resource, batch]
exporters: [debug, otlp/stackstate]
metrics:
receivers: [otlp]
processors: []
exporters: [prometheus]
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp/jaeger]
- isSubset:
path: spec.config.exporters
content:
otlp/stackstate:
auth:
authenticator: bearertokenauth
endpoint: "<otlp-stackstate-endpoint>:443"
- isSubset:
path: spec.config.extensions
content:
bearertokenauth:
scheme: StackState
token: "${env:API_KEY}"
- isSubset:
path: spec.config.processors
content:
tail_sampling:
decision_wait: 10s
policies:
- name: rate-limited-composite
type: composite
composite:
max_total_spans_per_second: 500
policy_order: [errors, slow-traces, rest]
composite_sub_policy:
- name: errors
type: status_code
status_code:
status_codes: [ ERROR ]
- name: slow-traces
type: latency
latency:
threshold_ms: 1000
- name: rest
type: always_sample
rate_allocation:
- policy: errors
percent: 33
- policy: slow-traces
percent: 33
- policy: rest
percent: 34
resource:
attributes:
- key: k8s.cluster.name
action: upsert
value: <your-cluster-name>
- key: service.instance.id
from_attribute: k8s.pod.uid
action: insert
filter/dropMissingK8sAttributes:
error_mode: ignore
traces:
span:
- resource.attributes["k8s.node.name"] == nil
- resource.attributes["k8s.pod.uid"] == nil
- resource.attributes["k8s.namespace.name"] == nil
- resource.attributes["k8s.pod.name"] == nil
Loading

0 comments on commit 543123e

Please sign in to comment.