---
# Source: splunk-otel-collector/templates/configmap-otel-agent.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: default-splunk-otel-collector-otel-agent
  labels:
    app.kubernetes.io/name: splunk-otel-collector
    helm.sh/chart: splunk-otel-collector-0.37.1
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/instance: default
    app.kubernetes.io/version: "0.38.1"
    app: splunk-otel-collector
    chart: splunk-otel-collector-0.37.1
    release: default
    heritage: Helm
data:
  relay: |
    exporters:
      sapm:
        access_token: ${SPLUNK_OBSERVABILITY_ACCESS_TOKEN}
        endpoint: https://ingest.CHANGEME.signalfx.com/v2/trace
      signalfx:
        access_token: ${SPLUNK_OBSERVABILITY_ACCESS_TOKEN}
        api_url: https://api.CHANGEME.signalfx.com
        correlation: null
        ingest_url: https://ingest.CHANGEME.signalfx.com
        sync_host_metadata: true
      splunk_hec/o11y:
        endpoint: https://ingest.CHANGEME.signalfx.com/v1/log
        token: ${SPLUNK_OBSERVABILITY_ACCESS_TOKEN}
    extensions:
      file_storage:
        directory: /var/addon/splunk/otel_pos
      health_check: null
      k8s_observer:
        auth_type: serviceAccount
        node: ${K8S_NODE_NAME}
      memory_ballast:
        size_mib: ${SPLUNK_BALLAST_SIZE_MIB}
      zpages: null
    processors:
      batch: null
      filter/logs:
        logs:
          exclude:
            resource_attributes:
            - key: splunk.com/exclude
              value: "true"
      k8sattributes:
        extract:
          annotations:
          - from: pod
            key: splunk.com/sourcetype
          - from: namespace
            key: splunk.com/exclude
            tag_name: splunk.com/exclude
          - from: pod
            key: splunk.com/exclude
            tag_name: splunk.com/exclude
          - from: namespace
            key: splunk.com/index
            tag_name: com.splunk.index
          - from: pod
            key: splunk.com/index
            tag_name: com.splunk.index
          labels:
          - key: app
          metadata:
          - k8s.namespace.name
          - k8s.node.name
          - k8s.pod.name
          - k8s.pod.uid
          - container.id
          - container.image.name
          - container.image.tag
        filter:
          node_from_env_var: K8S_NODE_NAME
        pod_association:
        - from: resource_attribute
          name: k8s.pod.uid
        - from: resource_attribute
          name: k8s.pod.ip
        - from: resource_attribute
          name: ip
        - from: connection
        - from: resource_attribute
          name: host.name
      memory_limiter:
        check_interval: 2s
        limit_mib: ${SPLUNK_MEMORY_LIMIT_MIB}
      resource:
        attributes:
        - action: insert
          key: k8s.node.name
          value: ${K8S_NODE_NAME}
        - action: insert
          key: k8s.cluster.name
          value: CHANGEME
      resource/add_agent_k8s:
        attributes:
        - action: insert
          key: k8s.pod.name
          value: ${K8S_POD_NAME}
        - action: insert
          key: k8s.pod.uid
          value: ${K8S_POD_UID}
        - action: insert
          key: k8s.namespace.name
          value: ${K8S_NAMESPACE}
      resource/logs:
        attributes:
        - action: upsert
          from_attribute: k8s.pod.annotations.splunk.com/sourcetype
          key: com.splunk.sourcetype
        - action: delete
          key: k8s.pod.annotations.splunk.com/sourcetype
        - action: delete
          key: splunk.com/exclude
      resourcedetection:
        detectors:
        - env
        - system
        override: false
        timeout: 10s
    receivers:
      filelog:
        encoding: utf-8
        exclude:
        - /var/log/pods/default_default-splunk-otel-collector*_*/otel-collector/*.log
        fingerprint_size: 1kb
        force_flush_period: "0"
        include:
        - /var/log/pods/*/*/*.log
        include_file_name: false
        include_file_path: true
        max_concurrent_files: 1024
        max_log_size: 1MiB
        operators:
        - id: get-format
          routes:
          - expr: $$$$body matches "^\\{"
            output: parser-docker
          - expr: $$$$body matches "^[^ Z]+ "
            output: parser-crio
          - expr: $$$$body matches "^[^ Z]+Z"
            output: parser-containerd
          type: router
        - id: parser-crio
          regex: ^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) (?P<log>.*)$
          timestamp:
            layout: "2006-01-02T15:04:05.000000000-07:00"
            layout_type: gotime
            parse_from: time
          type: regex_parser
        - combine_field: log
          id: crio-recombine
          is_last_entry: ($$.logtag) == 'F'
          type: recombine
        - id: crio-handle_empty_log
          if: $$.log == nil
          ops:
          - add:
              field: log
              value: ""
          output: filename
          type: restructure
        - id: parser-containerd
          regex: ^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) (?P<log>.*)$
          timestamp:
            layout: '%Y-%m-%dT%H:%M:%S.%LZ'
            parse_from: time
          type: regex_parser
        - combine_field: log
          id: containerd-recombine
          is_last_entry: ($$.logtag) == 'F'
          type: recombine
        - id: containerd-handle_empty_log
          if: $$.log == nil
          ops:
          - add:
              field: log
              value: ""
          output: filename
          type: restructure
        - id: parser-docker
          timestamp:
            layout: '%Y-%m-%dT%H:%M:%S.%LZ'
            parse_from: time
          type: json_parser
        - id: filename
          resource:
            com.splunk.source: EXPR($$$$attributes["file.path"])
          type: metadata
        - id: extract_metadata_from_filepath
          parse_from: $$$$attributes["file.path"]
          regex: ^\/var\/log\/pods\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[^\/]+)\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$
          type: regex_parser
        - attributes:
            stream: EXPR($$.stream)
          resource:
            com.splunk.sourcetype: EXPR("kube:container:"+$$.container_name)
            k8s.container.name: EXPR($$.container_name)
            k8s.container.restart_count: EXPR($$.restart_count)
            k8s.namespace.name: EXPR($$.namespace)
            k8s.pod.name: EXPR($$.pod_name)
            k8s.pod.uid: EXPR($$.uid)
          type: metadata
        - id: clean-up-log-record
          ops:
          - move:
              from: log
              to: $$
          type: restructure
        poll_interval: 200ms
        start_at: beginning
      fluentforward:
        endpoint: 0.0.0.0:8006
      hostmetrics:
        collection_interval: 10s
        scrapers:
          cpu: null
          disk: null
          filesystem: null
          load: null
          memory: null
          network: null
          paging: null
          processes: null
      jaeger:
        protocols:
          grpc:
            endpoint: 0.0.0.0:14250
          thrift_http:
            endpoint: 0.0.0.0:14268
      kubeletstats:
        auth_type: serviceAccount
        collection_interval: 10s
        endpoint: ${K8S_NODE_IP}:10250
        extra_metadata_labels:
        - container.id
        metric_groups:
        - container
        - pod
        - node
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
          http:
            endpoint: 0.0.0.0:4318
      prometheus/agent:
        config:
          scrape_configs:
          - job_name: otel-agent
            scrape_interval: 10s
            static_configs:
            - targets:
              - ${K8S_POD_IP}:8889
      receiver_creator:
        receivers: null
        watch_observers:
        - k8s_observer
      signalfx:
        endpoint: 0.0.0.0:9943
      smartagent/signalfx-forwarder:
        listenAddress: 0.0.0.0:9080
        type: signalfx-forwarder
      zipkin:
        endpoint: 0.0.0.0:9411
    service:
      extensions:
      - file_storage
      - health_check
      - k8s_observer
      - memory_ballast
      - zpages
      pipelines:
        logs:
          exporters:
          - splunk_hec/o11y
          processors:
          - memory_limiter
          - k8sattributes
          - batch
          - filter/logs
          - resource
          - resource/logs
          - resourcedetection
          receivers:
          - filelog
          - fluentforward
          - otlp
        metrics:
          exporters:
          - signalfx
          processors:
          - memory_limiter
          - batch
          - resource
          - resourcedetection
          receivers:
          - hostmetrics
          - kubeletstats
          - otlp
          - receiver_creator
          - signalfx
        metrics/agent:
          exporters:
          - signalfx
          processors:
          - memory_limiter
          - batch
          - resource
          - resource/add_agent_k8s
          - resourcedetection
          receivers:
          - prometheus/agent
        traces:
          exporters:
          - sapm
          - signalfx
          processors:
          - memory_limiter
          - k8sattributes
          - batch
          - resource
          - resourcedetection
          receivers:
          - otlp
          - jaeger
          - smartagent/signalfx-forwarder
          - zipkin
