
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "influxdb.fullname" . }}
  labels:
    app: {{ template "influxdb.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
data:
  influxdb.conf: |+
    reporting-disabled = {{ .Values.config.reporting_disabled | default false }}
    bind-address = ":{{ .Values.config.rpc.bind_address }}"

    [meta]
      dir = "{{ .Values.config.storage_directory }}/meta"
      retention-autocreate = {{ .Values.config.meta.retention_autocreate }}
      logging-enabled = {{ .Values.config.meta.logging_enabled }}

    [data]
      dir = "{{ .Values.config.storage_directory }}/data"
      wal-dir = "{{ .Values.config.storage_directory }}/wal"
      query-log-enabled = {{ .Values.config.data.query_log_enabled }}
      cache-max-memory-size = {{ .Values.config.data.cache_max_memory_size | int64 }}
      cache-snapshot-memory-size = {{ .Values.config.data.cache_snapshot_memory_size | int64 }}
      cache-snapshot-write-cold-duration = "{{ .Values.config.data.cache_snapshot_write_cold_duration }}"
      compact-full-write-cold-duration = "{{ .Values.config.data.compact_full_write_cold_duration }}"
      max-series-per-database = {{ .Values.config.data.max_series_per_database | int64 }}
      max-values-per-tag = {{ .Values.config.data.max_values_per_tag | int64 }}
      trace-logging-enabled = {{ .Values.config.data.trace_logging_enabled }}

    [coordinator]
      write-timeout = "{{ .Values.config.coordinator.write_timeout }}"
      max-concurrent-queries = {{ .Values.config.coordinator.max_concurrent_queries | int64 }}
      query-timeout = "{{ .Values.config.coordinator.query_timeout }}"
      log-queries-after = "{{ .Values.config.coordinator.log_queries_after }}"
      max-select-point = {{ .Values.config.coordinator.max_select_point | int64 }}
      max-select-series = {{ .Values.config.coordinator.max_select_series | int64 }}
      max-select-buckets = {{ .Values.config.coordinator.max_select_buckets | int64 }}

    [retention]
      enabled = {{ .Values.config.retention.enabled }}
      check-interval = "{{ .Values.config.retention.check_interval }}"

    [shard-precreation]
      enabled = {{ .Values.config.shard_precreation.enabled }}
      check-interval = "{{ .Values.config.shard_precreation.check_interval }}"
      advance-period = "{{ .Values.config.shard_precreation.advance_period }}"

    [admin]
      enabled = {{ .Values.config.admin.enabled }}
      bind-address = ":{{ .Values.config.admin.bind_address }}"
      https-enabled = {{ .Values.config.admin.https_enabled }}
      https-certificate = "{{ .Values.config.admin.https_certificate }}"

    [monitor]
      store-enabled = {{ .Values.config.monitor.store_enabled }}
      store-database = "{{ .Values.config.monitor.store_database }}"
      store-interval = "{{ .Values.config.monitor.store_interval }}"

    [subscriber]
      enabled = {{ .Values.config.subscriber.enabled }}
      http-timeout = "{{ .Values.config.subscriber.http_timeout }}"
      insecure-skip-verify = {{ .Values.config.subscriber.insecure_skip_verify }}
      ca-certs = "{{ .Values.config.subscriber.ca_certs }}"
      write-concurrency = {{ .Values.config.subscriber.write_concurrency | int64 }}
      write-buffer-size = {{ .Values.config.subscriber.write_buffer_size | int64 }}

    [http]
      enabled = {{ .Values.config.http.enabled }}
      bind-address = ":{{ .Values.config.http.bind_address }}"
      auth-enabled = {{ .Values.config.http.auth_enabled }}
      log-enabled = {{ .Values.config.http.log_enabled }}
      write-tracing = {{ .Values.config.http.write_tracing }}
      pprof-enabled = {{ .Values.config.http.pprof_enabled }}
      https-enabled = {{ .Values.config.http.https_enabled }}
      https-certificate = "{{ .Values.config.http.https_certificate }}"
      https-private-key = "{{ .Values.config.http.https_private_key }}"
      max-row-limit = {{ .Values.config.http.max_row_limit | int64 }}
      max-connection-limit = {{ .Values.config.http.max_connection_limit | int64 }}
      shared-secret = "{{ .Values.config.http.shared_secret }}"
      realm = "{{ .Values.config.http.realm }}"
      unix-socket-enabled = {{ .Values.config.http.unix_socket_enabled }}
      bind-socket = "{{ .Values.config.http.bind_socket }}"
    
    # TODO: allow multiple graphite listeners
    
    [[graphite]]
      enabled = {{ .Values.config.graphite.enabled }}
      bind-address = ":{{ .Values.config.graphite.bind_address }}"
      database = "{{ .Values.config.graphite.database }}"
      retention-policy = "{{ .Values.config.graphite.retention_policy }}"
      protocol = "{{ .Values.config.graphite.protocol }}"
      batch-size = {{ .Values.config.graphite.batch_size | int64 }}
      batch-pending = {{ .Values.config.graphite.batch_pending | int64 }}
      batch-timeout = "{{ .Values.config.graphite.batch_timeout }}"
      consistency-level = "{{ .Values.config.graphite.consistency_level }}"
      separator = "{{ .Values.config.graphite.separator }}"
      udp-read-buffer = {{ .Values.config.graphite.udp_read_buffer | int64 }}
      {{- if .Values.config.graphite.templates }}
      templates = [
        {{- range .Values.config.graphite.templates }}
          {{ quote . }},
        {{- end }}
      ]
      {{- end }}
    
    # TODO: allow multiple collectd listeners with templates

    [[collectd]]
      enabled = {{ .Values.config.collectd.enabled }}
      bind-address = ":{{ .Values.config.collectd.bind_address }}"
      database = "{{ .Values.config.collectd.database }}"
      retention-policy = "{{ .Values.config.collectd.retention_policy }}"
      batch-size = {{ .Values.config.collectd.batch_size | int64 }}
      batch-pending = {{ .Values.config.collectd.batch_pending | int64 }}
      batch-timeout = "{{ .Values.config.collectd.batch_timeout }}"
      read-buffer = {{ .Values.config.collectd.read_buffer | int64 }}
      typesdb = "{{ .Values.config.collectd.typesdb }}"
      security-level = "{{ .Values.config.collectd.security_level }}"
      auth-file = "{{ .Values.config.collectd.auth_file }}"
    
    # TODO: allow multiple opentsdb listeners with templates

    [[opentsdb]]
      enabled = {{ .Values.config.opentsdb.enabled }}
      bind-address = ":{{ .Values.config.opentsdb.bind_address }}"
      database = "{{ .Values.config.opentsdb.database }}"
      retention-policy = "{{ .Values.config.opentsdb.retention_policy }}"
      consistency-level = "{{ .Values.config.opentsdb.consistency_level }}"
      tls-enabled = {{ .Values.config.opentsdb.tls_enabled }}
      certificate = "{{ .Values.config.opentsdb.certificate }}"
      batch-size = {{ .Values.config.opentsdb.batch_size | int64 }}
      batch-pending = {{ .Values.config.opentsdb.batch_pending | int64 }}
      batch-timeout = "{{ .Values.config.opentsdb.batch_timeout }}"
      log-point-errors = {{ .Values.config.opentsdb.log_point_errors }}
    
    # TODO: allow multiple udp listeners with templates

    [[udp]]
      enabled = {{ .Values.config.udp.enabled }}
      bind-address = ":{{ .Values.config.udp.bind_address }}"
      database = "{{ .Values.config.udp.database }}"
      retention-policy = "{{ .Values.config.udp.retention_policy }}"
      batch-size = {{ .Values.config.udp.batch_size | int64 }}
      batch-pending = {{ .Values.config.udp.batch_pending | int64 }}
      read-buffer = {{ .Values.config.udp.read_buffer | int64 }}
      batch-timeout = "{{ .Values.config.udp.batch_timeout }}"
      precision = "{{ .Values.config.udp.precision }}"

    [continuous_queries]
      log-enabled = {{ .Values.config.continuous_queries.log_enabled }}
      enabled = {{ .Values.config.continuous_queries.enabled }}
      run-interval = "{{ .Values.config.continuous_queries.run_interval }}"

    [logging]
      format =  "{{ .Values.config.logging.format }}"
      level =  "{{ .Values.config.logging.level }}"
      supress-logo = {{ .Values.config.logging.supress_logo }}
