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

Send agent telemetry #595

Merged
merged 30 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b7a3f42
Add ability to collect&send own telemetry
srikanthccv Oct 28, 2024
6203059
Use metric reader config
srikanthccv Oct 28, 2024
41127a3
Add traces to own telemetry
srikanthccv Oct 29, 2024
b2a8624
fix nil pointer issue
srikanthccv Oct 29, 2024
8c80483
Merge branch 'main' into own-telemetry
srikanthccv Oct 29, 2024
2cf721a
Remove redundant logic
srikanthccv Oct 29, 2024
f14fb68
Merge remote-tracking branch 'origin/main' into own-telemetry
nityanandagohain Jan 7, 2025
7e1888e
fix: dont send logs from deployment
nityanandagohain Jan 7, 2025
ec3d643
fix: proper config usage with the endpoint is present and not present
nityanandagohain Jan 7, 2025
02c6123
fix: add resource attributes for metrics and traces
nityanandagohain Jan 8, 2025
073cbc1
Merge remote-tracking branch 'origin/main' into own-telemetry-1
nityanandagohain Jan 8, 2025
d8729dd
Merge remote-tracking branch 'origin/main' into own-telemetry-1
nityanandagohain Jan 9, 2025
0715481
fix: remove comment from template which was causing issues when apply…
nityanandagohain Jan 9, 2025
d715278
fix: add tests
nityanandagohain Jan 10, 2025
303f21f
fix: remove unwanted change
nityanandagohain Jan 10, 2025
56d1ec4
Merge branch 'main' into own-telemetry-1
nityanandagohain Jan 10, 2025
5fd4c8e
fix: updated test name
nityanandagohain Jan 10, 2025
d3e470c
Merge remote-tracking branch 'origin/own-telemetry-1' into own-teleme…
nityanandagohain Jan 10, 2025
809bbeb
fix: remove extra spaces
nityanandagohain Jan 10, 2025
7acf423
fix: correct names of files
nityanandagohain Jan 10, 2025
3493107
fix: rename own to self
nityanandagohain Jan 13, 2025
ba87a04
Merge branch 'main' into own-telemetry-1
nityanandagohain Jan 13, 2025
fda1171
Merge branch 'main' into own-telemetry-1
grandwizard28 Jan 15, 2025
71c517e
fix: rename own to self in remaining places
nityanandagohain Jan 15, 2025
d604153
Merge remote-tracking branch 'origin/own-telemetry-1' into own-teleme…
nityanandagohain Jan 15, 2025
ba22df7
fix: use proper apikey
nityanandagohain Jan 15, 2025
fc7bfbb
fix: bump minor version
nityanandagohain Jan 16, 2025
a50144a
fix: add test for otelexporter
nityanandagohain Jan 17, 2025
49ec9d0
fix: use signozApiKey instead of apikey
nityanandagohain Jan 17, 2025
37e19fa
fix: update name
nityanandagohain Jan 17, 2025
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/
138 changes: 136 additions & 2 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) }}
prashant-shahi marked this conversation as resolved.
Show resolved Hide resolved
{{- 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,12 @@ 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.resourceDetection.enabled }}
{{- $config = (include "opentelemetry-collector.applyResourceDetectionConfigForDeployment" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
Expand All @@ -86,6 +104,24 @@ Build config file for deployment OpenTelemetry Collector: OtelDeployment
{{- 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 +167,98 @@ 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: http{{ if not .Values.presets.ownTelemetry.insecure }}s{{ end }}://{{ default "${env:OTEL_EXPORTER_OTLP_ENDPOINT}" .Values.presets.ownTelemetry.endpoint }}
tls:
insecure: {{ default "${env:OTEL_EXPORTER_OTLP_INSECURE}" .Values.presets.ownTelemetry.insecure }}
insecure_skip_verify: {{ default "${env:OTEL_EXPORTER_OTLP_INSECURE_SKIP_VERIFY}" .Values.presets.ownTelemetry.insecureSkipVerify }}
headers:
"signoz-access-token": "${env:SIGNOZ_API_KEY}"
prashant-shahi marked this conversation as resolved.
Show resolved Hide resolved
{{- 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: http{{ if not .Values.presets.ownTelemetry.insecure }}s{{ end }}://{{ default "${env:OTEL_EXPORTER_OTLP_ENDPOINT}" .Values.presets.ownTelemetry.endpoint }}
insecure: {{ default "${env:OTEL_EXPORTER_OTLP_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: http{{ if not .Values.presets.ownTelemetry.insecure }}s{{ end }}://{{ default "${env:OTEL_EXPORTER_OTLP_ENDPOINT}" .Values.presets.ownTelemetry.endpoint }}
insecure: {{ default "${env:OTEL_EXPORTER_OTLP_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 }}*-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 }}
processors:
filter/non_error_logs:
logs:
log_record:
- 'not IsMatch(body, ".*error.*")'
service:
pipelines:
logs/own_logs:
exporters: [otlphttp/own_telemetry]
# we want to send only error logs
processors: [filter/non_error_logs]
receivers: [filelog/own_logs]
{{- end }}
nityanandagohain marked this conversation as resolved.
Show resolved Hide resolved

{{- define "opentelemetry-collector.otlpExporterConfig" -}}
exporters:
otlp:
Expand Down Expand Up @@ -254,10 +382,8 @@ receivers:
# 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 }}
Expand Down Expand Up @@ -366,6 +492,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 @@ -383,6 +513,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
17 changes: 14 additions & 3 deletions charts/k8s-infra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,22 @@ presets:
samplingThereafter: 500
otlpExporter:
enabled: true
ownTelemetry:
nityanandagohain marked this conversation as resolved.
Show resolved Hide resolved
# 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
nityanandagohain marked this conversation as resolved.
Show resolved Hide resolved
traces:
enabled: false
metrics:
enabled: false
logs:
enabled: false
logsCollection:
enabled: true
startAt: beginning
startAt: end
prashant-shahi marked this conversation as resolved.
Show resolved Hide resolved
includeFilePath: true
includeFileName: false
# This include path patterns for log files to be collected.
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