Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to collect&send own telemetry #540

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

### Scripts ###
tmp/

rendered/
150 changes: 135 additions & 15 deletions charts/k8s-infra/templates/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Build config file for daemonset OpenTelemetry Collector: OtelAgent
{{- $values := deepCopy .Values.otelAgent }}
{{- $data := dict "Values" $values | mustMergeOverwrite (deepCopy .) }}
{{- $config := include "otelAgent.baseConfig" $data | fromYaml }}
{{- if .Values.presets.ownTelemetry.traces.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnTracesConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.metrics.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.logs.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnLogsConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.logsCollection.enabled }}
{{- $config = (include "opentelemetry-collector.applyLogsCollectionConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
Expand All @@ -40,6 +49,9 @@ Build config file for daemonset OpenTelemetry Collector: OtelAgent
{{- if .Values.presets.loggingExporter.enabled }}
{{- $config = (include "opentelemetry-collector.applyLoggingExporterConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.logs.enabled }}
{{- $config = (include "opentelemetry-collector.applyOtlpExporterOwnTelemetryConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.otlpExporter.enabled }}
{{- $config = (include "opentelemetry-collector.applyOtlpExporterConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
Expand All @@ -62,6 +74,15 @@ Build config file for deployment OpenTelemetry Collector: OtelDeployment
{{- $values := deepCopy .Values }}
{{- $data := dict "Values" $values | mustMergeOverwrite (deepCopy .) }}
{{- $config := include "otelDeployment.baseConfig" $data | fromYaml }}
{{- if .Values.presets.ownTelemetry.traces.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnTracesConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.metrics.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.logs.enabled }}
{{- $config = (include "opentelemetry-collector.applyOwnLogsConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.resourceDetection.enabled }}
{{- $config = (include "opentelemetry-collector.applyResourceDetectionConfigForDeployment" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
Expand All @@ -80,12 +101,33 @@ Build config file for deployment OpenTelemetry Collector: OtelDeployment
{{- if .Values.presets.otlpExporter.enabled }}
{{- $config = (include "opentelemetry-collector.applyOtlpExporterConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.ownTelemetry.logs.enabled }}
{{- $config = (include "opentelemetry-collector.applyOtlpExporterOwnTelemetryConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if or (eq (len (index (index $config.service.pipelines "metrics/internal") "receivers")) 0) (eq (len (index (index $config.service.pipelines "metrics/internal") "exporters")) 0) }}
{{- $_ := unset $config.service.pipelines "metrics/internal" }}
{{- end }}
{{- tpl (toYaml $config) . }}
{{- end }}

{{- define "opentelemetry-collector.applyOwnTracesConfig" -}}
{{- $config := .config }}
{{- $config = mustMergeOverwrite (include "opentelemetry-collector.ownTracesConfig" .Values | fromYaml) $config }}
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.applyOwnMetricsConfig" -}}
{{- $config := .config }}
{{- $config = mustMergeOverwrite (include "opentelemetry-collector.ownMetricsConfig" .Values | fromYaml) $config }}
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.applyOwnLogsConfig" -}}
{{- $config := .config }}
{{- $config = mustMergeOverwrite (include "opentelemetry-collector.ownLogsConfig" .Values | fromYaml) $config }}
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.applyLoggingExporterConfig" -}}
{{- $config := mustMergeOverwrite (include "opentelemetry-collector.loggingExporterConfig" .Values | fromYaml) .config }}
{{- if $config.service.pipelines.logs }}
Expand Down Expand Up @@ -131,6 +173,91 @@ exporters:
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.applyOtlpExporterOwnTelemetryConfig" -}}
{{- $config := mustMergeOverwrite (include "opentelemetry-collector.otlpExporterOwnTelemetryConfig" .Values | fromYaml) .config }}
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.otlpExporterOwnTelemetryConfig" -}}
exporters:
otlphttp/own_telemetry:
endpoint: {{ .Values.presets.ownTelemetry.endpoint }}
tls:
insecure: {{ .Values.presets.ownTelemetry.insecure }}
insecure_skip_verify: {{ .Values.presets.ownTelemetry.insecureSkipVerify }}
headers:
"signoz-access-token": "${env:SIGNOZ_API_KEY}"
{{- end }}

{{/*
Own traces config, if the endpoint is not set in the ownTelemetry config,
it will use the same endpoint as regular otlp exporter.
*/}}
{{- define "opentelemetry-collector.ownTracesConfig" -}}
service:
telemetry:
traces:
processors:
- batch:
exporter:
otlp:
protocol: http/protobuf
endpoint: {{ .Values.presets.ownTelemetry.endpoint }}
insecure: {{ .Values.presets.ownTelemetry.insecure }}
compression: gzip
headers:
"signoz-access-token": "${env:SIGNOZ_API_KEY}"
propagators:
- tracecontext
- b3
{{- end }}

{{/*
Own metrics config, if the endpoint is not set in the ownTelemetry config,
it will use the same endpoint as regular otlp exporter.
*/}}
{{- define "opentelemetry-collector.ownMetricsConfig" -}}
service:
telemetry:
metrics:
level: detailed
readers:
- periodic:
exporter:
otlp:
protocol: http/protobuf
endpoint: {{ .Values.presets.ownTelemetry.endpoint }}
insecure: {{ .Values.presets.ownTelemetry.insecure }}
compression: gzip
headers:
"signoz-access-token": "${env:SIGNOZ_API_KEY}"
{{- end }}

{{/*
OTEL go doesn't support logs yet, so we use filelog receiver to collect logs,
if the endpoint is not set in the ownTelemetry config, it will use the same endpoint as regular otlp exporter.
*/}}
{{- define "opentelemetry-collector.ownLogsConfig" -}}
receivers:
filelog/own_logs:
include:
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-signoz-*/*/*.log
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-k8s-infra-*/*/*.log
start_at: {{ .Values.presets.logsCollection.startAt }}
include_file_path: {{ .Values.presets.logsCollection.includeFilePath }}
include_file_name: {{ .Values.presets.logsCollection.includeFileName }}
operators:
{{ range $operators := .Values.presets.logsCollection.operators }}
- {{ toYaml $operators | nindent 8 }}
{{ end }}
service:
pipelines:
logs/own_logs:
exporters: [otlphttp/own_telemetry]
processors: []
receivers: [filelog/own_logs]
{{- end }}

{{- define "opentelemetry-collector.otlpExporterConfig" -}}
exporters:
otlp:
Expand Down Expand Up @@ -248,16 +375,6 @@ receivers:
{{- $pods := .Values.presets.logsCollection.whitelist.pods }}
{{- $containers := .Values.presets.logsCollection.whitelist.containers }}
{{- $additionalInclude := .Values.presets.logsCollection.whitelist.additionalInclude }}
# Include specific container's logs using whitelist config.
# The file format is /var/log/pods/<namespace_name>_<pod_name>_<pod_uid>/<container_name>/<run_id>.log
{{- if .Values.presets.logsCollection.whitelist.signozLogs }}
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-signoz-*/*/*.log
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-k8s-infra-*/*/*.log
{{- if and .Values.namespace (ne .Release.Namespace .Values.namespace) }}
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-signoz-*/*/*.log
- /var/log/pods/{{ .Values.namespace }}_{{ .Release.Name }}*-k8s-infra-*/*/*.log
{{- end }}
{{- end }}
{{- range $namespace := $namespaces }}
- /var/log/pods/{{ $namespace }}_*/*/*.log
{{- end }}
Expand All @@ -282,14 +399,9 @@ receivers:
# Exclude specific container's logs using blacklist config or includeSigNozLogs flag.
# The file format is /var/log/pods/<namespace_name>_<pod_name>_<pod_uid>/<container_name>/<run_id>.log
exclude:
{{- if .Values.presets.logsCollection.blacklist.signozLogs }}
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-signoz-*/*/*.log
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-k8s-infra-*/*/*.log
{{- if and .Values.namespace (ne .Release.Namespace .Values.namespace) }}
- /var/log/pods/{{ .Release.Namespace }}_{{ .Release.Name }}*-signoz-*/*/*.log
- /var/log/pods/{{ .Values.namespace }}_{{ .Release.Name }}*-k8s-infra-*/*/*.log
{{- end }}
{{- end }}
{{- range $namespace := $namespaces }}
- /var/log/pods/{{ $namespace }}_*/*/*.log
{{- end }}
Expand Down Expand Up @@ -360,6 +472,10 @@ processors:
{{- if index $config.service.pipelines "metrics/internal" }}
{{- $_ := set (index $config.service.pipelines "metrics/internal") "processors" (prepend (index (index $config.service.pipelines "metrics/internal") "processors") "resourcedetection" | uniq) }}
{{- end }}
# prepend for "logs/own_logs"
{{- if index $config.service.pipelines "logs/own_logs" }}
{{- $_ := set (index $config.service.pipelines "logs/own_logs") "processors" (prepend (index (index $config.service.pipelines "logs/own_logs") "processors") "resourcedetection" | uniq) }}
{{- end }}
{{- $config | toYaml }}
{{- end }}

Expand All @@ -377,6 +493,10 @@ processors:
{{- if index $config.service.pipelines "metrics/internal" }}
{{- $_ := set (index $config.service.pipelines "metrics/internal") "processors" (prepend (index (index $config.service.pipelines "metrics/internal") "processors") "resourcedetection" | uniq) }}
{{- end }}
# prepend for "logs/own_logs"
{{- if index $config.service.pipelines "logs/own_logs" }}
{{- $_ := set (index $config.service.pipelines "logs/own_logs") "processors" (prepend (index (index $config.service.pipelines "logs/own_logs") "processors") "resourcedetection" | uniq) }}
{{- end }}
{{- $config | toYaml }}
{{- end }}

Expand Down
15 changes: 13 additions & 2 deletions charts/k8s-infra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ presets:
samplingThereafter: 500
otlpExporter:
enabled: true
ownTelemetry:
# OTLP HTTP endpoint to send own telemetry data to.
endpoint: ""
# Whether to use insecure mode.
insecure: true
# Whether to skip verifying the certificate.
insecureSkipVerify: true
traces:
enabled: false
metrics:
enabled: false
logs:
enabled: false
logsCollection:
enabled: true
startAt: beginning
Expand All @@ -104,7 +117,6 @@ presets:
# By default, kube-system and hotrod, locust pods are excluded.
blacklist:
enabled: true
signozLogs: true
namespaces:
- kube-system
pods:
Expand All @@ -117,7 +129,6 @@ presets:
# If whitelist is enabled, `include` is ignored.
whitelist:
enabled: false
signozLogs: true
namespaces: []
pods: []
containers: []
Expand Down
Loading