diff --git a/charts/k8s-monitoring/docs/examples/remote-config/output.yaml b/charts/k8s-monitoring/docs/examples/remote-config/output.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/charts/k8s-monitoring/docs/examples/remote-config/values.yaml b/charts/k8s-monitoring/docs/examples/remote-config/values.yaml new file mode 100644 index 000000000..502df67e6 --- /dev/null +++ b/charts/k8s-monitoring/docs/examples/remote-config/values.yaml @@ -0,0 +1,12 @@ +cluster: + name: remote-config-example-cluster + +alloy-metrics: + enabled: true + remoteConfig: + enabled: true + url: "https://remote-config.example.com/alloy" + auth: + type: "basic" + username: "my-remote-cfg-user" + password: "my-remote-cfg-password" diff --git a/charts/k8s-monitoring/schema-mods/types-and-enums.json b/charts/k8s-monitoring/schema-mods/types-and-enums.json index 915b6c2f0..e3d801d02 100644 --- a/charts/k8s-monitoring/schema-mods/types-and-enums.json +++ b/charts/k8s-monitoring/schema-mods/types-and-enums.json @@ -6,7 +6,10 @@ "podLogs": {"properties": {"destinations": { "uniqueItems": true, "items": { "type": "string" }}}}, "frontendObservability": {"properties": {"destinations": { "uniqueItems": true, "items": { "type": "string" }}}}, - "destinations": {"$ref": "#/definitions/destination-list"} + "destinations": {"$ref": "#/definitions/destination-list"}, + "alloy-metrics": {"properties": {"remoteConfig": {"properties": { + "auth": {"properties": {"type": {"enum": ["none", "basic", "bearerToken"]}}} + }}}} }, "definitions": { "loki-destination": {"properties": { diff --git a/charts/k8s-monitoring/templates/_validations.tpl b/charts/k8s-monitoring/templates/_validations.tpl index 73caba13a..80f4eacc2 100644 --- a/charts/k8s-monitoring/templates/_validations.tpl +++ b/charts/k8s-monitoring/templates/_validations.tpl @@ -15,6 +15,10 @@ {{- range $feature := ((include "features.list" .) | fromYamlArray ) }} {{- $aFeatureIsEnabled = or $aFeatureIsEnabled (eq (include (printf "features.%s.enabled" $feature) (dict "Values" $.Values)) "true") }} {{- end }} +{{- range $collector := ((include "collectors.list" .) | fromYamlArray ) }} + {{- $aFeatureIsEnabled = or $aFeatureIsEnabled (and (index $.Values $collector).remoteConfig.enabled) }} + {{- $aFeatureIsEnabled = or $aFeatureIsEnabled (and (index $.Values $collector).extraConfig) }} +{{- end }} {{- if not $aFeatureIsEnabled }} {{- $msg := list "" "No features are enabled. Please choose a feature to start monitoring. For example:" }} {{- $msg = append $msg "clusterMetrics:" }} diff --git a/charts/k8s-monitoring/templates/alloy-config.yaml b/charts/k8s-monitoring/templates/alloy-config.yaml index e9cfdaba0..29d6c106f 100644 --- a/charts/k8s-monitoring/templates/alloy-config.yaml +++ b/charts/k8s-monitoring/templates/alloy-config.yaml @@ -28,9 +28,8 @@ data: {{- end }} {{- include "collectors.logging.alloy" $values | trim | nindent 4 }} {{- include "collectors.liveDebugging.alloy" $values | trim | nindent 4 }} - {{- if (index $.Values $collector).extraConfig }} - {{ (index $.Values $collector).extraConfig | trim | nindent 4 }} - {{- end }} + {{- include "collectors.remoteConfig.alloy" $values | trim | nindent 4 }} + {{- include "collectors.extraConfig.alloy" $values | trim | nindent 4 }} {{- if $selfReportingEnabled }} {{- include "features.selfReporting.file" $values | trim | nindent 2 }} {{- end }} diff --git a/charts/k8s-monitoring/templates/collectors/_collector_extraConfig.tpl b/charts/k8s-monitoring/templates/collectors/_collector_extraConfig.tpl new file mode 100644 index 000000000..3e7d02d6a --- /dev/null +++ b/charts/k8s-monitoring/templates/collectors/_collector_extraConfig.tpl @@ -0,0 +1,5 @@ +{{- define "collectors.extraConfig.alloy" -}} + {{- if (index .Values .collectorName).extraConfig }} + {{ (index .Values .collectorName).extraConfig | trim }} + {{- end }} +{{- end -}} diff --git a/charts/k8s-monitoring/templates/collectors/_collector_remoteConfig.tpl b/charts/k8s-monitoring/templates/collectors/_collector_remoteConfig.tpl new file mode 100644 index 000000000..cddbc483f --- /dev/null +++ b/charts/k8s-monitoring/templates/collectors/_collector_remoteConfig.tpl @@ -0,0 +1,34 @@ +{{- define "collectors.remoteConfig.alloy" -}} +{{- with (index .Values .collectorName).remoteConfig }} +{{- if .enabled }} +remotecfg { + url = {{ .url | quote }} +{{- if eq .auth.type "basic" }} + basic_auth { + username = {{ include "destinations.secret.read" (dict "destination" . "key" "auth.username" "nonsensitive" true) }} + password = {{ include "destinations.secret.read" (dict "destination" . "key" "auth.password") }} + } +{{- end -}} +{{- if .id }} + id = {{ .id | quote }} +{{- else }} + id = "{{ $.Values.cluster.name }}-{{ $.Release.Namespace }}-" + constants.hostname +{{- end -}} + poll_frequency = {{ .pollFrequency | quote }} + attributes = { + "cluster" = {{ $.Values.cluster.name | quote }}, + "platform" = "kubernetes", + "workloadType": {{ (index $.Values $.collectorName).controller.type | quote }}, +{{- range $key, $value := .extraAttributes }} + {{ $key | quote }} = {{ $value | quote }}, +{{- end -}} + } +} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "collectors.remoteConfig.secrets" -}} +- auth.username +- auth.password +{{- end -}} diff --git a/charts/k8s-monitoring/templates/collectors/_collector_validations.tpl b/charts/k8s-monitoring/templates/collectors/_collector_validations.tpl index 35b354df0..e6f2a8c62 100644 --- a/charts/k8s-monitoring/templates/collectors/_collector_validations.tpl +++ b/charts/k8s-monitoring/templates/collectors/_collector_validations.tpl @@ -7,6 +7,8 @@ {{- $collectorName := "alloy-metrics" }} {{- if (index .Values $collectorName).enabled }} {{- $atLeastOneFeatureEnabled := or .Values.clusterMetrics.enabled .Values.annotationAutodiscovery.enabled .Values.prometheusOperatorObjects.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).remoteConfig.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).extraConfig }} {{- $integrationsConfigured := include "feature.integrations.configured.metrics" .Subcharts.integrations | fromYamlArray }} {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (not (empty $integrationsConfigured)) }} @@ -18,6 +20,8 @@ {{- $collectorName = "alloy-singleton" }} {{- if (index .Values $collectorName).enabled }} {{- $atLeastOneFeatureEnabled := .Values.clusterEvents.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).remoteConfig.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).extraConfig }} {{- if not $atLeastOneFeatureEnabled }} {{- fail (printf $errorMessage $collectorName $collectorName) }} {{- end }} @@ -26,6 +30,8 @@ {{- $collectorName = "alloy-logs" }} {{- if (index .Values $collectorName).enabled }} {{- $atLeastOneFeatureEnabled := .Values.podLogs.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).remoteConfig.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).extraConfig }} {{- if not $atLeastOneFeatureEnabled }} {{- fail (printf $errorMessage $collectorName $collectorName) }} {{- end }} @@ -34,6 +40,8 @@ {{- $collectorName = "alloy-receiver" }} {{- if (index .Values $collectorName).enabled }} {{- $atLeastOneFeatureEnabled := or .Values.applicationObservability.enabled .Values.frontendObservability.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).remoteConfig.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).extraConfig }} {{- if not $atLeastOneFeatureEnabled }} {{- fail (printf $errorMessage $collectorName $collectorName) }} {{- end }} @@ -42,6 +50,8 @@ {{- $collectorName = "alloy-profiles" }} {{- if (index .Values $collectorName).enabled }} {{- $atLeastOneFeatureEnabled := .Values.profiling.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).remoteConfig.enabled }} + {{- $atLeastOneFeatureEnabled = or $atLeastOneFeatureEnabled (index .Values $collectorName).extraConfig }} {{- if not $atLeastOneFeatureEnabled }} {{- fail (printf $errorMessage $collectorName $collectorName) }} {{- end }} diff --git a/charts/k8s-monitoring/values.schema.json b/charts/k8s-monitoring/values.schema.json index 025151c62..fc6036624 100644 --- a/charts/k8s-monitoring/values.schema.json +++ b/charts/k8s-monitoring/values.schema.json @@ -232,6 +232,77 @@ "type": "string" } } + }, + "remoteConfig": { + "type": "object", + "properties": { + "auth": { + "type": "object", + "properties": { + "password": { + "type": "string" + }, + "passwordFrom": { + "type": "string" + }, + "passwordKey": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "none", + "basic", + "bearerToken" + ] + }, + "username": { + "type": "string" + }, + "usernameFrom": { + "type": "string" + }, + "usernameKey": { + "type": "string" + } + } + }, + "enabled": { + "type": "boolean" + }, + "extraAttributes": { + "type": "object" + }, + "id": { + "type": "string" + }, + "pollFrequency": { + "type": "string" + }, + "secret": { + "type": "object", + "properties": { + "create": { + "type": "null" + }, + "embed": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + } + } + }, + "type": { + "type": "string" + }, + "url": { + "type": "string" + } + } } } }, diff --git a/charts/k8s-monitoring/values.yaml b/charts/k8s-monitoring/values.yaml index d5de7adb9..a1cd870d1 100644 --- a/charts/k8s-monitoring/values.yaml +++ b/charts/k8s-monitoring/values.yaml @@ -234,6 +234,61 @@ alloy-metrics: # @section -- Collectors - Alloy Metrics extraConfig: "" + # Remote configuration from a remote config server. + remoteConfig: + # -- Enable fetching configuration from a remote config server. + # @section -- Collectors - Alloy Metrics + enabled: false + + # -- The URL of the remote config server. + # @section -- Collectors - Alloy Metrics + url: "" + + auth: + # -- The type of authentication to use for the remote config server. + # @section -- Collectors - Alloy Metrics + type: "none" + + # -- The username to use for the remote config server. + # @section -- Collectors - Alloy Metrics + username: "" + usernameKey: "username" + usernameFrom: "" + + # -- The password to use for the remote config server. + # @section -- Collectors - Alloy Metrics + password: "" + passwordKey: "password" + passwordFrom: "" + + secret: + # -- (bool) Whether to create a secret for the remote config server. + # @default -- `true` + # @section -- Collectors - Alloy Metrics + create: + # -- If true, skip secret creation and embed the credentials directly into the configuration. + # @section -- Collectors - Alloy Metrics + embed: false + # -- The name of the secret to create. + # @section -- Collectors - Alloy Metrics + name: "" + # -- The namespace for the secret. + # @section -- Collectors - Alloy Metrics + namespace: "" + + # -- (string) The unique identifier for this Alloy instance. + # @default -- `--` + # @section -- Collectors - Alloy Metrics + id: "" + + # -- The frequency at which to poll the remote config server for updates. + # @section -- Collectors - Alloy Metrics + pollFrequency: 5m + + # -- Attributes to be added to this collector when requesting configuration. + # @section -- Collectors - Alloy Metrics + extraAttributes: {} + logging: # -- Level at which Alloy log lines should be written. # @section -- Collectors - Alloy Metrics