Skip to content

Commit

Permalink
Option 4
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall committed Jan 3, 2025
1 parent c22f4cc commit 9f28b65
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 1,468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| fieldSelectors | list | `[]` | Discover Alloy instances based on field selectors. |
| labelSelectors | object | `{}` | Discover Alloy instances based on label selectors. Will automatically set a matcher for `app.kubernetes.io/name: <name>` unless set here. |
| labelSelectors | object | `{}` | Discover Alloy instances based on label selectors. |
| metrics.portName | string | `"http-metrics"` | Name of the port to scrape metrics from. |
| namespaces | list | `[]` | The namespaces to look for Alloy instances in. Will automatically look for Alloy instances in all namespaces unless specified here |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# @section -- General Settings
name: ""

# -- Discover Alloy instances based on label selectors.
# Will automatically set a matcher for `app.kubernetes.io/name: <name>` unless set here.
# @section -- Discovery Settings
labelSelectors: {}

# -- The namespaces to look for Alloy instances in.
# Will automatically look for Alloy instances in all namespaces unless specified here
# @section -- Discovery Settings
Expand All @@ -17,6 +12,10 @@ namespaces: []
# @section -- Discovery Settings
fieldSelectors: []

# -- Discover Alloy instances based on label selectors.
# @section -- Discovery Settings
labelSelectors: {}

metrics:
# -- Whether to enable metrics collection from Alloy.
# @section -- Metrics Settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"definitions": {
"alloy-integration": {
"properties": {
"labelSelectors": {
"additionalProperties": {
"oneOf": [{"type": "string"}, {"type": "array", "items": { "type": "string" }}]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,22 @@ declare "alloy_integration" {
{{- with $defaultValues | merge (deepCopy .instance) }}
{{- $metricAllowList := include "integrations.alloy.allowList" (dict "instance" . "Files" $.Files) | fromYamlArray }}
{{- $metricDenyList := .excludeMetrics }}

{{- $nameLabelDefined := false }}
{{- $labelSelectors := list }}
{{- range $k, $v := .labelSelectors }}
{{- if eq $k "app.kubernetes.io/name" }}{{- $nameLabelDefined = true }}{{- end }}
{{- if $v }}
{{- if kindIs "slice" $v }}
{{- $labelSelectors = append $labelSelectors (printf "%s in (%s)" $k (join "," $v)) }}
{{- else }}
{{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }}
{{- end }}
{{- end }}
{{- if not $nameLabelDefined }}
{{- $labelSelectors = append $labelSelectors (printf "app.kubernetes.io/name=%s" .name) }}
{{- end }}

{{- $fieldSelectors := list }}
{{- range $k, $v := .fieldSelectors }}
{{- $fieldSelectors = append $fieldSelectors (printf "%s=%s" $k $v) }}
{{- if kindIs "slice" $v }}
{{- $fieldSelectors = append $fieldSelectors (printf "%s in (%s)" $k (join "," $v)) }}
{{- else }}
{{- $fieldSelectors = append $fieldSelectors (printf "%s=%s" $k $v) }}
{{- end }}
{{- end }}
alloy_integration_discovery {{ include "helper.alloy_name" .name | quote }} {
port_name = {{ .metrics.portName | quote }}
Expand Down Expand Up @@ -268,3 +269,26 @@ alloy_integration_scrape {{ include "helper.alloy_name" .name | quote }} {
}
{{- end }}
{{- end }}

{{- define "integrations.alloy.validate" }}
{{- range $instance := $.Values.alloy.instances }}
{{- include "integrations.alloy.instance.validate" (merge $ (dict "instance" $instance)) | nindent 2 }}
{{- end }}
{{- end }}

{{- define "integrations.alloy.instance.validate" }}
{{- if not .instance.labelSelectors }}
{{- $msg := list "" "The Alloy integration requires a label selector" }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "integrations:" }}
{{- $msg = append $msg " alloy:" }}
{{- $msg = append $msg " instances:" }}
{{- $msg = append $msg (printf " - name: %s" .instance.name) }}
{{- $msg = append $msg " labelSelectors:" }}
{{- $msg = append $msg (printf " app.kubernetes.io/name: %s" .instance.name) }}
{{- $msg = append $msg "OR" }}
{{- $msg = append $msg " labelSelectors:" }}
{{- $msg = append $msg " app.kubernetes.io/name: [alloy-one, alloy-two]" }}
{{- fail (join "\n" $msg) }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ cert_manager.scrape {{ include "helper.alloy_name" .name | quote }} {
}
{{- end }}
{{- end }}

{{- define "integrations.cert-manager.validate" }}{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ etcd.scrape {{ include "helper.alloy_name" .name | quote }} {
}
{{- end }}
{{- end }}

{{- define "integrations.etcd.validate" }}{{- end }}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{{- define "integrations.loki.defaultSelectorLabel" -}}app.kubernetes.io/name{{- end }}
{{- define "integrations.loki.defaultSelectorValue" -}}loki{{- end }}
{{- define "integrations.loki.validate" }}{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
{{- end }}

{{- define "integrations.mysql.instance.validate" }}
{{- $defaultValues := "integrations/mysql-values.yaml" | .Files.Get | fromYaml }}
{{- with merge .instance $defaultValues }}
{{- if .exporter.enabled }}
{{- if and (not .exporter.dataSourceName) (not (and .exporter.dataSource.username .exporter.dataSource.password .exporter.dataSource.host)) }}
{{- if .instance.exporter.enabled }}
{{- if and (not .instance.exporter.dataSourceName) (not (and .instance.exporter.dataSource.username .instance.exporter.dataSource.password .instance.exporter.dataSource.host)) }}
{{- $msg := list "" "Missing data source details for MySQL exporter." }}
{{- $msg = append $msg "Please set:" }}
{{- $msg = append $msg "integrations:" }}
{{- $msg = append $msg " mysql:" }}
{{- $msg = append $msg " instances:" }}
{{- $msg = append $msg (printf " - name: %s" .name) }}
{{- $msg = append $msg (printf " - name: %s" .instance.name) }}
{{- $msg = append $msg " exporter:" }}
{{- $msg = append $msg " dataSourceName: \"user:pass@database.namespace.svc:3306\"" }}
{{- $msg = append $msg "OR" }}
Expand All @@ -28,7 +26,6 @@
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- define "secrets.list.integration.mysql" }}
- exporter.dataSource.auth.username
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "feature.integrations.validate" }}
{{- range $type := (include "integrations.types" .) | fromYamlArray }}
{{ include (printf "integrations.%s.validate" $type) $ }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@
"type": "array"
},
"labelSelectors": {
"type": "object"
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"metrics": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ destinations:
integrations:
alloy:
instances:
- name: alloy-metrics
- name: alloy
labelSelectors:
app.kubernetes.io/name: alloy-metrics

alloy-metrics:
enabled: true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ destinations:
integrations:
alloy:
instances:
- name: alloy-metrics
- name: alloy
labelSelectors:
app.kubernetes.io/name: alloy-metrics

alloy-metrics:
enabled: true
Loading

0 comments on commit 9f28b65

Please sign in to comment.