Skip to content

Commit

Permalink
WIP: start introducing the remotecfg component.
Browse files Browse the repository at this point in the history
Not working because the secret management templates are tied specifically to destinations

Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall committed Oct 22, 2024
1 parent ed99cf2 commit 36aded1
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 4 deletions.
Empty file.
12 changes: 12 additions & 0 deletions charts/k8s-monitoring/docs/examples/remote-config/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cluster:

Check failure on line 1 in charts/k8s-monitoring/docs/examples/remote-config/values.yaml

View workflow job for this annotation

GitHub Actions / runner / yamllint

[yamllint] reported by reviewdog 🐶 [warning] missing document start "---" (document-start) Raw Output: ./charts/k8s-monitoring/docs/examples/remote-config/values.yaml:1:1: [warning] missing document start "---" (document-start)
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"
5 changes: 4 additions & 1 deletion charts/k8s-monitoring/schema-mods/types-and-enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions charts/k8s-monitoring/templates/_validations.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:" }}
Expand Down
5 changes: 2 additions & 3 deletions charts/k8s-monitoring/templates/alloy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "collectors.extraConfig.alloy" -}}
{{- if (index .Values .collectorName).extraConfig }}
{{ (index .Values .collectorName).extraConfig | trim }}
{{- end }}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -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 -}}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }}

Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
71 changes: 71 additions & 0 deletions charts/k8s-monitoring/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
},
Expand Down
55 changes: 55 additions & 0 deletions charts/k8s-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- `<cluster>-<namespace>-<pod-name>`
# @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
Expand Down

0 comments on commit 36aded1

Please sign in to comment.