diff --git a/.github/workflows/platform-test.yml b/.github/workflows/platform-test.yml index efb4be8f7..b7c2c168f 100644 --- a/.github/workflows/platform-test.yml +++ b/.github/workflows/platform-test.yml @@ -42,6 +42,7 @@ jobs: name: Platform Test needs: list-tests runs-on: ubuntu-latest + if: ${{ needs.list-tests.outputs.tests != '[]' }} strategy: matrix: test: ${{ fromJson(needs.list-tests.outputs.tests) }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5d4cde295..7082b4386 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,10 +42,9 @@ Each component has its own guide for contributing: - [Feature subcharts](./charts/k8s-monitoring/docs/Features.md#Contributing) +- [Integrations](./charts/feature-integrations/README.md#Contributing) - [Destinations](./charts/k8s-monitoring/docs/destinations/README.md#Contributing) - - ## Building Lots of files in this repository are generated in order to reduce duplication and ensure consistency. To build these diff --git a/charts/feature-integrations/README.md b/charts/feature-integrations/README.md index 3f4506446..bd43b4cdf 100644 --- a/charts/feature-integrations/README.md +++ b/charts/feature-integrations/README.md @@ -105,3 +105,50 @@ Actual integration testing in a live environment should be done in the main [k8s | global.alloyModules.source | string | `"git"` | The source of the Alloy modules. The valid options are "configMap" or "git" | | global.maxCacheSize | int | `100000` | Sets the max_cache_size for every prometheus.relabel component. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/#arguments)) This should be at least 2x-5x your largest scrape target or samples appended rate. | | global.scrapeInterval | string | `"60s"` | How frequently to scrape metrics. | + +### Integration: MySQL + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| mysql | object | `{"instances":[]}` | Scrape metrics from MySQL | + +## Contributing + +To contribute integrations to this feature, there are a few files that need to be created or modified: + +* `values.yaml` - The main feature chart's values file. Add a section for your integration. It must contain an + `instance` array and any settings that apply to every instance of the integration. For example: + + ```yaml + : + instances: [] + globalSetting: value + ``` + +* `integrations/-values.yaml` - The values that will be used for each instance. This must include `name` to + differentiate it from other instances, and any other settings that are specific to that instance. For example: + + ```yaml + name: "" + labelSelectors: + app.kubernetes.io/name: my-service + protocol: http + ... + ``` + +* `templates/_integration<=_.tpl` - The file that contains template functions that build the configuration to + discover, gather, process, and deliver the telemetry data. This file is required to implement the following template + functions: + * `integrations..type.metrics` - Returns true if this integration scrapes metrics. + * `integrations..type.logs` - Returns true if this integration gathers logs. + * `integrations..module` - Returns the configuration that is included once if this integration is used. This + is typically the module definition. + * `integrations..include.metrics` - Returns the configuration that is included for each instance of the + integration that scrapes metrics. + * `integrations..include.logs` - Returns the configuration that is included for each instance of the + integration that gathers logs. + * `integrations..exclude.logs` - Returns a rule that can be used by other Log-gathering features to ensure + that logs that are gathered from this integration are not collected twice. Typically the inverse of a rule in + the `integrations..include.logs` function. + * `default-allow-lists/.yaml` - If the integration scrapes metrics, a common pattern is to provide a list of + metrics that should be allowed. This minimizes the amount of metrics delivered to a useful minimal set. diff --git a/charts/feature-integrations/README.md.gotmpl b/charts/feature-integrations/README.md.gotmpl index 9158dc327..d8c25334f 100644 --- a/charts/feature-integrations/README.md.gotmpl +++ b/charts/feature-integrations/README.md.gotmpl @@ -66,3 +66,44 @@ Actual integration testing in a live environment should be done in the main [k8s {{ template "chart.requirementsSection" . }} {{ template "chart.valuesSection" . }} + +## Contributing + +To contribute integrations to this feature, there are a few files that need to be created or modified: + +* `values.yaml` - The main feature chart's values file. Add a section for your integration. It must contain an + `instance` array and any settings that apply to every instance of the integration. For example: + + ```yaml + : + instances: [] + globalSetting: value + ``` + +* `integrations/-values.yaml` - The values that will be used for each instance. This must include `name` to + differentiate it from other instances, and any other settings that are specific to that instance. For example: + + ```yaml + name: "" + labelSelectors: + app.kubernetes.io/name: my-service + protocol: http + ... + ``` + +* `templates/_integration<=_.tpl` - The file that contains template functions that build the configuration to + discover, gather, process, and deliver the telemetry data. This file is required to implement the following template + functions: + * `integrations..type.metrics` - Returns true if this integration scrapes metrics. + * `integrations..type.logs` - Returns true if this integration gathers logs. + * `integrations..module` - Returns the configuration that is included once if this integration is used. This + is typically the module definition. + * `integrations..include.metrics` - Returns the configuration that is included for each instance of the + integration that scrapes metrics. + * `integrations..include.logs` - Returns the configuration that is included for each instance of the + integration that gathers logs. + * `integrations..exclude.logs` - Returns a rule that can be used by other Log-gathering features to ensure + that logs that are gathered from this integration are not collected twice. Typically the inverse of a rule in + the `integrations..include.logs` function. + * `default-allow-lists/.yaml` - If the integration scrapes metrics, a common pattern is to provide a list of + metrics that should be allowed. This minimizes the amount of metrics delivered to a useful minimal set. diff --git a/charts/feature-integrations/docs/integrations/alloy.md b/charts/feature-integrations/docs/integrations/alloy.md index 5054f91ed..062e111ca 100644 --- a/charts/feature-integrations/docs/integrations/alloy.md +++ b/charts/feature-integrations/docs/integrations/alloy.md @@ -28,4 +28,4 @@ | Key | Type | Default | Description | |-----|------|---------|-------------| -| scrapeInterval | string | `60s` | How frequently to scrape metrics from Windows Exporter. | +| scrapeInterval | string | `60s` | How frequently to scrape metrics from Alloy. | diff --git a/charts/feature-integrations/docs/integrations/mysql.md b/charts/feature-integrations/docs/integrations/mysql.md new file mode 100644 index 000000000..5a2ce7ab1 --- /dev/null +++ b/charts/feature-integrations/docs/integrations/mysql.md @@ -0,0 +1,55 @@ +# mysql + +## 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. | + +### Logs Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| logs.enabled | bool | `true` | Whether to enable special processing of MySQL pod logs. | +| logs.labelSelectors | object | `{}` | Label selectors to choose the set of pods to gather logs from for this MySQL Instance. Example: `app.kubernetes.io/name: mysql` | + +### Metric Processing Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| maxCacheSize | string | `100000` | Sets the max_cache_size for prometheus.relabel component. This should be at least 2x-5x your largest scrape target or samples appended rate. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) Overrides global.maxCacheSize | +| metricsTuning.excludeMetrics | list | `[]` | Metrics to drop. Can use regular expressions. | +| metricsTuning.includeMetrics | list | `[]` | Metrics to keep. Can use regular expressions. | + +### General Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| name | string | `""` | Name for this MySQL instance. | + +### Scrape Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| scrapeInterval | string | `60s` | How frequently to scrape metrics from MySQL Exporter. | + +### Secret + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| 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. | diff --git a/charts/feature-integrations/integrations/alloy-values.yaml b/charts/feature-integrations/integrations/alloy-values.yaml index 6de4e92f5..1b5d367af 100644 --- a/charts/feature-integrations/integrations/alloy-values.yaml +++ b/charts/feature-integrations/integrations/alloy-values.yaml @@ -8,7 +8,7 @@ name: "" labelSelectors: app.kubernetes.io/name: alloy -# -- How frequently to scrape metrics from Windows Exporter. +# -- How frequently to scrape metrics from Alloy. # @default -- `60s` # @section -- Scrape Settings scrapeInterval: diff --git a/charts/feature-integrations/integrations/mysql-values.yaml b/charts/feature-integrations/integrations/mysql-values.yaml new file mode 100644 index 000000000..ce49ce421 --- /dev/null +++ b/charts/feature-integrations/integrations/mysql-values.yaml @@ -0,0 +1,94 @@ +--- +# -- Name for this MySQL instance. +# @section -- General Settings +name: "" + +# Settings for log gathering using the Pod Logs feature +logs: + # -- Whether to enable special processing of MySQL pod logs. + # @section -- Logs Settings + enabled: true + + # -- Label selectors to choose the set of pods to gather logs from for this MySQL Instance. + # Example: + # `app.kubernetes.io/name: mysql` + # @section -- Logs Settings + labelSelectors: {} + +# Settings for the Alloy embedded MySQL Exporter +exporter: + # -- 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: "" + # -- 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: "" + # -- The key for storing the password in the secret. + # @section -- Exporter Settings + passwordKey: "password" + # -- Raw config for accessing the password. + # @section -- Exporter Settings + passwordFrom: "" + + # -- 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: "" + +# -- How frequently to scrape metrics from MySQL Exporter. +# @default -- `60s` +# @section -- Scrape Settings +scrapeInterval: + +# Adjustments to the scraped metrics to filter the amount of data sent to storage. +metricsTuning: + # -- Metrics to keep. Can use regular expressions. + # @section -- Metric Processing Settings + includeMetrics: [] + # -- Metrics to drop. Can use regular expressions. + # @section -- Metric Processing Settings + excludeMetrics: [] + +# -- Sets the max_cache_size for prometheus.relabel component. +# This should be at least 2x-5x your largest scrape target or samples appended rate. +# ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus.relabel/#arguments)) +# Overrides global.maxCacheSize +# @default -- `100000` +# @section -- Metric Processing Settings +maxCacheSize: diff --git a/charts/feature-integrations/schema-mods/definitions/mysql-integration.schema.json b/charts/feature-integrations/schema-mods/definitions/mysql-integration.schema.json new file mode 100644 index 000000000..2593881e5 --- /dev/null +++ b/charts/feature-integrations/schema-mods/definitions/mysql-integration.schema.json @@ -0,0 +1,105 @@ +{ + "type": "object", + "properties": { + "exporter": { + "type": "object", + "properties": { + "collectors": { + "type": "array", + "items": { + "type": "string" + } + }, + "dataSource": { + "type": "object", + "properties": { + "auth": { + "type": "object", + "properties": { + "password": { + "type": "string" + }, + "passwordFrom": { + "type": "string" + }, + "passwordKey": { + "type": "string" + }, + "username": { + "type": "string" + }, + "usernameFrom": { + "type": "string" + }, + "usernameKey": { + "type": "string" + } + } + }, + "host": { + "type": "string" + }, + "port": { + "type": "integer" + } + } + }, + "dataSourceName": { + "type": "string" + } + } + }, + "logs": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "labelSelectors": { + "type": "object" + } + } + }, + "maxCacheSize": { + "type": "null" + }, + "metricsTuning": { + "type": "object", + "properties": { + "excludeMetrics": { + "type": "array" + }, + "includeMetrics": { + "type": "array" + } + } + }, + "name": { + "type": "string" + }, + "scrapeInterval": { + "type": "null" + }, + "secret": { + "type": "object", + "properties": { + "create": { + "type": "null" + }, + "embed": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + } + } + }, + "type": { + "type": "string", + "const": "mysql" + } + } +} diff --git a/charts/feature-integrations/schema-mods/integration-list.json b/charts/feature-integrations/schema-mods/integration-list.json index fb35e6b87..3fb057e3c 100644 --- a/charts/feature-integrations/schema-mods/integration-list.json +++ b/charts/feature-integrations/schema-mods/integration-list.json @@ -6,7 +6,8 @@ "anyOf": [ { "$ref": "#/definitions/alloy-integration"}, { "$ref": "#/definitions/cert-manager-integration"}, - { "$ref": "#/definitions/etcd-integration"} + { "$ref": "#/definitions/etcd-integration"}, + { "$ref": "#/definitions/mysql-integration"} ] } } diff --git a/charts/feature-integrations/templates/_helpers.tpl b/charts/feature-integrations/templates/_helpers.tpl index 273f4a856..04e4c6b70 100644 --- a/charts/feature-integrations/templates/_helpers.tpl +++ b/charts/feature-integrations/templates/_helpers.tpl @@ -19,3 +19,11 @@ If release name contains chart name it will be used as a full name. {{ define "helper.alloy_name" }} {{- . | lower | replace "-" "_" -}} {{ end }} + +{{- define "escape_label" -}} +{{ . | replace "-" "_" | replace "." "_" | replace "/" "_" }} +{{- end }} + +{{- define "pod_label" -}} +{{ printf "__meta_kubernetes_pod_label_%s" (include "escape_label" .) }} +{{- end }} diff --git a/charts/feature-integrations/templates/_integration_alloy.tpl b/charts/feature-integrations/templates/_integration_alloy.tpl index 102ab4ac6..5a4227168 100644 --- a/charts/feature-integrations/templates/_integration_alloy.tpl +++ b/charts/feature-integrations/templates/_integration_alloy.tpl @@ -288,7 +288,7 @@ declare "alloy_integration" { } } {{- range $instance := $.Values.alloy.instances }} - {{- include "integrations.alloy.include.metrics" (dict "integration" $instance "Values" $.Values "Files" $.Files) | nindent 2 }} + {{- include "integrations.alloy.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }} {{- end }} } {{- end }} @@ -297,7 +297,7 @@ declare "alloy_integration" { {{/* Inputs: integration (Alloy integration definition), Values (all values), Files (Files object) */}} {{- define "integrations.alloy.include.metrics" }} {{- $defaultValues := "integrations/alloy-values.yaml" | .Files.Get | fromYaml }} -{{- with merge .integration $defaultValues }} +{{- with deepCopy .integration | merge $defaultValues }} {{- $metricAllowList := include "integrations.alloy.allowList" (dict "integration" . "Files" $.Files) }} {{- $metricDenyList := .excludeMetrics }} {{- $labelSelectors := list }} diff --git a/charts/feature-integrations/templates/_integration_cert-manager.tpl b/charts/feature-integrations/templates/_integration_cert-manager.tpl index 99a648647..43f9c27b6 100644 --- a/charts/feature-integrations/templates/_integration_cert-manager.tpl +++ b/charts/feature-integrations/templates/_integration_cert-manager.tpl @@ -11,7 +11,7 @@ declare "cert_manager_integration" { {{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "cert_manager" "path" "modules/kubernetes/cert-manager/metrics.alloy")) | nindent 2 }} {{- range $instance := (index $.Values "cert-manager").instances }} - {{- include "integrations.cert-manager.include.metrics" (dict "integration" $instance "Values" $.Values "Files" $.Files) | nindent 2 }} + {{- include "integrations.cert-manager.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }} {{- end }} } {{- end }} @@ -20,7 +20,7 @@ declare "cert_manager_integration" { {{/* Inputs: integration (cert-manager integration definition), Values (all values), Files (Files object) */}} {{- define "integrations.cert-manager.include.metrics" }} {{- $defaultValues := "integrations/cert-manager-values.yaml" | .Files.Get | fromYaml }} -{{- with merge .integration $defaultValues }} +{{- with deepCopy .integration | merge $defaultValues }} {{- $metricAllowList := .metricsTuning.includeMetrics }} {{- $metricDenyList := .metricsTuning.excludeMetrics }} {{- $labelSelectors := list }} diff --git a/charts/feature-integrations/templates/_integration_etcd.tpl b/charts/feature-integrations/templates/_integration_etcd.tpl index 8230721b5..49baf0147 100644 --- a/charts/feature-integrations/templates/_integration_etcd.tpl +++ b/charts/feature-integrations/templates/_integration_etcd.tpl @@ -11,7 +11,7 @@ declare "etcd_integration" { {{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "etcd" "path" "modules/databases/kv/etcd/metrics.alloy")) | nindent 2 }} {{- range $instance := (index $.Values "etcd").instances }} - {{- include "integrations.etcd.include.metrics" (dict "integration" $instance "Values" $.Values "Files" $.Files) | nindent 2 }} + {{- include "integrations.etcd.include.metrics" (deepCopy $ | merge (dict "integration" $instance)) | nindent 2 }} {{- end }} } {{- end }} @@ -20,7 +20,7 @@ declare "etcd_integration" { {{/* Inputs: integration (etcd integration definition), Values (all values), Files (Files object) */}} {{- define "integrations.etcd.include.metrics" }} {{- $defaultValues := "integrations/etcd-values.yaml" | .Files.Get | fromYaml }} -{{- with merge .integration $defaultValues }} +{{- with deepCopy .integration | merge $defaultValues }} {{- $metricAllowList := .metricsTuning.includeMetrics }} {{- $metricDenyList := .metricsTuning.excludeMetrics }} {{- $labelSelectors := list }} diff --git a/charts/feature-integrations/templates/_integration_helpers.tpl b/charts/feature-integrations/templates/_integration_helpers.tpl index 3b7760f41..ef57a6b05 100644 --- a/charts/feature-integrations/templates/_integration_helpers.tpl +++ b/charts/feature-integrations/templates/_integration_helpers.tpl @@ -2,7 +2,7 @@ {{- define "feature.integrations.configured.metrics" }} {{- range $type := (include "integrations.types" .) | fromYamlArray }} {{- if (index $.Values $type).instances }} - {{- if eq (include (printf "integrations.%s.type.metrics" $type) .) "true" }} + {{- if eq (include (printf "integrations.%s.type.metrics" $type) $) "true" }} - {{ $type }} {{- end }} {{- end }} @@ -13,7 +13,7 @@ {{- define "feature.integrations.configured.logs" }} {{- range $type := (include "integrations.types" .) | fromYamlArray }} {{- if (index $.Values $type).instances }} - {{- if eq (include (printf "integrations.%s.type.logs" $type) .) "true" }} + {{- if eq (include (printf "integrations.%s.type.logs" $type) $) "true" }} - {{ $type }} {{- end }} {{- end }} diff --git a/charts/feature-integrations/templates/_integration_mysql.tpl b/charts/feature-integrations/templates/_integration_mysql.tpl new file mode 100644 index 000000000..c941fae11 --- /dev/null +++ b/charts/feature-integrations/templates/_integration_mysql.tpl @@ -0,0 +1,36 @@ +{{- define "integrations.mysql.validate" }} + {{- range $instance := $.Values.mysql.instances }} + {{- 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 .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." }} + {{- $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 " exporter:" }} + {{- $msg = append $msg " dataSourceName: \"user:pass@database.namespace.svc:3306\"" }} + {{- $msg = append $msg "OR" }} + {{- $msg = append $msg " exporter:" }} + {{- $msg = append $msg " dataSource:" }} + {{- $msg = append $msg " username: user" }} + {{- $msg = append $msg " password: pass" }} + {{- $msg = append $msg " host: database.namespace.svc" }} + {{- $msg = append $msg " port: 3306" }} + {{- fail (join "\n" $msg) }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} + +{{- define "secrets.list.integration.mysql" }} +- exporter.dataSource.auth.username +- exporter.dataSource.auth.password +{{- end }} diff --git a/charts/feature-integrations/templates/_integration_mysql_logs.tpl b/charts/feature-integrations/templates/_integration_mysql_logs.tpl new file mode 100644 index 000000000..6cc01dbfe --- /dev/null +++ b/charts/feature-integrations/templates/_integration_mysql_logs.tpl @@ -0,0 +1,82 @@ +{{/* Inputs: . (Values) */}} +{{- define "integrations.mysql.type.logs" }} +{{- $defaultValues := "integrations/mysql-values.yaml" | .Files.Get | fromYaml }} +{{- $logsEnabled := false }} +{{- range $instance := .Values.mysql.instances }} + {{- with merge $instance $defaultValues (dict "type" "integration.mysql") }} + {{- $logsEnabled = or $logsEnabled $instance.logs.enabled }} + {{- end }} +{{- end }} +{{- $logsEnabled -}} +{{- end }} + +{{- define "integrations.mysql.logs.discoveryRules" }} +{{- range $instance := $.Values.mysql.instances }} +{{- if $instance.logs.enabled }} +{{- $labelList := list }} +{{- $valueList := list }} +{{- $selectors := dict "app.kubernetes.io/name" "mysql" "app.kubernetes.io/instance" $instance.name }} +{{- if $instance.logs.labelSelectors }} + {{- $selectors = $instance.logs.labelSelectors }} +{{- end }} + +{{- range (keys $selectors) }} + {{- $labelList = append $labelList (include "pod_label" .) -}} + {{- $valueList = append $valueList (index $selectors .) -}} +{{- end }} + +{{- if $instance.logs.enabled }} +rule { + source_labels = {{ $labelList | toJson }} + separator = ";" + regex = {{ $valueList | join ";" | quote }} + target_label = "integration" + replacement = "mysql" +} +rule { + source_labels = {{ $labelList | toJson }} + separator = ";" + regex = {{ $valueList | join ";" | quote }} + target_label = "instance" + replacement = {{ $instance.name | quote }} +} +{{- end }} +{{- end }} +{{- end }} +{{- end }} + +{{- define "integrations.mysql.logs.processingStage" }} +{{- if eq (include "integrations.mysql.type.logs" .) "true" }} +// Integration: MySQL +stage.match { + selector = "{integration=\"mysql\"}" + + stage.regex { + expression = `(?P.+) (?P[\d]+) \[(?P