From e6083b163ffa244913eb2b326d3f27fb5103ec16 Mon Sep 17 00:00:00 2001 From: Kevin Tibi <2437140+ktibi@users.noreply.github.com> Date: Mon, 7 Aug 2023 12:42:16 +0200 Subject: [PATCH] Extend configuration for customMetrics (#202) --- docs/eks/index.md | 13 ++++++++----- modules/eks-monitoring/README.md | 2 +- modules/eks-monitoring/main.tf | 8 ++------ modules/eks-monitoring/otel-config/Chart.yaml | 4 ++-- .../templates/opentelemetrycollector.yaml | 19 ++++++++++++++----- .../eks-monitoring/otel-config/values.yaml | 3 +-- modules/eks-monitoring/variables.tf | 19 +++++++++---------- 7 files changed, 37 insertions(+), 31 deletions(-) diff --git a/docs/eks/index.md b/docs/eks/index.md index afa2e3c..1db3453 100644 --- a/docs/eks/index.md +++ b/docs/eks/index.md @@ -170,11 +170,14 @@ In the module `module "workloads_infra" {` add the following config (make sure t enable_custom_metrics = true custom_metrics_config = { - # list of applications ports (example) - ports = [8000, 8080] - - # list of series prefixes you want to discard from ingestion - dropped_series_prefixes = ["go_gcc"] + custom_app_1 = { + enableBasicAuth = true + path = "/metrics" + basicAuthUsername = "username" + basicAuthPassword = "password" + ports = ".*:(8080)$" + droppedSeriesPrefixes = "(unspecified.*)$" + } } ``` diff --git a/modules/eks-monitoring/README.md b/modules/eks-monitoring/README.md index 0269284..bd66cd8 100644 --- a/modules/eks-monitoring/README.md +++ b/modules/eks-monitoring/README.md @@ -67,7 +67,7 @@ See examples using this Terraform modules in the **Amazon EKS** section of [this | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [adot\_loglevel](#input\_adot\_loglevel) | Verbosity level for ADOT collector logs | `string` | `"warn"` | no | -| [custom\_metrics\_config](#input\_custom\_metrics\_config) | Configuration object to enable custom metrics collection |
object({
ports = list(number)
# paths = optional(list(string), ["/metrics"])
# list of samples to be dropped by label prefix, ex: go_ -> discards go_.*
dropped_series_prefixes = list(string)
}) | {
"dropped_series_prefixes": [
"unspecified"
],
"ports": []
} | no |
+| [custom\_metrics\_config](#input\_custom\_metrics\_config) | Configuration object to enable custom metrics collection | map(object({
enableBasicAuth = bool
path = string
basicAuthUsername = string
basicAuthPassword = string
ports = string
droppedSeriesPrefixes = string
})) | `null` | no |
| [eks\_cluster\_id](#input\_eks\_cluster\_id) | EKS Cluster Id | `string` | n/a | yes |
| [enable\_alerting\_rules](#input\_enable\_alerting\_rules) | Enables or disables Managed Prometheus alerting rules | `bool` | `true` | no |
| [enable\_amazon\_eks\_adot](#input\_enable\_amazon\_eks\_adot) | Enables the ADOT Operator on the EKS Cluster | `bool` | `true` | no |
diff --git a/modules/eks-monitoring/main.tf b/modules/eks-monitoring/main.tf
index 308a04e..5f5dcd6 100644
--- a/modules/eks-monitoring/main.tf
+++ b/modules/eks-monitoring/main.tf
@@ -138,12 +138,8 @@ module "helm_addon" {
value = var.enable_custom_metrics
},
{
- name = "customMetricsPorts"
- value = format(".*:(%s)$", join("|", var.custom_metrics_config.ports))
- },
- {
- name = "customMetricsDroppedSeriesPrefixes"
- value = format("(%s.*)$", join(".*|", var.custom_metrics_config.dropped_series_prefixes))
+ name = "custom_metrics"
+ value = yamlencode(var.custom_metrics_config)
},
{
name = "enableJava"
diff --git a/modules/eks-monitoring/otel-config/Chart.yaml b/modules/eks-monitoring/otel-config/Chart.yaml
index 5f55abe..ae933ab 100644
--- a/modules/eks-monitoring/otel-config/Chart.yaml
+++ b/modules/eks-monitoring/otel-config/Chart.yaml
@@ -2,5 +2,5 @@ apiVersion: v2
name: opentelemetry
description: A Helm chart to install otel operator
type: application
-version: 0.6.0
-appVersion: 0.6.0
+version: 0.7.0
+appVersion: 0.7.0
diff --git a/modules/eks-monitoring/otel-config/templates/opentelemetrycollector.yaml b/modules/eks-monitoring/otel-config/templates/opentelemetrycollector.yaml
index 850bbca..bfbd938 100644
--- a/modules/eks-monitoring/otel-config/templates/opentelemetrycollector.yaml
+++ b/modules/eks-monitoring/otel-config/templates/opentelemetrycollector.yaml
@@ -1464,13 +1464,21 @@ spec:
regex: $K8S_NODE_NAME
source_labels: [__meta_kubernetes_endpoint_node_name]
{{ end }}
- - job_name: "custom-metrics"
+ {{ if .Values.enableCustomMetrics }}
+ {{- range $k, $v := fromYaml .Values.customMetrics }}
+ - job_name: "{{ $k }}"
kubernetes_sd_configs:
- role: pod
+ metrics_path: '{{ $v.path }}'
+ {{ if $v.enableBasicAuth }}
+ basic_auth:
+ username: '{{ $v.basicAuthUsername }}'
+ password: '{{ $v.basicAuthPassword }}'
+ {{ end }}
relabel_configs:
- source_labels: [ __address__ ]
action: keep
- regex: '{{ .Values.customMetricsPorts }}'
+ regex: '{{ $v.ports }}'
- action: replace
source_labels: [__meta_kubernetes_pod_node_name]
target_label: nodename
@@ -1486,16 +1494,17 @@ spec:
- action: replace
source_labels: [__meta_kubernetes_pod_controller_kind]
target_label: pod_controller_kind
- {{ if .Values.enableTracing }}
+ {{ if $.Values.enableTracing }}
- action: keep
regex: $K8S_NODE_NAME
source_labels: [__meta_kubernetes_pod_node_name]
{{ end }}
metric_relabel_configs:
- source_labels: [ __name__ ]
- regex: '{{ .Values.customMetricsDroppedSeriesPrefixes }}'
+ regex: '{{ $v.droppedSeriesPrefixes }}'
action: drop
-
+ {{- end }}
+ {{ end }}
{{ if .Values.enableJava }}
- job_name: 'kubernetes-java-jmx'
sample_limit: {{ .Values.javaScrapeSampleLimit }}
diff --git a/modules/eks-monitoring/otel-config/values.yaml b/modules/eks-monitoring/otel-config/values.yaml
index 64e6998..d0f91fb 100644
--- a/modules/eks-monitoring/otel-config/values.yaml
+++ b/modules/eks-monitoring/otel-config/values.yaml
@@ -13,8 +13,7 @@ tracingTimeout: ${tracing_timeout}
tracingSendBatchSize: ${tracing_send_batch_size}
enableCustomMetrics: ${enable_custom_metrics}
-customMetricsPorts: ${custom_metrics_ports}
-customMetricsDroppedSeriesPrefixes: ${custom_metrics_dropped_series_prefixes}
+customMetrics: ${custom_metrics}
enableJava: ${enable_java}
javaScrapeSampleLimit: ${java_scrape_sample_limit}
diff --git a/modules/eks-monitoring/variables.tf b/modules/eks-monitoring/variables.tf
index 13fc60f..6d64c13 100644
--- a/modules/eks-monitoring/variables.tf
+++ b/modules/eks-monitoring/variables.tf
@@ -232,17 +232,16 @@ variable "enable_custom_metrics" {
variable "custom_metrics_config" {
description = "Configuration object to enable custom metrics collection"
- type = object({
- ports = list(number)
- # paths = optional(list(string), ["/metrics"])
- # list of samples to be dropped by label prefix, ex: go_ -> discards go_.*
- dropped_series_prefixes = list(string)
- })
+ type = map(object({
+ enableBasicAuth = bool
+ path = string
+ basicAuthUsername = string
+ basicAuthPassword = string
+ ports = string
+ droppedSeriesPrefixes = string
+ }))
- default = {
- ports = []
- dropped_series_prefixes = ["unspecified"]
- }
+ default = null
}
variable "enable_java" {