Skip to content

Commit

Permalink
fix(helm): always create default metrics source if traces are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Mar 15, 2022
1 parent 6c94c5e commit da38548
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
19 changes: 13 additions & 6 deletions deploy/helm/sumologic/conf/setup/locals.tf
Original file line number Diff line number Diff line change
@@ -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 }}
}
38 changes: 26 additions & 12 deletions deploy/helm/sumologic/conf/setup/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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 }}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/helm/terraform/static/traces.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ data:
}
locals.tf: |
locals {
default_metrics_source = "(default-metrics)"
default_traces_source = "traces"
}
main.tf: |
Expand Down Expand Up @@ -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
Expand All @@ -166,6 +172,7 @@ data:
}
data = {
endpoint-metrics = sumologic_http_source.default_metrics_source.url
endpoint-traces = sumologic_http_source.default_traces_source.url
}
Expand Down

0 comments on commit da38548

Please sign in to comment.