Skip to content

Commit

Permalink
feat(k8s-infra): single generic prometheus scraper
Browse files Browse the repository at this point in the history
Signed-off-by: Prashant Shahi <[email protected]>
  • Loading branch information
prashant-shahi committed Jan 6, 2025
1 parent ff7db84 commit a34cf89
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 115 deletions.
103 changes: 22 additions & 81 deletions charts/k8s-infra/templates/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Build config file for deployment OpenTelemetry Collector: OtelDeployment
{{- if .Values.presets.clusterMetrics.enabled }}
{{- $config = (include "opentelemetry-collector.applyClusterMetricsConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if and .Values.presets.prometheusScraper.enabled (or .Values.presets.prometheusScraper.signoz.enabled .Values.presets.prometheusScraper.prometheus.enabled) }}
{{- if and .Values.presets.prometheus.enabled (or .Values.presets.prometheus.enabled .Values.presets.prometheus.prometheus.enabled) }}
{{- $config = (include "opentelemetry-collector.applyPrometheusScraperConfig" (dict "Values" $data "config" $config) | fromYaml) }}
{{- end }}
{{- if .Values.presets.k8sEvents.enabled }}
Expand Down Expand Up @@ -209,109 +209,50 @@ receivers:
{{- $config | toYaml }}
{{- end }}

{{- define "opentelemetry-collector.convertAnnotationToPrometheusMetaLabel" -}}
{{- $name := . | lower -}}
{{- $name = regexReplaceAll "\\." $name "_" -}}
{{- $name := regexReplaceAll "/" $name "_" -}}
{{- $name := regexReplaceAll "-" $name "_" -}}
{{- $name := regexReplaceAll "[^a-z0-9_]" $name "_" -}}
{{- $name -}}
{{- end -}}

{{- define "opentelemetry-collector.prometheusScraperConfig" -}}
{{- $annotationsPrefix := include "opentelemetry-collector.convertAnnotationToPrometheusMetaLabel" .Values.presets.prometheus.annotationsPrefix }}
receivers:
prometheus/scraper:
config:
scrape_configs:
{{- if .Values.presets.prometheusScraper.signoz.enabled }}
{{- if .Values.presets.prometheus.enabled }}
- job_name: "signoz-scraper"
scrape_interval: {{ .Values.presets.prometheusScraper.signoz.scrapeInterval }}
scrape_interval: {{ .Values.presets.prometheus.scrapeInterval }}
kubernetes_sd_configs:
- role: pod
{{- if or .Values.presets.prometheusScraper.signoz.namespaceScoped (len .Values.presets.prometheusScraper.signoz.namespaces) }}
{{- if or .Values.presets.prometheus.namespaceScoped (len .Values.presets.prometheus.namespaces) }}
namespaces:
{{- if .Values.presets.prometheusScraper.signoz.namespaceScoped }}
{{- if .Values.presets.prometheus.namespaceScoped }}
own_namespace: true
{{- end }}
{{- if .Values.presets.prometheusScraper.signoz.namespaces }}
names: {{ toYaml .Values.presets.prometheusScraper.signoz.namespaces | nindent 16 }}
{{- if .Values.presets.prometheus.namespaces }}
names: {{ toYaml .Values.presets.prometheus.namespaces | nindent 16 }}
{{- end }}
{{- end }}
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_signoz_io_scrape]
- source_labels: [__meta_kubernetes_pod_annotation_{{ $annotationsPrefix }}_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_signoz_io_path]
- source_labels: [__meta_kubernetes_pod_annotation_{{ $annotationsPrefix }}_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__meta_kubernetes_pod_ip, __meta_kubernetes_pod_annotation_signoz_io_port]
- source_labels: [__meta_kubernetes_pod_ip, __meta_kubernetes_pod_annotation_{{ $annotationsPrefix }}_port]
action: replace
separator: ":"
target_label: __address__
- target_label: job_name
replacement: signoz-scraper
{{- if .Values.presets.prometheusScraper.signoz.includePodLabel }}
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
{{- end }}
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_name]
action: replace
target_label: signoz_k8s_name
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_instance]
action: replace
target_label: signoz_k8s_instance
- source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_component]
action: replace
target_label: signoz_k8s_component
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: k8s_namespace_name
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: k8s_pod_name
- source_labels: [__meta_kubernetes_pod_uid]
action: replace
target_label: k8s_pod_uid
{{- if .Values.presets.prometheusScraper.signoz.includeContainerName }}
- source_labels: [__meta_kubernetes_pod_container_name]
action: replace
target_label: k8s_container_name
- source_labels: [__meta_kubernetes_pod_container_name]
regex: (.+)-init
action: drop
{{- end }}
- source_labels: [__meta_kubernetes_pod_node_name]
action: replace
target_label: k8s_node_name
- source_labels: [__meta_kubernetes_pod_ready]
action: replace
target_label: k8s_pod_ready
- source_labels: [__meta_kubernetes_pod_phase]
action: replace
target_label: k8s_pod_phase
{{- end }}
{{- if .Values.presets.prometheusScraper.prometheus.enabled }}
- job_name: "prometheus-scraper"
scrape_interval: {{ .Values.presets.prometheusScraper.prometheus.scrapeInterval }}
kubernetes_sd_configs:
- role: pod
{{- if or .Values.presets.prometheusScraper.prometheus.namespaceScoped (len .Values.presets.prometheusScraper.prometheus.namespaces) }}
namespaces:
{{- if .Values.presets.prometheusScraper.prometheus.namespaceScoped }}
own_namespace: true
{{- end }}
{{- if.Values.presets.prometheusScraper.prometheus.namespaces }}
names:
{{- toYaml .Values.presets.prometheusScraper.prometheus.namespaces | nindent 16 }}
{{- end }}
{{- end }}
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__meta_kubernetes_pod_ip, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
separator: ":"
target_label: __address__
- target_label: job_name
replacement: prometheus-scraper
{{- if .Values.presets.prometheusScraper.prometheus.includePodLabel }}
{{- if .Values.presets.prometheus.includePodLabel }}
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
{{- end }}
Expand All @@ -333,7 +274,7 @@ receivers:
- source_labels: [__meta_kubernetes_pod_uid]
action: replace
target_label: k8s_pod_uid
{{- if .Values.presets.prometheusScraper.prometheus.includeContainerName }}
{{- if .Values.presets.prometheus.includeContainerName }}
- source_labels: [__meta_kubernetes_pod_container_name]
action: replace
target_label: k8s_container_name
Expand Down
52 changes: 18 additions & 34 deletions charts/k8s-infra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,40 +309,24 @@ presets:
enabled: true
k8s.pod.status_reason:
enabled: true
prometheusScraper:
enabled: true
signoz:
# -- Whether to enable metrics scraping using `signoz.io/scrape` pod annotation
enabled: true
# -- How often to scrape metrics
scrapeInterval: 60s
# -- Whether to only scrape metrics from pods in the same namespace
namespaceScoped: false
# -- If set, only scrape metrics from pods in the specified namespaces
namespaces: []
# -- This will include all pod labels in the metrics, could potentially cause
# performance issues with large number of pods with many labels
includePodLabel: false
# -- This is not recommended in case of multiple containers or init containers in a pod
# Since it will create multiple timeseries for the same pod metrics with different container names
# containers with `-init` suffix in the name will be ignored
includeContainerName: false
prometheus:
# -- Whether to enable metrics scraping using `prometheus.io/scrape` pod annotation
enabled: true
# -- How often to scrape metrics
scrapeInterval: 60s
# -- If enabled, only scrape metrics from pods in the same namespace
namespaceScoped: false
# -- If set, only scrape metrics from pods in the specified namespaces
namespaces: []
# -- This will include all pod labels in the metrics, could potentially cause
# performance issues with large number of pods with many labels
includePodLabel: false
# -- This is not recommended to be enabled in case of multiple containers or init containers in a pod
# Since it will create multiple timeseries for the same pod metrics with different container names
# containers with `-init` suffix in the name will be ignored
includeContainerName: false
prometheus:
# -- Whether to enable metrics scraping using pod annotation
enabled: false
# -- Prefix for the pod annotations to be used for metrics scraping
annotationsPrefix: signoz.io
# -- How often to scrape metrics
scrapeInterval: 60s
# -- Whether to only scrape metrics from pods in the same namespace
namespaceScoped: false
# -- If set, only scrape metrics from pods in the specified namespaces
namespaces: []
# -- This will include all pod labels in the metrics, could potentially cause
# performance issues with large number of pods with many labels
includePodLabel: false
# -- This is not recommended in case of multiple containers or init containers in a pod
# Since it will create multiple timeseries for the same pod metrics with different container names
# containers with `-init` suffix in the name will be ignored
includeContainerName: false
resourceDetectionInternal:
enabled: true
timeout: 2s
Expand Down

0 comments on commit a34cf89

Please sign in to comment.