Skip to content

Commit e6083b1

Browse files
authored
Extend configuration for customMetrics (#202)
1 parent 05589cd commit e6083b1

File tree

7 files changed

+37
-31
lines changed

7 files changed

+37
-31
lines changed

docs/eks/index.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,14 @@ In the module `module "workloads_infra" {` add the following config (make sure t
170170
enable_custom_metrics = true
171171
172172
custom_metrics_config = {
173-
# list of applications ports (example)
174-
ports = [8000, 8080]
175-
176-
# list of series prefixes you want to discard from ingestion
177-
dropped_series_prefixes = ["go_gcc"]
173+
custom_app_1 = {
174+
enableBasicAuth = true
175+
path = "/metrics"
176+
basicAuthUsername = "username"
177+
basicAuthPassword = "password"
178+
ports = ".*:(8080)$"
179+
droppedSeriesPrefixes = "(unspecified.*)$"
180+
}
178181
}
179182
```
180183

modules/eks-monitoring/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ See examples using this Terraform modules in the **Amazon EKS** section of [this
6767
| Name | Description | Type | Default | Required |
6868
|------|-------------|------|---------|:--------:|
6969
| <a name="input_adot_loglevel"></a> [adot\_loglevel](#input\_adot\_loglevel) | Verbosity level for ADOT collector logs | `string` | `"warn"` | no |
70-
| <a name="input_custom_metrics_config"></a> [custom\_metrics\_config](#input\_custom\_metrics\_config) | Configuration object to enable custom metrics collection | <pre>object({<br> ports = list(number)<br> # paths = optional(list(string), ["/metrics"])<br> # list of samples to be dropped by label prefix, ex: go_ -> discards go_.*<br> dropped_series_prefixes = list(string)<br> })</pre> | <pre>{<br> "dropped_series_prefixes": [<br> "unspecified"<br> ],<br> "ports": []<br>}</pre> | no |
70+
| <a name="input_custom_metrics_config"></a> [custom\_metrics\_config](#input\_custom\_metrics\_config) | Configuration object to enable custom metrics collection | <pre>map(object({<br> enableBasicAuth = bool<br> path = string<br> basicAuthUsername = string<br> basicAuthPassword = string<br> ports = string<br> droppedSeriesPrefixes = string<br> }))</pre> | `null` | no |
7171
| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | EKS Cluster Id | `string` | n/a | yes |
7272
| <a name="input_enable_alerting_rules"></a> [enable\_alerting\_rules](#input\_enable\_alerting\_rules) | Enables or disables Managed Prometheus alerting rules | `bool` | `true` | no |
7373
| <a name="input_enable_amazon_eks_adot"></a> [enable\_amazon\_eks\_adot](#input\_enable\_amazon\_eks\_adot) | Enables the ADOT Operator on the EKS Cluster | `bool` | `true` | no |

modules/eks-monitoring/main.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,8 @@ module "helm_addon" {
138138
value = var.enable_custom_metrics
139139
},
140140
{
141-
name = "customMetricsPorts"
142-
value = format(".*:(%s)$", join("|", var.custom_metrics_config.ports))
143-
},
144-
{
145-
name = "customMetricsDroppedSeriesPrefixes"
146-
value = format("(%s.*)$", join(".*|", var.custom_metrics_config.dropped_series_prefixes))
141+
name = "custom_metrics"
142+
value = yamlencode(var.custom_metrics_config)
147143
},
148144
{
149145
name = "enableJava"

modules/eks-monitoring/otel-config/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: opentelemetry
33
description: A Helm chart to install otel operator
44
type: application
5-
version: 0.6.0
6-
appVersion: 0.6.0
5+
version: 0.7.0
6+
appVersion: 0.7.0

modules/eks-monitoring/otel-config/templates/opentelemetrycollector.yaml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,13 +1464,21 @@ spec:
14641464
regex: $K8S_NODE_NAME
14651465
source_labels: [__meta_kubernetes_endpoint_node_name]
14661466
{{ end }}
1467-
- job_name: "custom-metrics"
1467+
{{ if .Values.enableCustomMetrics }}
1468+
{{- range $k, $v := fromYaml .Values.customMetrics }}
1469+
- job_name: "{{ $k }}"
14681470
kubernetes_sd_configs:
14691471
- role: pod
1472+
metrics_path: '{{ $v.path }}'
1473+
{{ if $v.enableBasicAuth }}
1474+
basic_auth:
1475+
username: '{{ $v.basicAuthUsername }}'
1476+
password: '{{ $v.basicAuthPassword }}'
1477+
{{ end }}
14701478
relabel_configs:
14711479
- source_labels: [ __address__ ]
14721480
action: keep
1473-
regex: '{{ .Values.customMetricsPorts }}'
1481+
regex: '{{ $v.ports }}'
14741482
- action: replace
14751483
source_labels: [__meta_kubernetes_pod_node_name]
14761484
target_label: nodename
@@ -1486,16 +1494,17 @@ spec:
14861494
- action: replace
14871495
source_labels: [__meta_kubernetes_pod_controller_kind]
14881496
target_label: pod_controller_kind
1489-
{{ if .Values.enableTracing }}
1497+
{{ if $.Values.enableTracing }}
14901498
- action: keep
14911499
regex: $K8S_NODE_NAME
14921500
source_labels: [__meta_kubernetes_pod_node_name]
14931501
{{ end }}
14941502
metric_relabel_configs:
14951503
- source_labels: [ __name__ ]
1496-
regex: '{{ .Values.customMetricsDroppedSeriesPrefixes }}'
1504+
regex: '{{ $v.droppedSeriesPrefixes }}'
14971505
action: drop
1498-
1506+
{{- end }}
1507+
{{ end }}
14991508
{{ if .Values.enableJava }}
15001509
- job_name: 'kubernetes-java-jmx'
15011510
sample_limit: {{ .Values.javaScrapeSampleLimit }}

modules/eks-monitoring/otel-config/values.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ tracingTimeout: ${tracing_timeout}
1313
tracingSendBatchSize: ${tracing_send_batch_size}
1414

1515
enableCustomMetrics: ${enable_custom_metrics}
16-
customMetricsPorts: ${custom_metrics_ports}
17-
customMetricsDroppedSeriesPrefixes: ${custom_metrics_dropped_series_prefixes}
16+
customMetrics: ${custom_metrics}
1817

1918
enableJava: ${enable_java}
2019
javaScrapeSampleLimit: ${java_scrape_sample_limit}

modules/eks-monitoring/variables.tf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,16 @@ variable "enable_custom_metrics" {
232232

233233
variable "custom_metrics_config" {
234234
description = "Configuration object to enable custom metrics collection"
235-
type = object({
236-
ports = list(number)
237-
# paths = optional(list(string), ["/metrics"])
238-
# list of samples to be dropped by label prefix, ex: go_ -> discards go_.*
239-
dropped_series_prefixes = list(string)
240-
})
235+
type = map(object({
236+
enableBasicAuth = bool
237+
path = string
238+
basicAuthUsername = string
239+
basicAuthPassword = string
240+
ports = string
241+
droppedSeriesPrefixes = string
242+
}))
241243

242-
default = {
243-
ports = []
244-
dropped_series_prefixes = ["unspecified"]
245-
}
244+
default = null
246245
}
247246

248247
variable "enable_java" {

0 commit comments

Comments
 (0)