apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "aws-cloudwatch-metrics.fullname" . }}
  labels:
    {{- include "aws-cloudwatch-metrics.labels" . | nindent 4 }}
data:
  cwagentconfig.json: |
    {
      "logs": {
        "metrics_collected": {
          "kubernetes": {
            "cluster_name": "{{ .Values.clusterName }}",
            "enhanced_container_insights": {{ .Values.enhancedContainerInsights.enabled }},
            "metrics_collection_interval": 60
          }
        },
        "force_flush_interval": 5
{{- if .Values.statsd.enabled }}
      },
      "metrics": {
        {{- if .Values.statsd.cloudwatch_namespace }}
        "namespace": "{{- .Values.statsd.cloudwatch_namespace -}}",
        {{- end }}
        "metrics_collected": {
          "statsd": {
              {{- if .Values.statsd.metrics_aggregation_interval }}
              "metrics_aggregation_interval": {{ .Values.statsd.metrics_aggregation_interval }},
              {{- end }}
              {{- if .Values.statsd.metrics_collection_interval }}
              "metrics_collection_interval": {{ .Values.statsd.metrics_collection_interval }},
              {{- end }}
              "service_address": ":{{- .Values.statsd.port -}}"
          }
        }
      }
{{- else }}
      }
{{- end }}
    }
