diff --git a/CHANGELOG.md b/CHANGELOG.md index be6f6b41cb..c02ee123dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,10 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- fix(helm): always create default metrics source if traces are enabled [#2182][#2182] + [Unreleased]: https://github.com/SumoLogic/sumologic-kubernetes-collection/compare/v2.6.0...main [#2170]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2170 [#2177]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2177 [#2173]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2173 +[#2182]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2182 ## [v2.6.0][v2.6.0] diff --git a/deploy/helm/sumologic/conf/setup/locals.tf b/deploy/helm/sumologic/conf/setup/locals.tf index bdeea24b3c..27a9fdd4da 100644 --- a/deploy/helm/sumologic/conf/setup/locals.tf +++ b/deploy/helm/sumologic/conf/setup/locals.tf @@ -1,12 +1,19 @@ locals { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} -{{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} -{{- range $key, $source := $sources }} -{{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ template "terraform.sources.local" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Value" $source.name) }} -{{- end }} -{{- end }} -{{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- if hasKey $sources "default" }} + {{ template "terraform.sources.local" (dict "Name" (include "terraform.sources.name" (dict "Name" "default" "Type" $type)) "Value" ( dig "default" "name" "(default-metrics)" $sources )) }} + {{- end }} + {{- end }} {{- end }} } diff --git a/deploy/helm/sumologic/conf/setup/resources.tf b/deploy/helm/sumologic/conf/setup/resources.tf index 495357f3aa..81195e3698 100644 --- a/deploy/helm/sumologic/conf/setup/resources.tf +++ b/deploy/helm/sumologic/conf/setup/resources.tf @@ -11,13 +11,20 @@ resource "sumologic_collector" "collector" { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} -{{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} -{{- range $key, $source := $sources }} -{{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ include "terraform.sources.resource" (dict "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type)) "Source" $source "Context" $ctx) | nindent 2 }} -{{- end }} -{{- end }} -{{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- if hasKey $sources "default" }} +{{ include "terraform.sources.resource" (dict "Name" (include "terraform.sources.name" (dict "Name" "default" "Type" $type)) "Source" (get $sources "default" ) "Context" $ctx) | nindent 2 }} + {{- end }} + {{- end }} {{- end }} resource "kubernetes_secret" "sumologic_collection_secret" { @@ -29,13 +36,20 @@ resource "kubernetes_secret" "sumologic_collection_secret" { data = { {{- $ctx := .Values }} {{- range $type, $sources := .Values.sumologic.collector.sources }} - {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} - {{- range $key, $source := $sources }} - {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} + {{- if eq (include "terraform.sources.component_enabled" (dict "Context" $ctx "Type" $type)) "true" }} + {{- range $key, $source := $sources }} + {{- if eq (include "terraform.sources.to_create" (dict "Context" $ctx "Type" $type "Name" $key)) "true" }} {{ include "terraform.sources.data" (dict "Endpoint" (include "terraform.sources.config-map-variable" (dict "Type" $type "Context" $ctx "Name" $key)) "Name" (include "terraform.sources.name" (dict "Name" $key "Type" $type))) }} - {{- end }} - {{- end }} - {{- end }} + {{- end }} + {{- end }} + {{- else if and (eq $type "metrics") $ctx.sumologic.traces.enabled }} + {{- /* + If traces are enabled and metrics are disabled, create default metrics source anyway + */}} + {{- if hasKey $sources "default" }} + {{ include "terraform.sources.data" (dict "Endpoint" (include "terraform.sources.config-map-variable" (dict "Type" $type "Context" $ctx "Name" "default")) "Name" (include "terraform.sources.name" (dict "Name" "default" "Type" $type))) }} + {{- end }} + {{- end }} {{- end }} } diff --git a/tests/helm/terraform/static/traces.output.yaml b/tests/helm/terraform/static/traces.output.yaml index aed8adbfc0..c478946762 100644 --- a/tests/helm/terraform/static/traces.output.yaml +++ b/tests/helm/terraform/static/traces.output.yaml @@ -120,6 +120,7 @@ data: } locals.tf: | locals { + default_metrics_source = "(default-metrics)" default_traces_source = "traces" } main.tf: | @@ -153,6 +154,11 @@ data: } } + resource "sumologic_http_source" "default_metrics_source" { + name = local.default_metrics_source + collector_id = sumologic_collector.collector.id + } + resource "sumologic_http_source" "default_traces_source" { name = local.default_traces_source collector_id = sumologic_collector.collector.id @@ -166,6 +172,7 @@ data: } data = { + endpoint-metrics = sumologic_http_source.default_metrics_source.url endpoint-traces = sumologic_http_source.default_traces_source.url }