chore: mirror k8s-monitoring-2.0.12

upstream_repo:
This commit is contained in:
Nikolai Rodionov
2025-02-21 09:42:13 +01:00
commit 57712751f1
440 changed files with 101268 additions and 0 deletions

View File

@ -0,0 +1,37 @@
{{- define "features.annotationAutodiscovery.enabled" }}{{ .Values.annotationAutodiscovery.enabled }}{{- end }}
{{- define "features.annotationAutodiscovery.collectors" }}
{{- if .Values.annotationAutodiscovery.enabled -}}
- {{ .Values.annotationAutodiscovery.collector }}
{{- end }}
{{- end }}
{{- define "features.annotationAutodiscovery.include" }}
{{- if .Values.annotationAutodiscovery.enabled -}}
{{- $destinations := include "features.annotationAutodiscovery.destinations" . | fromYamlArray }}
// Feature: Annotation Autodiscovery
{{- include "feature.annotationAutodiscovery.module" .Subcharts.annotationAutodiscovery }}
annotation_autodiscovery "feature" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.annotationAutodiscovery.destinations" }}
{{- if .Values.annotationAutodiscovery.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.annotationAutodiscovery.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.annotationAutodiscovery.validate" }}
{{- if .Values.annotationAutodiscovery.enabled -}}
{{- $featureName := "Annotation Autodiscovery" }}
{{- $destinations := include "features.annotationAutodiscovery.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "metrics" "ecosystem" "prometheus" "feature" $featureName) }}
{{- range $collector := include "features.annotationAutodiscovery.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,93 @@
{{- define "features.applicationObservability.enabled" }}{{ .Values.applicationObservability.enabled }}{{- end }}
{{- define "features.applicationObservability.collectors" }}
{{- if .Values.applicationObservability.enabled -}}
- {{ .Values.applicationObservability.collector }}
{{- end }}
{{- end }}
{{- define "features.applicationObservability.include" }}
{{- if .Values.applicationObservability.enabled -}}
{{- $destinations := include "features.applicationObservability.destinations" . | fromYamlArray }}
// Feature: Application Observability
{{- include "feature.applicationObservability.module" (dict "Values" $.Values.applicationObservability "Files" $.Subcharts.applicationObservability.Files) }}
application_observability "feature" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "otlp") | indent 4 | trim }}
]
logs_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "logs" "ecosystem" "otlp") | indent 4 | trim }}
]
traces_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "traces" "ecosystem" "otlp") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.applicationObservability.destinations" }}
{{- if .Values.applicationObservability.enabled -}}
{{- $metricsDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "otlp" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- $logDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "logs" "ecosystem" "otlp" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- $traceDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "traces" "ecosystem" "otlp" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- concat $metricsDestinations $logDestinations $traceDestinations | toYaml }}
{{- end -}}
{{- end -}}
{{- define "features.applicationObservability.validate" }}
{{- if .Values.applicationObservability.enabled -}}
{{- $featureName := "Application Observability" }}
{{- if .Values.applicationObservability.metrics.enabled -}}
{{- $metricDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "otlp" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- include "destinations.validate_destination_list" (dict "destinations" $metricDestinations "type" "metrics" "ecosystem" "otlp" "feature" $featureName) }}
{{- end -}}
{{- if .Values.applicationObservability.logs.enabled -}}
{{- $logDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "logs" "ecosystem" "loki" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- include "destinations.validate_destination_list" (dict "destinations" $logDestinations "type" "logs" "ecosystem" "loki" "feature" $featureName) }}
{{- end -}}
{{- if .Values.applicationObservability.traces.enabled -}}
{{- $traceDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "traces" "ecosystem" "otlp" "filter" $.Values.applicationObservability.destinations) | fromYamlArray -}}
{{- include "destinations.validate_destination_list" (dict "destinations" $traceDestinations "type" "traces" "ecosystem" "otlp" "feature" $featureName) }}
{{- end -}}
{{- range $collector := include "features.applicationObservability.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- if $.Values.applicationObservability.receivers.otlp.grpc.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.otlp.grpc.port "portName" "otlp-grpc" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.otlp.http.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.otlp.http.port "portName" "otlp-http" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.zipkin.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.zipkin.port "portName" "zipkin" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.jaeger.grpc.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.jaeger.grpc.port "portName" "jaeger-grpc" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.jaeger.thriftBinary.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.jaeger.thriftBinary.port "portName" "jaeger-binary" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.jaeger.thriftCompact.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.jaeger.thriftCompact.port "portName" "jaeger-compact" "portProtocol" "TCP") }}
{{- end -}}
{{- if $.Values.applicationObservability.receivers.jaeger.thriftHttp.enabled }}
{{- include "collectors.require_extra_port" (dict "Values" $.Values "name" $collector "feature" $featureName "portNumber" $.Values.applicationObservability.receivers.jaeger.thriftHttp.port "portName" "jaeger-http" "portProtocol" "TCP") }}
{{- end -}}
{{- include "feature.applicationObservability.validate" (dict "Values" $.Values.applicationObservability) }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "features.applicationObservability.receiver.grpc" }}
{{- if and .Values.applicationObservability.enabled .Values.applicationObservability.receivers.otlp.grpc.enabled }}
http://{{ include "alloy.fullname" (index .Subcharts .Values.applicationObservability.collector) }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.applicationObservability.receivers.otlp.grpc.port }}
{{- end }}
{{- end }}
{{- define "features.applicationObservability.receiver.http" }}
{{- if and .Values.applicationObservability.enabled .Values.applicationObservability.receivers.otlp.http.enabled }}
http://{{ include "alloy.fullname" (index .Subcharts .Values.applicationObservability.collector) }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.applicationObservability.receivers.otlp.http.port }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,37 @@
{{- define "features.autoInstrumentation.enabled" }}{{ .Values.autoInstrumentation.enabled }}{{- end }}
{{- define "features.autoInstrumentation.collectors" }}
{{- if .Values.autoInstrumentation.enabled -}}
- {{ .Values.autoInstrumentation.collector }}
{{- end }}
{{- end }}
{{- define "features.autoInstrumentation.include" }}
{{- if .Values.autoInstrumentation.enabled -}}
{{- $destinations := include "features.autoInstrumentation.destinations" . | fromYamlArray }}
// Feature: Auto-Instrumentation
{{- include "feature.autoInstrumentation.module" (dict "Values" $.Values.autoInstrumentation "Files" $.Subcharts.autoInstrumentation.Files) }}
auto_instrumentation "feature" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.autoInstrumentation.destinations" }}
{{- if .Values.autoInstrumentation.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.autoInstrumentation.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.autoInstrumentation.validate" }}
{{- if .Values.autoInstrumentation.enabled -}}
{{- $featureName := "Auto-Instrumentation" }}
{{- $destinations := include "features.autoInstrumentation.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "metrics" "ecosystem" "prometheus" "feature" $featureName) }}
{{- range $collector := include "features.autoInstrumentation.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,37 @@
{{- define "features.clusterEvents.enabled" }}{{ .Values.clusterEvents.enabled }}{{- end }}
{{- define "features.clusterEvents.collectors" }}
{{- if .Values.clusterEvents.enabled -}}
- {{ .Values.clusterEvents.collector }}
{{- end }}
{{- end }}
{{- define "features.clusterEvents.include" }}
{{- if .Values.clusterEvents.enabled -}}
{{- $destinations := include "features.clusterEvents.destinations" . | fromYamlArray }}
// Feature: Cluster Events
{{- include "feature.clusterEvents.module" (dict "Values" $.Values.clusterEvents "Files" $.Subcharts.clusterEvents.Files) }}
cluster_events "feature" {
logs_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "logs" "ecosystem" "loki") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.clusterEvents.destinations" }}
{{- if .Values.clusterEvents.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "logs" "ecosystem" "loki" "filter" $.Values.clusterEvents.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.clusterEvents.validate" }}
{{- if .Values.clusterEvents.enabled -}}
{{- $featureName := "Kubernetes Cluster events" }}
{{- $destinations := include "features.clusterEvents.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "logs" "ecosystem" "loki" "feature" $featureName) }}
{{- range $collector := include "features.clusterEvents.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,183 @@
{{- define "features.clusterMetrics.enabled" }}{{ .Values.clusterMetrics.enabled }}{{- end }}
{{- define "features.clusterMetrics.collectors" }}
{{- if .Values.clusterMetrics.enabled -}}
- {{ .Values.clusterMetrics.collector }}
{{- end }}
{{- end }}
{{- define "features.clusterMetrics.include" }}
{{- if .Values.clusterMetrics.enabled -}}
{{- $destinations := include "features.clusterMetrics.destinations" . | fromYamlArray }}
// Feature: Cluster Metrics
{{- include "feature.clusterMetrics.module" (dict "Values" $.Values.clusterMetrics "Files" $.Subcharts.clusterMetrics.Files "Release" $.Release) }}
cluster_metrics "feature" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.clusterMetrics.destinations" }}
{{- if .Values.clusterMetrics.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.clusterMetrics.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.clusterMetrics.validate" }}
{{- if .Values.clusterMetrics.enabled -}}
{{- $featureName := "Kubernetes Cluster metrics" }}
{{- $destinations := include "features.clusterMetrics.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "metrics" "ecosystem" "prometheus" "feature" $featureName) }}
{{- range $collector := include "features.clusterMetrics.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- if .Values.clusterMetrics.opencost.enabled}}
{{- if ne .Values.cluster.name .Values.clusterMetrics.opencost.opencost.exporter.defaultClusterId }}
{{- $msg := list "" "The OpenCost default cluster id should match the cluster name." }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " exporter:" }}
{{- $msg = append $msg (printf " defaultClusterId: %s" .Values.cluster.name) }}
{{- fail (join "\n" $msg) }}
{{- end -}}
{{- if ne .Values.clusterMetrics.opencost.metricsSource "custom" }}
{{- if eq .Values.clusterMetrics.opencost.metricsSource "" }}
{{- $msg := list "" "OpenCost requires linking to a Prometheus data source." }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- if eq (len $destinations) 1 }}
{{- $msg = append $msg (printf " metricsSource: %s" (first $destinations)) }}
{{- else }}
{{- $msg = append $msg " metricsSource: <metrics destination name>" }}
{{- $msg = append $msg (printf "Where <metrics destination name> is one of %s" (include "english_list_or" $destinations)) }}
{{- end }}
{{- fail (join "\n" $msg) }}
{{- end -}}
{{- $destinationFound := false }}
{{- range $index, $destinationName := $destinations }}
{{- if eq $destinationName $.Values.clusterMetrics.opencost.metricsSource }}
{{- $destinationFound = true }}
{{- $destination := index $.Values.destinations $index }}
{{- $openCostMetricsUrl := (printf "<Query URL for destination \"%s\">" $destinationName) }}
{{- if $destination.url }}
{{- if regexMatch "/api/prom/push" $destination.url }}
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/prom/push$" $destination.url "${1}/api/prom") }}
{{- else if regexMatch "/api/v1/push" $destination.url }}
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/v1/push$" $destination.url "${1}/api/v1/query") }}
{{- else if regexMatch "/api/v1/write" $destination.url }}
{{- $openCostMetricsUrl = (regexReplaceAll "^(.*)/api/v1/write$" $destination.url "${1}/api/v1/query") }}
{{- end }}
{{- end }}
{{- if eq $.Values.clusterMetrics.opencost.opencost.prometheus.external.url ""}}
{{- $msg := list "" "OpenCost requires a url to a Prometheus data source." }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg " external:" }}
{{- $msg = append $msg (printf " url: %s" $openCostMetricsUrl) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- $authType := include "secrets.authType" $destination }}
{{- $secretType := include "secrets.secretType" $destination }}
{{- if eq $authType "basic" }}
{{- if eq $secretType "embedded" }}
{{- $destinationUsername := include "secrets.getSecretValue" (dict "object" $destination "key" ".auth.username") }}
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.username $destinationUsername}}
{{- $msg := list "" (printf "The username for %s and OpenCost do not match." $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg (printf " username: %s" $destinationUsername) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- $destinationPassword := include "secrets.getSecretValue" (dict "object" $destination "key" ".auth.password") }}
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.password_key $destinationPassword}}
{{- $msg := list "" (printf "The password for %s and OpenCost do not match." $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg (printf " password: %s" $destinationPassword) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- else }}
{{- $destinationSecret := include "secrets.kubernetesSecretName" (dict "Values" $.Values "Chart" $.Chart "Release" $.Release "object" $destination) }}
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.existingSecretName $destinationSecret}}
{{- $msg := list "" (printf "OpenCost requires the secret for %s to be set." $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg (printf " existingSecretName: %s" $destinationSecret) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- $destinationUsernameKey := include "secrets.getSecretKey" (dict "object" $destination "key" ".auth.username") }}
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.username_key $destinationUsernameKey}}
{{- $msg := list "" (printf "The username secret key for %s and OpenCost do not match." $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg (printf " username_key: %s" $destinationUsernameKey) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- $destinationPasswordKey := include "secrets.getSecretKey" (dict "object" $destination "key" ".auth.password") }}
{{- if ne $.Values.clusterMetrics.opencost.opencost.prometheus.password_key $destinationPasswordKey}}
{{- $msg := list "" (printf "The password secret key for %s and OpenCost do not match." $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " prometheus:" }}
{{- $msg = append $msg (printf " password_key: %s" $destinationPasswordKey) }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- end }}
{{- else if ne $authType "none" }}
{{- $msg := list "" (printf "Unable to provide guidance for configuring OpenCost to use %s authentication for %s." $authType $destinationName) }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " metricsSource: custom" }}
{{- $msg = append $msg ("And configure %s authentication for %s using guidance from the OpenCost Helm chart.") }}
{{- $msg = append $msg "Documentation: https://github.com/opencost/opencost-helm-chart/tree/main/charts/opencost" }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- end }}
{{- end -}}
{{- if eq $destinationFound false }}
{{- $msg := list "" (printf "The destination \"%s\" is not a Prometheus data source." $.Values.clusterMetrics.opencost.metricsSource) }}
{{- $msg = append $msg "OpenCost requires a Prometheus database to query where cluster metrics are stored." }}
{{- $msg = append $msg "" }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "clusterMetrics:" }}
{{- $msg = append $msg " opencost:" }}
{{- $msg = append $msg " metricsSource: <metrics destination name>" }}
{{- $msg = append $msg (printf "Where <metrics destination name> is one of %s" (include "english_list_or" $destinations)) }}
{{- fail (join "\n" $msg) }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,21 @@
{{- define "features.list" }}
- annotationAutodiscovery
- applicationObservability
- autoInstrumentation
- clusterMetrics
- clusterEvents
- nodeLogs
- podLogs
- profiling
- prometheusOperatorObjects
- integrations
- selfReporting
{{- end }}
{{- define "features.list.enabled" }}
{{- range $feature := ((include "features.list" .) | fromYamlArray ) }}
{{- if eq (include (printf "features.%s.enabled" $feature) $) "true" }}
- {{ $feature }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,80 @@
{{- define "features.integrations.enabled" }}
{{- $metricIntegrations := include "feature.integrations.configured.metrics" (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) | fromYamlArray }}
{{- $logIntegrations := include "feature.integrations.configured.logs" (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) | fromYamlArray }}
{{- if or $metricIntegrations $logIntegrations }}true{{ else }}false{{ end }}
{{- end }}
{{- define "features.integrations.collectors" }}
{{- $metricIntegrations := include "feature.integrations.configured.metrics" (dict "Values" .Values.integrations) | fromYamlArray }}
{{- if (not (empty $metricIntegrations)) }}
- {{ .Values.integrations.collector }}
{{- end }}
{{- end }}
{{- define "features.integrations.metrics.include" }}
{{- $values := dict "Chart" $.Subcharts.integrations.Chart "Values" .Values.integrations "Files" $.Subcharts.integrations.Files "Release" $.Release }}
{{- $destinations := include "features.integrations.destinations" . | fromYamlArray }}
{{- $integrations := include "feature.integrations.configured.metrics" $values | fromYamlArray }}
{{- range $integrationType := $integrations }}
{{- include (printf "integrations.%s.module.metrics" $integrationType) $values | indent 0 }}
{{ include "helper.alloy_name" $integrationType }}_integration "integration" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end }}
{{- end }}
{{- define "features.integrations.include" }}
{{- if eq .collectorName .Values.integrations.collector }}
{{ include "features.integrations.metrics.include" . | indent 0 }}
{{- end }}
{{- end }}
{{- define "features.integrations.destinations" }}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.integrations.destinations) -}}
{{- end }}
{{- define "features.integrations.logs.discoveryRules" }}
{{- $values := (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) }}
{{- $extraDiscoveryRules := list }}
{{- $logIntegrations := include "feature.integrations.configured.logs" $values | fromYamlArray }}
{{- range $integration := $logIntegrations }}
{{- $extraDiscoveryRules = append $extraDiscoveryRules ((include (printf "integrations.%s.logs.discoveryRules" $integration) $values) | indent 0) }}
{{- end }}
{{ $extraDiscoveryRules | join "\n" }}
{{- end }}
{{- define "features.integrations.logs.logProcessingStages" }}
{{- $values := (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) }}
{{- $extraLogProcessingStages := "" }}
{{- $logIntegrations := include "feature.integrations.configured.logs" $values | fromYamlArray }}
{{- range $integration := $logIntegrations }}
{{- $extraLogProcessingStages = cat $extraLogProcessingStages "\n" (include (printf "integrations.%s.logs.processingStage" $integration) $values) | indent 0 }}
{{- end }}
{{ $extraLogProcessingStages }}
{{- end }}
{{- define "features.integrations.validate" }}
{{- if eq (include "features.integrations.enabled" .) "true" }}
{{- $featureName := "Service Integrations" }}
{{- $metricIntegrations := include "feature.integrations.configured.metrics" (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) | fromYamlArray }}
{{- if $metricIntegrations }}
{{- $metricDestinations := include "features.integrations.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $metricDestinations "type" "metrics" "ecosystem" "prometheus" "feature" $featureName) }}
{{- end }}
{{- $podLogsEnabled := include "features.podLogs.enabled" $ }}
{{- $logIntegrations := include "feature.integrations.configured.logs" (dict "Values" .Values.integrations "Files" $.Subcharts.integrations.Files) | fromYamlArray }}
{{- if and $logIntegrations (ne $podLogsEnabled "true") }}
{{- $msg := list "" "Service integrations that include logs requires enabling the Pod Logs feature." }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "podLogs:" }}
{{- $msg = append $msg " enabled: true" }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- include "feature.integrations.validate" (dict "Values" $.Values.integrations) }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,40 @@
{{- define "features.nodeLogs.enabled" }}{{ .Values.nodeLogs.enabled }}{{- end }}
{{- define "features.nodeLogs.collectors" }}
{{- if .Values.nodeLogs.enabled -}}
- {{ .Values.nodeLogs.collector }}
{{- end }}
{{- end }}
{{- define "features.nodeLogs.include" }}
{{- if .Values.nodeLogs.enabled -}}
{{- $destinations := include "features.nodeLogs.destinations" . | fromYamlArray }}
// Feature: Node Logs
{{- include "feature.nodeLogs.module" (dict "Values" .Values.nodeLogs "Files" $.Subcharts.nodeLogs.Files) }}
node_logs "feature" {
logs_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "logs" "ecosystem" "loki") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.nodeLogs.destinations" }}
{{- if .Values.nodeLogs.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "logs" "ecosystem" "loki" "filter" $.Values.nodeLogs.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.nodeLogs.validate" }}
{{- if .Values.nodeLogs.enabled -}}
{{- $featureName := "Kubernetes Node logs" }}
{{- $destinations := include "features.nodeLogs.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "logs" "ecosystem" "loki" "feature" $featureName) }}
{{- range $collector := include "features.nodeLogs.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- include "feature.nodeLogs.collector.validate" (dict "Values" $.Values.nodeLogs "Collector" (index $.Values $collector) "CollectorName" $collector) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,43 @@
{{- define "features.podLogs.enabled" }}{{ .Values.podLogs.enabled }}{{- end }}
{{- define "features.podLogs.collectors" }}
{{- if .Values.podLogs.enabled -}}
- {{ .Values.podLogs.collector }}
{{- end }}
{{- end }}
{{- define "features.podLogs.include" }}
{{- if .Values.podLogs.enabled -}}
{{- $extraDiscoveryRules := cat (include "features.integrations.logs.discoveryRules" .) "\n" .Values.podLogs.extraDiscoveryRules | trim }}
{{- $extraLogProcessingStages := cat (include "features.integrations.logs.logProcessingStages" .) "\n" .Values.podLogs.extraLogProcessingStages | trim }}
{{- $values := mergeOverwrite .Values.podLogs (dict "extraDiscoveryRules" $extraDiscoveryRules "extraLogProcessingStages" $extraLogProcessingStages) }}
{{- $destinations := include "features.podLogs.destinations" . | fromYamlArray }}
// Feature: Pod Logs
{{- include "feature.podLogs.module" (dict "Values" $values "Files" $.Subcharts.podLogs.Files) }}
pod_logs "feature" {
logs_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "logs" "ecosystem" "loki") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.podLogs.destinations" }}
{{- if .Values.podLogs.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "logs" "ecosystem" "loki" "filter" $.Values.podLogs.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.podLogs.validate" }}
{{- if .Values.podLogs.enabled -}}
{{- $featureName := "Kubernetes Pod logs" }}
{{- $destinations := include "features.podLogs.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "logs" "ecosystem" "loki" "feature" $featureName) }}
{{- range $collector := include "features.podLogs.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- include "feature.podLogs.collector.validate" (dict "Values" $.Values.podLogs "Collector" (index $.Values $collector) "CollectorName" $collector) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,37 @@
{{- define "features.profiling.enabled" }}{{ .Values.profiling.enabled }}{{- end }}
{{- define "features.profiling.collectors" }}
{{- if .Values.profiling.enabled -}}
- {{ .Values.profiling.collector }}
{{- end }}
{{- end }}
{{- define "features.profiling.include" }}
{{- if .Values.profiling.enabled -}}
{{- $destinations := include "features.profiling.destinations" . | fromYamlArray }}
// Feature: Profiling
{{- include "feature.profiling.module" (dict "Values" $.Values.profiling "Files" $.Subcharts.profiling.Files) }}
profiling "feature" {
profiles_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "profiles" "ecosystem" "pyroscope") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.profiling.destinations" }}
{{- if .Values.profiling.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "profiles" "ecosystem" "pyroscope" "filter" $.Values.profiling.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.profiling.validate" }}
{{- if .Values.profiling.enabled -}}
{{- $featureName := "Profiling" }}
{{- $destinations := include "features.profiling.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "profiles" "ecosystem" "pyroscope" "feature" $featureName) }}
{{- range $collector := include "features.profiling.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,38 @@
{{- define "features.prometheusOperatorObjects.enabled" }}{{ .Values.prometheusOperatorObjects.enabled }}{{- end }}
{{- define "features.prometheusOperatorObjects.collectors" }}
{{- if .Values.prometheusOperatorObjects.enabled -}}
- {{ .Values.prometheusOperatorObjects.collector }}
{{- end }}
{{- end }}
{{- define "features.prometheusOperatorObjects.include" }}
{{- if .Values.prometheusOperatorObjects.enabled -}}
{{- $destinations := include "features.prometheusOperatorObjects.destinations" . | fromYamlArray }}
// Feature: Prometheus Operator Objects
{{- include "feature.prometheusOperatorObjects.module" (dict "Values" $.Values.prometheusOperatorObjects "Files" $.Subcharts.prometheusOperatorObjects.Files) }}
prometheus_operator_objects "feature" {
metrics_destinations = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end -}}
{{- end -}}
{{- define "features.prometheusOperatorObjects.destinations" }}
{{- if .Values.prometheusOperatorObjects.enabled -}}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.prometheusOperatorObjects.destinations) -}}
{{- end -}}
{{- end -}}
{{- define "features.prometheusOperatorObjects.validate" }}
{{- if .Values.prometheusOperatorObjects.enabled -}}
{{- $featureName := "Prometheus Operator Objects" }}
{{- $destinations := include "features.prometheusOperatorObjects.destinations" . | fromYamlArray }}
{{- include "destinations.validate_destination_list" (dict "destinations" $destinations "type" "metrics" "ecosystem" "prometheus" "feature" $featureName) }}
{{- range $collector := include "features.prometheusOperatorObjects.collectors" . | fromYamlArray }}
{{- include "collectors.require_collector" (dict "Values" $.Values "name" $collector "feature" $featureName) }}
{{- end -}}
{{- include "feature.prometheusOperatorObjects.validate" (dict "Values" $.Values.prometheusOperatorObjects) }}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,92 @@
{{- define "features.selfReporting.enabled" -}}
{{- $metricsDestinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.selfReporting.destinations) | fromYamlArray -}}
{{ and .Values.selfReporting.enabled (not (empty $metricsDestinations)) }}
{{- end -}}
{{- define "features.selfReporting.collectors" -}}
{{- if eq (include "features.selfReporting.enabled" .) "true" }}
{{- $collectorsByIncreasingPreference := list "alloy-receiver" "alloy-metrics" "alloy-singleton" }}
{{- $chosenCollector := "" }}
{{- range $collector := $collectorsByIncreasingPreference }}
{{- if (index $.Values $collector).enabled }}{{- $chosenCollector = $collector }}{{- end -}}
{{- end -}}
- {{ $chosenCollector }}
{{- end -}}
{{- end }}
{{- define "features.selfReporting.destinations" }}
{{- if eq (include "features.selfReporting.enabled" .) "true" }}
{{- include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.selfReporting.destinations) -}}
{{- end }}
{{- end }}
{{- define "features.selfReporting.validate" }}{{ end }}
{{- define "features.selfReporting.include" }}
{{- if eq (include "features.selfReporting.enabled" .) "true" }}
{{- $destinations := include "destinations.get" (dict "destinations" $.Values.destinations "type" "metrics" "ecosystem" "prometheus" "filter" $.Values.selfReporting.destinations) | fromYamlArray -}}
// Self Reporting
prometheus.exporter.unix "kubernetes_monitoring_telemetry" {
set_collectors = ["textfile"]
textfile {
directory = "/etc/alloy"
}
}
discovery.relabel "kubernetes_monitoring_telemetry" {
targets = prometheus.exporter.unix.kubernetes_monitoring_telemetry.targets
rule {
target_label = "instance"
action = "replace"
replacement = "{{ .Release.Name }}"
}
rule {
target_label = "job"
action = "replace"
replacement = "integrations/kubernetes/kubernetes_monitoring_telemetry"
}
}
prometheus.scrape "kubernetes_monitoring_telemetry" {
job_name = "integrations/kubernetes/kubernetes_monitoring_telemetry"
targets = discovery.relabel.kubernetes_monitoring_telemetry.output
scrape_interval = {{ .Values.selfReporting.scrapeInterval | default .Values.global.scrapeInterval | quote}}
clustering {
enabled = true
}
forward_to = [prometheus.relabel.kubernetes_monitoring_telemetry.receiver]
}
prometheus.relabel "kubernetes_monitoring_telemetry" {
rule {
source_labels = ["__name__"]
regex = "grafana_kubernetes_monitoring_.*"
action = "keep"
}
forward_to = [
{{ include "destinations.alloy.targets" (dict "destinations" $.Values.destinations "names" $destinations "type" "metrics" "ecosystem" "prometheus") | indent 4 | trim }}
]
}
{{- end }}
{{- end }}
{{- define "features.selfReporting.metrics" }}
{{- if eq (include "features.selfReporting.enabled" .) "true" }}
# HELP grafana_kubernetes_monitoring_build_info A metric to report the version of the Kubernetes Monitoring Helm chart
# TYPE grafana_kubernetes_monitoring_build_info gauge
grafana_kubernetes_monitoring_build_info{version="{{ .Chart.Version }}", namespace="{{ .Release.Namespace }}"{{- if .Values.global.platform }}, platform="{{ .Values.global.platform }}"{{ end }}} 1
# HELP grafana_kubernetes_monitoring_feature_info A metric to report the enabled features of the Kubernetes Monitoring Helm chart
# TYPE grafana_kubernetes_monitoring_feature_info gauge
{{- range $feature := include "features.list.enabled" . | fromYamlArray }}
{{- if ne $feature "selfReporting" }}
{{- $featureSummary := include (printf "feature.%s.summary" $feature) (dict "Chart" (index $.Subcharts $feature).Chart "Values" (index $.Values $feature)) | fromYaml }}
grafana_kubernetes_monitoring_feature_info{{ include "label_list" (merge $featureSummary (dict "feature" $feature)) }} 1
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- define "feature.selfReporting.alloyModules" }}{{ end }}
{{- define "feature.selfReporting.notes.deployments" }}{{ end }}
{{- define "feature.selfReporting.notes.task" }}{{ end }}
{{- define "feature.selfReporting.notes.actions" }}{{ end }}