Skip to content

Commit 65c50e6

Browse files
authored
Nginx config options (#265)
* Nginx config options * Fix variable type mismatch for nginx pattern module * Allow partial declaration of config variables with defaults * Add telemetry log level configuration * remove coalesce function * Formatting
1 parent b6d044e commit 65c50e6

File tree

7 files changed

+99
-128
lines changed

7 files changed

+99
-128
lines changed

modules/eks-monitoring/README.md

Lines changed: 10 additions & 9 deletions
Large diffs are not rendered by default.

modules/eks-monitoring/locals.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ locals {
5757
grafana_dashboard_url = "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/v0.2.0/artifacts/grafana-dashboards/eks/java/default.json"
5858
}
5959

60-
nginx_pattern_config = {
60+
nginx_pattern_config_defaults = {
6161
# disabled if options from module are disabled, by default
6262
# can be overriden by providing a config
6363
enable_alerting_rules = var.enable_alerting_rules
@@ -78,6 +78,11 @@ locals {
7878
grafana_dashboard_url = "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/v0.2.0/artifacts/grafana-dashboards/eks/nginx/nginx.json"
7979
}
8080

81+
nginx_pattern_config = {
82+
# Merge input variable with defaults and rebuild with non-null values
83+
for k, v in merge(local.nginx_pattern_config_defaults, var.nginx_config) : k => v != null ? v : local.nginx_pattern_config_defaults[k]
84+
}
85+
8186
istio_pattern_config = {
8287
# disabled if options from module are disabled, by default
8388
# can be overriden by providing a config

modules/eks-monitoring/main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ module "helm_addon" {
120120
name = "adotLoglevel"
121121
value = var.adot_loglevel
122122
},
123+
{
124+
name = "adotServiceTelemetryLoglevel"
125+
value = var.adot_service_telemetry_loglevel
126+
},
123127
{
124128
name = "accountId"
125129
value = local.context.aws_caller_identity_account_id
@@ -174,11 +178,11 @@ module "helm_addon" {
174178
},
175179
{
176180
name = "nginxScrapeSampleLimit"
177-
value = try(var.nginx_config.scrape_sample_limit, local.nginx_pattern_config.scrape_sample_limit)
181+
value = local.nginx_pattern_config.scrape_sample_limit
178182
},
179183
{
180184
name = "nginxPrometheusMetricsEndpoint"
181-
value = try(var.nginx_config.prometheus_metrics_endpoint, local.nginx_pattern_config.prometheus_metrics_endpoint)
185+
value = local.nginx_pattern_config.prometheus_metrics_endpoint
182186
},
183187
{
184188
name = "enableIstio"
@@ -239,7 +243,7 @@ module "nginx_monitoring" {
239243
source = "./patterns/nginx"
240244
count = var.enable_nginx ? 1 : 0
241245

242-
pattern_config = coalesce(var.nginx_config, local.nginx_pattern_config)
246+
pattern_config = local.nginx_pattern_config
243247
}
244248

245249
module "istio_monitoring" {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,9 @@ spec:
15361536
exporters: [logging, prometheusremotewrite]
15371537
{{ if .Values.enableAdotcollectorMetrics }}
15381538
metrics/1:
1539-
receivers: [prometheus/1]
1540-
processors: []
1541-
exporters: [prometheusremotewrite]
1539+
receivers: [prometheus/1]
1540+
processors: []
1541+
exporters: [prometheusremotewrite]
15421542
{{ end }}
15431543
{{ if .Values.enableTracing }}
15441544
traces:
@@ -1551,4 +1551,6 @@ spec:
15511551
metrics:
15521552
address: 0.0.0.0:8888
15531553
level: basic
1554+
logging:
1555+
level: {{ .Values.adotServiceTelemetryLoglevel }}
15541556
{{ end }}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ istioScrapeSampleLimit: ${istio_scrape_sample_limit}
3232
istioPrometheusMetricsEndpoint: ${istio_prometheus_metrics_endpoint}
3333

3434
adotLoglevel: ${adot_loglevel}
35+
adotServiceTelemetryLoglevel: ${adot_service_telemetry_loglevel}
3536

3637
enableAdotcollectorMetrics: ${enable_adotcollector_metrics}
3738

modules/eks-monitoring/variables.tf

Lines changed: 69 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ variable "irsa_iam_additional_policies" {
5858
}
5959

6060
variable "adot_loglevel" {
61-
description = "Verbosity level for ADOT collector logs. This accepts (detailed|normal|basic), see https://aws-otel.github.io/docs/components/misc-exporters for mor infos."
61+
description = "Verbosity level for ADOT collector logs. This accepts (detailed|normal|basic), see https://aws-otel.github.io/docs/components/misc-exporters for more info."
6262
type = string
6363
default = "normal"
6464
}
6565

66+
variable "adot_service_telemetry_loglevel" {
67+
description = "Verbosity level for ADOT service telemetry logs. See https://opentelemetry.io/docs/collector/configuration/#telemetry for more info."
68+
type = string
69+
default = "INFO"
70+
}
71+
6672
variable "managed_prometheus_workspace_endpoint" {
6773
description = "Amazon Managed Prometheus Workspace Endpoint"
6874
type = string
@@ -144,32 +150,20 @@ variable "enable_kube_state_metrics" {
144150
variable "ksm_config" {
145151
description = "Kube State metrics configuration"
146152
type = object({
147-
create_namespace = bool
148-
k8s_namespace = string
149-
helm_chart_name = string
150-
helm_chart_version = string
151-
helm_release_name = string
152-
helm_repo_url = string
153-
helm_settings = map(string)
154-
helm_values = map(any)
155-
156-
scrape_interval = string
157-
scrape_timeout = string
153+
create_namespace = optional(bool, true)
154+
k8s_namespace = optional(string, "kube-system")
155+
helm_chart_name = optional(string, "kube-state-metrics")
156+
helm_chart_version = optional(string, "5.15.2")
157+
helm_release_name = optional(string, "kube-state-metrics")
158+
helm_repo_url = optional(string, "https://prometheus-community.github.io/helm-charts")
159+
helm_settings = optional(map(string), {})
160+
helm_values = optional(map(any), {})
161+
162+
scrape_interval = optional(string, "60s")
163+
scrape_timeout = optional(string, "15s")
158164
})
159165

160-
default = {
161-
create_namespace = true
162-
helm_chart_name = "kube-state-metrics"
163-
helm_chart_version = "5.15.2"
164-
helm_release_name = "kube-state-metrics"
165-
helm_repo_url = "https://prometheus-community.github.io/helm-charts"
166-
helm_settings = {}
167-
helm_values = {}
168-
k8s_namespace = "kube-system"
169-
170-
scrape_interval = "60s"
171-
scrape_timeout = "15s"
172-
}
166+
default = {}
173167
nullable = false
174168
}
175169

@@ -182,32 +176,20 @@ variable "enable_node_exporter" {
182176
variable "ne_config" {
183177
description = "Node exporter configuration"
184178
type = object({
185-
create_namespace = bool
186-
k8s_namespace = string
187-
helm_chart_name = string
188-
helm_chart_version = string
189-
helm_release_name = string
190-
helm_repo_url = string
191-
helm_settings = map(string)
192-
helm_values = map(any)
193-
194-
scrape_interval = string
195-
scrape_timeout = string
179+
create_namespace = optional(bool, true)
180+
k8s_namespace = optional(string, "prometheus-node-exporter")
181+
helm_chart_name = optional(string, "prometheus-node-exporter")
182+
helm_chart_version = optional(string, "4.24.0")
183+
helm_release_name = optional(string, "prometheus-node-exporter")
184+
helm_repo_url = optional(string, "https://prometheus-community.github.io/helm-charts")
185+
helm_settings = optional(map(string), {})
186+
helm_values = optional(map(any), {})
187+
188+
scrape_interval = optional(string, "60s")
189+
scrape_timeout = optional(string, "60s")
196190
})
197191

198-
default = {
199-
create_namespace = true
200-
helm_chart_name = "prometheus-node-exporter"
201-
helm_chart_version = "4.24.0"
202-
helm_release_name = "prometheus-node-exporter"
203-
helm_repo_url = "https://prometheus-community.github.io/helm-charts"
204-
helm_settings = {}
205-
helm_values = {}
206-
k8s_namespace = "prometheus-node-exporter"
207-
208-
scrape_interval = "60s"
209-
scrape_timeout = "60s"
210-
}
192+
default = {}
211193
nullable = false
212194
}
213195

@@ -220,14 +202,11 @@ variable "tags" {
220202
variable "prometheus_config" {
221203
description = "Controls default values such as scrape interval, timeouts and ports globally"
222204
type = object({
223-
global_scrape_interval = string
224-
global_scrape_timeout = string
205+
global_scrape_interval = optional(string, "120s")
206+
global_scrape_timeout = optional(string, "15s")
225207
})
226208

227-
default = {
228-
global_scrape_interval = "120s"
229-
global_scrape_timeout = "15s"
230-
}
209+
default = {}
231210
nullable = false
232211
}
233212

@@ -266,18 +245,14 @@ variable "enable_tracing" {
266245
variable "tracing_config" {
267246
description = "Configuration object for traces collection to AWS X-Ray"
268247
type = object({
269-
otlp_grpc_endpoint = string
270-
otlp_http_endpoint = string
271-
send_batch_size = number
272-
timeout = string
248+
otlp_grpc_endpoint = optional(string, "0.0.0.0:4317")
249+
otlp_http_endpoint = optional(string, "0.0.0.0:4318")
250+
send_batch_size = optional(number, 50)
251+
timeout = optional(string, "30s")
273252
})
274253

275-
default = {
276-
otlp_grpc_endpoint = "0.0.0.0:4317"
277-
otlp_http_endpoint = "0.0.0.0:4318"
278-
send_batch_size = 50
279-
timeout = "30s"
280-
}
254+
default = {}
255+
nullable = false
281256
}
282257

283258
variable "enable_custom_metrics" {
@@ -336,28 +311,27 @@ variable "enable_nginx" {
336311
default = false
337312
}
338313

339-
340314
variable "nginx_config" {
341315
description = "Configuration object for NGINX monitoring"
342316
type = object({
343-
enable_alerting_rules = bool
344-
enable_recording_rules = bool
345-
enable_dashboards = bool
346-
scrape_sample_limit = number
317+
enable_alerting_rules = optional(bool)
318+
enable_recording_rules = optional(bool)
319+
enable_dashboards = optional(bool)
320+
scrape_sample_limit = optional(number)
347321

348-
flux_gitrepository_name = string
349-
flux_gitrepository_url = string
350-
flux_gitrepository_branch = string
351-
flux_kustomization_name = string
352-
flux_kustomization_path = string
322+
flux_gitrepository_name = optional(string)
323+
flux_gitrepository_url = optional(string)
324+
flux_gitrepository_branch = optional(string)
325+
flux_kustomization_name = optional(string)
326+
flux_kustomization_path = optional(string)
353327

354-
grafana_dashboard_url = string
328+
grafana_dashboard_url = optional(string)
355329

356-
prometheus_metrics_endpoint = string
330+
prometheus_metrics_endpoint = optional(string)
357331
})
358332

359-
# defaults are pre-computed in locals.tf, provide a full definition to override
360-
default = null
333+
# defaults are pre-computed in locals.tf
334+
default = {}
361335
}
362336

363337
variable "enable_istio" {
@@ -423,26 +397,17 @@ variable "enable_fluxcd" {
423397
variable "flux_config" {
424398
description = "FluxCD configuration"
425399
type = object({
426-
create_namespace = bool
427-
k8s_namespace = string
428-
helm_chart_name = string
429-
helm_chart_version = string
430-
helm_release_name = string
431-
helm_repo_url = string
432-
helm_settings = map(string)
433-
helm_values = map(any)
400+
create_namespace = optional(bool, true)
401+
k8s_namespace = optional(string, "flux-system")
402+
helm_chart_name = optional(string, "flux2")
403+
helm_chart_version = optional(string, "2.12.2")
404+
helm_release_name = optional(string, "observability-fluxcd-addon")
405+
helm_repo_url = optional(string, "https://fluxcd-community.github.io/helm-charts")
406+
helm_settings = optional(map(string), {})
407+
helm_values = optional(map(any), {})
434408
})
435409

436-
default = {
437-
create_namespace = true
438-
helm_chart_name = "flux2"
439-
helm_chart_version = "2.12.2"
440-
helm_release_name = "observability-fluxcd-addon"
441-
helm_repo_url = "https://fluxcd-community.github.io/helm-charts"
442-
helm_settings = {}
443-
helm_values = {}
444-
k8s_namespace = "flux-system"
445-
}
410+
default = {}
446411
nullable = false
447412
}
448413

@@ -455,22 +420,15 @@ variable "enable_grafana_operator" {
455420
variable "go_config" {
456421
description = "Grafana Operator configuration"
457422
type = object({
458-
create_namespace = bool
459-
helm_chart = string
460-
helm_name = string
461-
k8s_namespace = string
462-
helm_release_name = string
463-
helm_chart_version = string
423+
create_namespace = optional(bool, true)
424+
helm_chart = optional(string, "oci://ghcr.io/grafana-operator/helm-charts/grafana-operator")
425+
helm_name = optional(string, "grafana-operator")
426+
k8s_namespace = optional(string, "grafana-operator")
427+
helm_release_name = optional(string, "grafana-operator")
428+
helm_chart_version = optional(string, "v5.5.2")
464429
})
465430

466-
default = {
467-
create_namespace = true
468-
helm_chart = "oci://ghcr.io/grafana-operator/helm-charts/grafana-operator"
469-
helm_name = "grafana-operator"
470-
k8s_namespace = "grafana-operator"
471-
helm_release_name = "grafana-operator"
472-
helm_chart_version = "v5.5.2"
473-
}
431+
default = {}
474432
nullable = false
475433
}
476434

modules/eks-monitoring/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.1.0"
2+
required_version = ">= 1.3.0"
33

44
required_providers {
55
aws = {

0 commit comments

Comments
 (0)