Skip to content

Commit

Permalink
Should be working now
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 Oct 30, 2024
1 parent 859dda4 commit f155199
Show file tree
Hide file tree
Showing 40 changed files with 644 additions and 86 deletions.
31 changes: 22 additions & 9 deletions charts/feature-integrations/docs/integrations/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

## Values

### Exporter Settings

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| exporter.collectors | list | `["heartbeat","mysql.user"]` | The list of collectors to enable for the MySQL Exporter ([Documentation](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.mysql/#supported-collectors)). |
| exporter.dataSource | object | `{"auth":{"password":"","passwordFrom":"","passwordKey":"password","username":"","usernameFrom":"","usernameKey":"username"},"host":"","port":3306}` | The data source to use for the MySQL Exporter. |
| exporter.dataSource.auth.password | string | `""` | The password to use for the MySQL connection. |
| exporter.dataSource.auth.passwordFrom | string | `""` | Raw config for accessing the password. |
| exporter.dataSource.auth.passwordKey | string | `"password"` | The key for storing the password in the secret. |
| exporter.dataSource.auth.username | string | `""` | The username to use for the MySQL connection. |
| exporter.dataSource.auth.usernameFrom | string | `""` | Raw config for accessing the username. |
| exporter.dataSource.auth.usernameKey | string | `"username"` | The key for storing the username in the secret. |
| exporter.dataSource.host | string | `""` | The MySQL host to connect to. |
| exporter.dataSource.port | int | `3306` | The MySQL port to connect to. |
| exporter.dataSourceName | string | `""` | The data source string to use for the MySQL Exporter. |
| exporter.enabled | bool | `true` | Whether to enable the Alloy-embedded MySQL Exporter. |

### Discovery Settings

| Key | Type | Default | Description |
Expand All @@ -28,15 +45,11 @@
|-----|------|---------|-------------|
| scrapeInterval | string | `60s` | How frequently to scrape metrics from MySQL Exporter. |

### Other Values
### Secret

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| exporter.collectors[0] | string | `"heartbeat"` | |
| exporter.collectors[1] | string | `"mysql.user"` | |
| exporter.dataSource.host | string | `""` | |
| exporter.dataSource.password | string | `""` | |
| exporter.dataSource.port | int | `3306` | |
| exporter.dataSource.username | string | `""` | |
| exporter.dataSourceName | string | `""` | |
| exporter.enabled | bool | `true` | |
| secret.create | bool | `true` | Whether to create a secret to store credentials for this MySQL integration instance. |
| secret.embed | bool | `false` | If true, skip secret creation and embed the credentials directly into the configuration. |
| secret.name | string | `""` | The name of the secret to create. |
| secret.namespace | string | `""` | The namespace for the secret. |
61 changes: 43 additions & 18 deletions charts/feature-integrations/integrations/mysql-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,66 @@
# @section -- General Settings
name: ""

# Settings for the Alloy embedded MySQL Exporter
exporter:
# -- Whether to enable the Alloy-embedded MySQL Exporter.
# @section -- Exporter Settings
enabled: true

# TODO: Utilize the secret functions to use from
# -- The data source string to use for the MySQL Exporter.
# @section -- Exporter Settings
dataSourceName: ""

# -- The data source to use for the MySQL Exporter.
# @section -- Exporter Settings
dataSource:
# -- The MySQL host to connect to.
# @section -- Exporter Settings
host: ""
# -- The MySQL port to connect to.
# @section -- Exporter Settings
port: 3306
auth:
# -- The username to use for the MySQL connection.
# @section -- Exporter Settings
username: ""
usernameKey: ""
# -- The key for storing the username in the secret.
# @section -- Exporter Settings
usernameKey: "username"
# -- Raw config for accessing the username.
# @section -- Exporter Settings
usernameFrom: ""
# -- The password to use for the MySQL connection.
# @section -- Exporter Settings
password: ""
passwordKey: ""
# -- The key for storing the password in the secret.
# @section -- Exporter Settings
passwordKey: "password"
# -- Raw config for accessing the password.
# @section -- Exporter Settings
passwordFrom: ""

secret:
# -- (bool) Whether to create a secret for this MySQL integration instance.
# @default -- `true`
# @section -- Secret
create:
# -- If true, skip secret creation and embed the credentials directly into the configuration.
# @section -- Secret
embed: false
# -- The name of the secret to create.
# @section -- Secret
name: ""
# -- The namespace for the secret.
# @section -- Secret
namespace: ""

# -- The list of collectors to enable for the MySQL Exporter ([Documentation](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.mysql/#supported-collectors)).
# @section -- Exporter Settings
collectors:
- heartbeat
- mysql.user

secret:
# -- (bool) Whether to create a secret to store credentials for this MySQL integration instance.
# @default -- `true`
# @section -- Secret
create:
# -- If true, skip secret creation and embed the credentials directly into the configuration.
# @section -- Secret
embed: false
# -- The name of the secret to create.
# @section -- Secret
name: ""
# -- The namespace for the secret.
# @section -- Secret
namespace: ""

# -- Discover MySQL Exporter instances based on label selectors, if not using the exporter
# @section -- Discovery Settings
labelSelectors: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,34 @@
"dataSource": {
"type": "object",
"properties": {
"host": {
"type": "string"
"auth": {
"type": "object",
"properties": {
"password": {
"type": "string"
},
"passwordFrom": {
"type": "string"
},
"passwordKey": {
"type": "string"
},
"username": {
"type": "string"
},
"usernameFrom": {
"type": "string"
},
"usernameKey": {
"type": "string"
}
}
},
"password": {
"host": {
"type": "string"
},
"port": {
"type": "integer"
},
"username": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -58,6 +75,23 @@
"scrapeInterval": {
"type": "null"
},
"secret": {
"type": "object",
"properties": {
"create": {
"type": "null"
},
"embed": {
"type": "boolean"
},
"name": {
"type": "string"
},
"namespace": {
"type": "string"
}
}
},
"type": {
"type": "string",
"const": "mysql"
Expand Down
38 changes: 31 additions & 7 deletions charts/feature-integrations/templates/_integration_mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,41 @@ declare "mysql_integration" {
argument "metrics_destinations" {
comment = "Must be a list of metric destinations where collected metrics should be forwarded to"
}

{{- range $instance := $.Values.mysql.instances }}
{{- include "integrations.mysql.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }}
{{- include "integrations.mysql.include.metrics" (deepCopy $ | merge (dict "instance" $instance)) | nindent 2 }}
{{- end }}
}
{{- end }}

{{- define "integrations.mysql.include.metrics" }}
{{- $defaultValues := "integrations/mysql-values.yaml" | .Files.Get | fromYaml }}
{{- with deepCopy .integration | merge $defaultValues }}
{{- with merge .instance $defaultValues (dict "type" "integration.mysql") }}
{{- if .exporter.enabled }}
{{- if eq (include "secrets.usesKubernetesSecret" .) "true" }}
{{- include "secret.alloy" (deepCopy $ | merge (dict "object" .)) | nindent 0 }}
{{- end }}
prometheus.exporter.mysql {{ include "helper.alloy_name" .name | quote }} {
{{- if .exporter.dataSourceName }}
data_source_name = {{ .exporter.dataSourceName }}
data_source_name = {{ .exporter.dataSourceName | quote }}
{{- else }}
data_source_name = {{ printf "%s:%s@%s:%d/" .exporter.dataSource.username .exporter.dataSource.password .exporter.dataSource.host (.exporter.dataSource.port | int) | quote }}
{{- if eq (include "secrets.usesSecret" (dict "object" . "key" "exporter.dataSource.auth.username")) "true" }}
{{- if eq (include "secrets.usesSecret" (dict "object" . "key" "exporter.dataSource.auth.password")) "true" }}
data_source_name = string.format("%s:%s@(%s:%d)/",
{{ include "secrets.read" (dict "object" . "key" "exporter.dataSource.auth.username" "nonsensitive" true) }},
{{ include "secrets.read" (dict "object" . "key" "exporter.dataSource.auth.password") }},
{{ .exporter.dataSource.host | quote }},
{{ .exporter.dataSource.port | int }},
)
{{- else }}
data_source_name = string.format("%s@(%s:%d)/",
{{ include "secrets.read" (dict "object" . "key" "exporter.dataSource.auth.username" "nonsensitive" true) }},
{{ .exporter.dataSource.host | quote }},
{{ .exporter.dataSource.port | int }},
)
{{- end }}
{{- else }}
data_source_name = string.format("%s:%d/", {{ .exporter.dataSource.host | quote }}, {{ .exporter.dataSource.port | int }})
{{- end }}
{{- end }}
enable_collectors = {{ .exporter.collectors | toJson }}
}
Expand Down Expand Up @@ -60,13 +79,13 @@ promtheus.relabel {{ include "helper.alloy_name" .name | quote }} {

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

{{- define "integrations.mysql.instance.validate" }}
{{- $defaultValues := "integrations/mysql-values.yaml" | .Files.Get | fromYaml }}
{{- with merge .integration $defaultValues }}
{{- with merge .instance $defaultValues }}
{{- if .exporter.enabled }}
{{- if and (not .exporter.dataSourceName) (not (and .exporter.dataSource.username .exporter.dataSource.password .exporter.dataSource.host)) }}
{{- $msg := list "" "Missing data source details for MySQL exporter." }}
Expand All @@ -89,3 +108,8 @@ promtheus.relabel {{ include "helper.alloy_name" .name | quote }} {
{{- end }}
{{- end }}
{{- end }}

{{- define "secrets.list.integration.mysql" }}
- exporter.dataSource.auth.username
- exporter.dataSource.auth.password
{{- end }}
2 changes: 1 addition & 1 deletion charts/feature-integrations/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data:
metrics.alloy: |-
{{- range $type := (include "integrations.types" . | fromYamlArray) }}
{{- if (index $.Values $type).instances }}
{{- include (printf "integrations.%s.module.metrics" $type) (dict "Values" $.Values "Files" $.Files) | indent 4 }}
{{- include (printf "integrations.%s.module.metrics" $type) $ | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/feature-integrations/templates/mysql-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- range $instance := .Values.mysql.instances }}
{{- $instance = merge $instance (dict "type" "integration.mysql") }}
{{- if eq (include "secrets.shouldCreateKubernetesSecret" $instance ) "true" }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "secrets.kubernetesSecretName" (deepCopy $ | merge (dict "object" $instance)) | quote }}
namespace: {{ include "secrets.kubernetesSecretNamespace" (deepCopy $ | merge (dict "object" $instance)) | quote }}
stringData:
{{- $secrets := include "secrets.list.integration.mysql" $instance | fromYamlArray }}
{{- range $secret := $secrets }}
{{- $value := include "secrets.getSecretValue" (dict "object" $instance "key" $secret) -}}
{{- if $value }}
{{ include "secrets.getSecretKey" (dict "object" $instance "key" $secret) }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
Loading

0 comments on commit f155199

Please sign in to comment.