From 9f28b6538f49443aa4f1a7b9227dfd144a924cc7 Mon Sep 17 00:00:00 2001 From: Pete Wall Date: Fri, 3 Jan 2025 14:03:27 -0600 Subject: [PATCH] Option 4 Signed-off-by: Pete Wall --- .../docs/integrations/alloy.md | 2 +- .../integrations/alloy-values.yaml | 9 +- .../schema-mods/label-selectors.json | 13 + .../templates/_integration_alloy.tpl | 40 +- .../templates/_integration_cert-manager.tpl | 2 + .../templates/_integration_etcd.tpl | 2 + .../templates/_integration_loki.tpl | 1 + .../templates/_integration_mysql.tpl | 9 +- .../templates/_validation.tpl | 5 + .../feature-integrations/values.schema.json | 15 +- .../features/integrations/alloy/README.md | 4 +- .../integrations/alloy/alloy-metrics.alloy | 6 +- .../features/integrations/alloy/output.yaml | 6 +- .../features/integrations/alloy/values.yaml | 4 +- .../integrations/mysql/alloy-logs.alloy | 219 ---- .../integrations/mysql/alloy-metrics.alloy | 151 --- .../features/integrations/mysql/output.yaml | 994 ------------------ .../docs/examples/meta-monitoring/README.md | 2 + .../docs/examples/meta-monitoring/values.yaml | 2 + .../features/_feature_integrations.tpl | 2 + .../eks-with-windows/.rendered/output.yaml | 36 +- .../platform/eks-with-windows/values.yaml | 6 +- .../gke-autopilot/.rendered/output.yaml | 36 +- .../tests/platform/gke-autopilot/values.yaml | 6 +- .../otlp-gateway/.rendered/output.yaml | 8 +- .../tests/platform/otlp-gateway/values.yaml | 4 +- 26 files changed, 116 insertions(+), 1468 deletions(-) create mode 100644 charts/k8s-monitoring/charts/feature-integrations/schema-mods/label-selectors.json create mode 100644 charts/k8s-monitoring/charts/feature-integrations/templates/_validation.tpl diff --git a/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/alloy.md b/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/alloy.md index 74e1f0ba1..e6ebca4ff 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/alloy.md +++ b/charts/k8s-monitoring/charts/feature-integrations/docs/integrations/alloy.md @@ -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: ` 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 | diff --git a/charts/k8s-monitoring/charts/feature-integrations/integrations/alloy-values.yaml b/charts/k8s-monitoring/charts/feature-integrations/integrations/alloy-values.yaml index 8b26f58c9..8337bdf44 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/integrations/alloy-values.yaml +++ b/charts/k8s-monitoring/charts/feature-integrations/integrations/alloy-values.yaml @@ -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: ` 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 @@ -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 diff --git a/charts/k8s-monitoring/charts/feature-integrations/schema-mods/label-selectors.json b/charts/k8s-monitoring/charts/feature-integrations/schema-mods/label-selectors.json new file mode 100644 index 000000000..6c012d626 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-integrations/schema-mods/label-selectors.json @@ -0,0 +1,13 @@ +{ + "definitions": { + "alloy-integration": { + "properties": { + "labelSelectors": { + "additionalProperties": { + "oneOf": [{"type": "string"}, {"type": "array", "items": { "type": "string" }}] + } + } + } + } + } +} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_alloy.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_alloy.tpl index 15f2be7ce..09b370e33 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_alloy.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_alloy.tpl @@ -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 }} @@ -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 }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_cert-manager.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_cert-manager.tpl index 896476260..723bd7911 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_cert-manager.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_cert-manager.tpl @@ -68,3 +68,5 @@ cert_manager.scrape {{ include "helper.alloy_name" .name | quote }} { } {{- end }} {{- end }} + +{{- define "integrations.cert-manager.validate" }}{{- end }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_etcd.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_etcd.tpl index 89bb4b916..592d58437 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_etcd.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_etcd.tpl @@ -67,3 +67,5 @@ etcd.scrape {{ include "helper.alloy_name" .name | quote }} { } {{- end }} {{- end }} + +{{- define "integrations.etcd.validate" }}{{- end }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_loki.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_loki.tpl index 67b5c7bce..07cbefefa 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_loki.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_loki.tpl @@ -1,2 +1,3 @@ {{- define "integrations.loki.defaultSelectorLabel" -}}app.kubernetes.io/name{{- end }} {{- define "integrations.loki.defaultSelectorValue" -}}loki{{- end }} +{{- define "integrations.loki.validate" }}{{- end }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_mysql.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_mysql.tpl index c941fae11..0f4e99c14 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_mysql.tpl +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_integration_mysql.tpl @@ -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" }} @@ -28,7 +26,6 @@ {{- end }} {{- end }} {{- end }} -{{- end }} {{- define "secrets.list.integration.mysql" }} - exporter.dataSource.auth.username diff --git a/charts/k8s-monitoring/charts/feature-integrations/templates/_validation.tpl b/charts/k8s-monitoring/charts/feature-integrations/templates/_validation.tpl new file mode 100644 index 000000000..1547daef3 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-integrations/templates/_validation.tpl @@ -0,0 +1,5 @@ +{{- define "feature.integrations.validate" }} + {{- range $type := (include "integrations.types" .) | fromYamlArray }} + {{ include (printf "integrations.%s.validate" $type) $ }} + {{- end }} +{{- end }} diff --git a/charts/k8s-monitoring/charts/feature-integrations/values.schema.json b/charts/k8s-monitoring/charts/feature-integrations/values.schema.json index 638b4133b..3b32b2249 100644 --- a/charts/k8s-monitoring/charts/feature-integrations/values.schema.json +++ b/charts/k8s-monitoring/charts/feature-integrations/values.schema.json @@ -82,7 +82,20 @@ "type": "array" }, "labelSelectors": { - "type": "object" + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } }, "metrics": { "type": "object", diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/README.md b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/README.md index 7dda8b5ee..d6646df80 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/README.md +++ b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/README.md @@ -22,7 +22,9 @@ destinations: integrations: alloy: instances: - - name: alloy-metrics + - name: alloy + labelSelectors: + app.kubernetes.io/name: alloy-metrics alloy-metrics: enabled: true diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/alloy-metrics.alloy b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/alloy-metrics.alloy index a208492e5..b3dc3db3a 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/alloy-metrics.alloy +++ b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/alloy-metrics.alloy @@ -309,13 +309,13 @@ declare "alloy_integration" { } } - alloy_integration_discovery "alloy_metrics" { + alloy_integration_discovery "alloy" { port_name = "http-metrics" label_selectors = ["app.kubernetes.io/name=alloy-metrics"] } - alloy_integration_scrape "alloy_metrics" { - targets = alloy_integration_discovery.alloy_metrics.output + alloy_integration_scrape "alloy" { + targets = alloy_integration_discovery.alloy.output clustering = true keep_metrics = "up|alloy_build_info|alloy_component_controller_running_components|alloy_component_dependencies_wait_seconds|alloy_component_dependencies_wait_seconds_bucket|alloy_component_evaluation_seconds|alloy_component_evaluation_seconds_bucket|alloy_component_evaluation_seconds_count|alloy_component_evaluation_seconds_sum|alloy_component_evaluation_slow_seconds|alloy_config_hash|alloy_resources_machine_rx_bytes_total|alloy_resources_machine_tx_bytes_total|alloy_resources_process_cpu_seconds_total|alloy_resources_process_resident_memory_bytes|alloy_tcp_connections|alloy_wal_samples_appended_total|alloy_wal_storage_active_series|cluster_node_gossip_health_score|cluster_node_gossip_proto_version|cluster_node_gossip_received_events_total|cluster_node_info|cluster_node_lamport_time|cluster_node_peers|cluster_node_update_observers|cluster_transport_rx_bytes_total|cluster_transport_rx_packet_queue_length|cluster_transport_rx_packets_failed_total|cluster_transport_rx_packets_total|cluster_transport_stream_rx_bytes_total|cluster_transport_stream_rx_packets_failed_total|cluster_transport_stream_rx_packets_total|cluster_transport_stream_tx_bytes_total|cluster_transport_stream_tx_packets_failed_total|cluster_transport_stream_tx_packets_total|cluster_transport_streams|cluster_transport_tx_bytes_total|cluster_transport_tx_packet_queue_length|cluster_transport_tx_packets_failed_total|cluster_transport_tx_packets_total|otelcol_exporter_send_failed_spans_total|otelcol_exporter_sent_spans_total|go_gc_duration_seconds_count|go_goroutines|go_memstats_heap_inuse_bytes|loki_process_dropped_lines_total|loki_write_batch_retries_total|loki_write_dropped_bytes_total|loki_write_dropped_entries_total|loki_write_encoded_bytes_total|loki_write_mutated_bytes_total|loki_write_mutated_entries_total|loki_write_request_duration_seconds_bucket|loki_write_sent_bytes_total|loki_write_sent_entries_total|process_cpu_seconds_total|process_start_time_seconds|otelcol_processor_batch_batch_send_size_bucket|otelcol_processor_batch_metadata_cardinality|otelcol_processor_batch_timeout_trigger_send_total|prometheus_remote_storage_bytes_total|prometheus_remote_storage_enqueue_retries_total|prometheus_remote_storage_highest_timestamp_in_seconds|prometheus_remote_storage_metadata_bytes_total|prometheus_remote_storage_queue_highest_sent_timestamp_seconds|prometheus_remote_storage_samples_dropped_total|prometheus_remote_storage_samples_failed_total|prometheus_remote_storage_samples_pending|prometheus_remote_storage_samples_retried_total|prometheus_remote_storage_samples_total|prometheus_remote_storage_sent_batch_duration_seconds_bucket|prometheus_remote_storage_sent_batch_duration_seconds_count|prometheus_remote_storage_sent_batch_duration_seconds_sum|prometheus_remote_storage_shard_capacity|prometheus_remote_storage_shards|prometheus_remote_storage_shards_desired|prometheus_remote_storage_shards_max|prometheus_remote_storage_shards_min|prometheus_remote_storage_succeeded_samples_total|prometheus_remote_write_wal_samples_appended_total|prometheus_remote_write_wal_storage_active_series|prometheus_sd_discovered_targets|prometheus_target_interval_length_seconds_count|prometheus_target_interval_length_seconds_sum|prometheus_target_scrapes_exceeded_sample_limit_total|prometheus_target_scrapes_sample_duplicate_timestamp_total|prometheus_target_scrapes_sample_out_of_bounds_total|prometheus_target_scrapes_sample_out_of_order_total|prometheus_target_sync_length_seconds_sum|prometheus_wal_watcher_current_segment|otelcol_receiver_accepted_spans_total|otelcol_receiver_refused_spans_total|rpc_server_duration_milliseconds_bucket|scrape_duration_seconds|traces_exporter_send_failed_spans|traces_exporter_send_failed_spans_total|traces_exporter_sent_spans|traces_exporter_sent_spans_total|traces_loadbalancer_backend_outcome|traces_loadbalancer_num_backends|traces_receiver_accepted_spans|traces_receiver_accepted_spans_total|traces_receiver_refused_spans|traces_receiver_refused_spans_total" scrape_interval = "60s" diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/output.yaml b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/output.yaml index d6fc48c2a..2842d4a9a 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/output.yaml +++ b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/output.yaml @@ -334,13 +334,13 @@ data: } } - alloy_integration_discovery "alloy_metrics" { + alloy_integration_discovery "alloy" { port_name = "http-metrics" label_selectors = ["app.kubernetes.io/name=alloy-metrics"] } - alloy_integration_scrape "alloy_metrics" { - targets = alloy_integration_discovery.alloy_metrics.output + alloy_integration_scrape "alloy" { + targets = alloy_integration_discovery.alloy.output clustering = true keep_metrics = "up|alloy_build_info|alloy_component_controller_running_components|alloy_component_dependencies_wait_seconds|alloy_component_dependencies_wait_seconds_bucket|alloy_component_evaluation_seconds|alloy_component_evaluation_seconds_bucket|alloy_component_evaluation_seconds_count|alloy_component_evaluation_seconds_sum|alloy_component_evaluation_slow_seconds|alloy_config_hash|alloy_resources_machine_rx_bytes_total|alloy_resources_machine_tx_bytes_total|alloy_resources_process_cpu_seconds_total|alloy_resources_process_resident_memory_bytes|alloy_tcp_connections|alloy_wal_samples_appended_total|alloy_wal_storage_active_series|cluster_node_gossip_health_score|cluster_node_gossip_proto_version|cluster_node_gossip_received_events_total|cluster_node_info|cluster_node_lamport_time|cluster_node_peers|cluster_node_update_observers|cluster_transport_rx_bytes_total|cluster_transport_rx_packet_queue_length|cluster_transport_rx_packets_failed_total|cluster_transport_rx_packets_total|cluster_transport_stream_rx_bytes_total|cluster_transport_stream_rx_packets_failed_total|cluster_transport_stream_rx_packets_total|cluster_transport_stream_tx_bytes_total|cluster_transport_stream_tx_packets_failed_total|cluster_transport_stream_tx_packets_total|cluster_transport_streams|cluster_transport_tx_bytes_total|cluster_transport_tx_packet_queue_length|cluster_transport_tx_packets_failed_total|cluster_transport_tx_packets_total|otelcol_exporter_send_failed_spans_total|otelcol_exporter_sent_spans_total|go_gc_duration_seconds_count|go_goroutines|go_memstats_heap_inuse_bytes|loki_process_dropped_lines_total|loki_write_batch_retries_total|loki_write_dropped_bytes_total|loki_write_dropped_entries_total|loki_write_encoded_bytes_total|loki_write_mutated_bytes_total|loki_write_mutated_entries_total|loki_write_request_duration_seconds_bucket|loki_write_sent_bytes_total|loki_write_sent_entries_total|process_cpu_seconds_total|process_start_time_seconds|otelcol_processor_batch_batch_send_size_bucket|otelcol_processor_batch_metadata_cardinality|otelcol_processor_batch_timeout_trigger_send_total|prometheus_remote_storage_bytes_total|prometheus_remote_storage_enqueue_retries_total|prometheus_remote_storage_highest_timestamp_in_seconds|prometheus_remote_storage_metadata_bytes_total|prometheus_remote_storage_queue_highest_sent_timestamp_seconds|prometheus_remote_storage_samples_dropped_total|prometheus_remote_storage_samples_failed_total|prometheus_remote_storage_samples_pending|prometheus_remote_storage_samples_retried_total|prometheus_remote_storage_samples_total|prometheus_remote_storage_sent_batch_duration_seconds_bucket|prometheus_remote_storage_sent_batch_duration_seconds_count|prometheus_remote_storage_sent_batch_duration_seconds_sum|prometheus_remote_storage_shard_capacity|prometheus_remote_storage_shards|prometheus_remote_storage_shards_desired|prometheus_remote_storage_shards_max|prometheus_remote_storage_shards_min|prometheus_remote_storage_succeeded_samples_total|prometheus_remote_write_wal_samples_appended_total|prometheus_remote_write_wal_storage_active_series|prometheus_sd_discovered_targets|prometheus_target_interval_length_seconds_count|prometheus_target_interval_length_seconds_sum|prometheus_target_scrapes_exceeded_sample_limit_total|prometheus_target_scrapes_sample_duplicate_timestamp_total|prometheus_target_scrapes_sample_out_of_bounds_total|prometheus_target_scrapes_sample_out_of_order_total|prometheus_target_sync_length_seconds_sum|prometheus_wal_watcher_current_segment|otelcol_receiver_accepted_spans_total|otelcol_receiver_refused_spans_total|rpc_server_duration_milliseconds_bucket|scrape_duration_seconds|traces_exporter_send_failed_spans|traces_exporter_send_failed_spans_total|traces_exporter_sent_spans|traces_exporter_sent_spans_total|traces_loadbalancer_backend_outcome|traces_loadbalancer_num_backends|traces_receiver_accepted_spans|traces_receiver_accepted_spans_total|traces_receiver_refused_spans|traces_receiver_refused_spans_total" scrape_interval = "60s" diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/values.yaml b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/values.yaml index 09347ced5..20f7181ed 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/alloy/values.yaml +++ b/charts/k8s-monitoring/docs/examples/features/integrations/alloy/values.yaml @@ -10,7 +10,9 @@ destinations: integrations: alloy: instances: - - name: alloy-metrics + - name: alloy + labelSelectors: + app.kubernetes.io/name: alloy-metrics alloy-metrics: enabled: true diff --git a/charts/k8s-monitoring/docs/examples/features/integrations/mysql/alloy-logs.alloy b/charts/k8s-monitoring/docs/examples/features/integrations/mysql/alloy-logs.alloy index 5f98ce767..e69de29bb 100644 --- a/charts/k8s-monitoring/docs/examples/features/integrations/mysql/alloy-logs.alloy +++ b/charts/k8s-monitoring/docs/examples/features/integrations/mysql/alloy-logs.alloy @@ -1,219 +0,0 @@ -// Destination: loki (loki) -otelcol.exporter.loki "loki" { - forward_to = [loki.write.loki.receiver] -} - -loki.write "loki" { - endpoint { - url = "http://loki.loki.svc:3100/api/push" - tls_config { - insecure_skip_verify = false - } - } - external_labels = { - cluster = "mysql-integration-cluster", - "k8s_cluster_name" = "mysql-integration-cluster", - } -} - -// Feature: Pod Logs -declare "pod_logs" { - argument "logs_destinations" { - comment = "Must be a list of log destinations where collected logs should be forwarded to" - } - - discovery.relabel "filtered_pods" { - targets = discovery.kubernetes.pods.targets - rule { - source_labels = ["__meta_kubernetes_namespace"] - action = "replace" - target_label = "namespace" - } - rule { - source_labels = ["__meta_kubernetes_pod_name"] - action = "replace" - target_label = "pod" - } - rule { - source_labels = ["__meta_kubernetes_pod_container_name"] - action = "replace" - target_label = "container" - } - rule { - source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"] - separator = "/" - action = "replace" - replacement = "$1" - target_label = "job" - } - - // set the container runtime as a label - rule { - action = "replace" - source_labels = ["__meta_kubernetes_pod_container_id"] - regex = "^(\\S+):\\/\\/.+$" - replacement = "$1" - target_label = "tmp_container_runtime" - } - - // set the job label from the k8s.grafana.com/logs.job annotation if it exists - rule { - source_labels = ["__meta_kubernetes_pod_annotation_k8s_grafana_com_logs_job"] - regex = "(.+)" - target_label = "job" - } - - // make all labels on the pod available to the pipeline as labels, - // they are omitted before write to loki via stage.label_keep unless explicitly set - rule { - action = "labelmap" - regex = "__meta_kubernetes_pod_label_(.+)" - } - - // make all annotations on the pod available to the pipeline as labels, - // they are omitted before write to loki via stage.label_keep unless explicitly set - rule { - action = "labelmap" - regex = "__meta_kubernetes_pod_annotation_(.+)" - } - rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance","__meta_kubernetes_pod_label_app_kubernetes_io_name"] - separator = ";" - regex = "mysql;staging-db" - target_label = "integration" - replacement = "mysql" - } - rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance","__meta_kubernetes_pod_label_app_kubernetes_io_name"] - separator = ";" - regex = "mysql;staging-db" - target_label = "instance" - replacement = "staging-db" - } - rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance","__meta_kubernetes_pod_label_app_kubernetes_io_name"] - separator = ";" - regex = "mysql;prod-db" - target_label = "integration" - replacement = "mysql" - } - rule { - source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_instance","__meta_kubernetes_pod_label_app_kubernetes_io_name"] - separator = ";" - regex = "mysql;prod-db" - target_label = "instance" - replacement = "prod-db" - } - } - - discovery.kubernetes "pods" { - role = "pod" - selectors { - role = "pod" - field = "spec.nodeName=" + sys.env("HOSTNAME") - } - } - - discovery.relabel "filtered_pods_with_paths" { - targets = discovery.relabel.filtered_pods.output - - rule { - source_labels = ["__meta_kubernetes_pod_uid", "__meta_kubernetes_pod_container_name"] - separator = "/" - action = "replace" - replacement = "/var/log/pods/*$1/*.log" - target_label = "__path__" - } - } - - local.file_match "pod_logs" { - path_targets = discovery.relabel.filtered_pods_with_paths.output - } - - loki.source.file "pod_logs" { - targets = local.file_match.pod_logs.targets - forward_to = [loki.process.pod_logs.receiver] - } - - loki.process "pod_logs" { - stage.match { - selector = "{tmp_container_runtime=~\"containerd|cri-o\"}" - // the cri processing stage extracts the following k/v pairs: log, stream, time, flags - stage.cri {} - - // Set the extract flags and stream values as labels - stage.labels { - values = { - flags = "", - stream = "", - } - } - } - - stage.match { - selector = "{tmp_container_runtime=\"docker\"}" - // the docker processing stage extracts the following k/v pairs: log, stream, time - stage.docker {} - - // Set the extract stream value as a label - stage.labels { - values = { - stream = "", - } - } - } - - // Drop the filename label, since it's not really useful in the context of Kubernetes, where we already have cluster, - // namespace, pod, and container labels. Drop any structured metadata. Also drop the temporary - // container runtime label as it is no longer needed. - stage.label_drop { - values = [ - "filename", - "tmp_container_runtime", - ] - } - // Integration: MySQL - stage.match { - selector = "{integration=\"mysql\"}" - - stage.regex { - expression = `(?P.+) (?P[\d]+) \[(?P