apiVersion: v1
kind: ConfigMap
metadata:
  name: log-forwarder
data:
  fluentd.conf: |
    # Ignore fluentd own events
    <label @FLUENT_LOG>
      <match **>
        @type null
      </match>
    </label>

    # Ignore fluentd health checks
    <match fluentd.healthcheck>
      @type null
    </match>

    # HTTP input for forwarding and probes
    <source>
      @type http
      body_size_limit 2m
    </source>

    # Prometheus input plugin that exports metrics
    <source>
      @type prometheus
    </source>

    # Ensure record contains a tenant key
    <filter inventory>
      @type record_transformer
      enable_ruby
      <record>
        tenant ${tenant = record.fetch('tenant', ''); tenant ? tenant : ''}
      </record>
    </filter>

    # Prometheus filter plugin exporting inventory metrics
    <filter inventory>
      @id filter_inventory
      @type prometheus
      <metric>
        name inventory_client_events_total
        type counter
        desc The total number of incoming client events
        <labels>
          event ${event}
          tenant ${tenant}
        </labels>
      </metric>
    </filter>

    # Send the logs to the standard output
    <match **>
      @type stdout
    </match>
