> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/monitoring/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/monitoring/latest/concepts/exporter.md).

# Exporter

[`Exporter` Custom Resource (CR)](https://docs.cennso.com/cennso/monitoring/latest/technical-reference/crds/exporter.md) allows you to configure and deploy a Monitoring Exporter pipeline on the Management Cluster. Each `Exporter` CR produces one Telegraf pod that polls a PromQL source and forwards metrics to a configured sink.

A minimal configuration requires the following fields:

- **spec.source.metrics** — at least one metric definition, each with a **name** and a **query**.
- **spec.sink** — exactly one sink type. Currently only **elastic** is supported.

The following example shows the minimal configuration needed to deploy a working export pipeline:

```yaml
apiVersion: monitoring.cennso.com/v1alpha1
kind: Exporter
metadata:
  name: platform-metrics
  namespace: my-namespace
spec:
  source:
    metricsURL: http://mimir-gateway.cennso-monitoring/prometheus  # optional; defaults to this value
    metrics:
      - name: up                       # required; fallback metric name
        query: 'up'                    # required; raw PromQL expression
  sink:
    elastic:                           # exactly one sink type must be specified
      auth:
        oauth2:
          secretRef:
            name: elastic-oauth-credentials  # Secret must exist in the same namespace
```

## Deployment configuration

The **spec.deployment** section is optional. When omitted, the composition uses its built-in image and resource defaults.

### Image override

The **spec.deployment.image** block overrides the Telegraf container image. Omit to use the chart default.

- **repository** — Container image repository (for example, `registry.cennso.com/cennso-dev/telegraf`)
- **tag** — Image tag (for example, `v1.39.1-cennso.0-rc.1`)

### Resource requests and limits

The **spec.deployment.resources** block sets CPU and memory requests and limits for the Telegraf container. It accepts the standard Kubernetes resource format and is passed through to the Helm Release values.

## Source configuration

The **spec.source** section configures the PromQL endpoint and polling behavior.

### Metrics URL

- **metricsURL** (optional, recommended) — Base URL of a PromQL-compatible HTTP API (for example, `http://mimir-gateway.cennso-monitoring/prometheus`). Defaults to `http://mimir-gateway.cennso-monitoring/prometheus` when omitted. Explicitly setting this field is recommended to ensure the pipeline reads from the intended source. Any PromQL-compatible endpoint works: Prometheus or Grafana Mimir.

### Basic authentication

The **spec.source.basicAuth** block configures HTTP Basic Auth for the PromQL endpoint. Both fields reference keys in pre-existing Secrets in the same namespace.

- **usernameSecretRef.name** / **usernameSecretRef.key** — Secret and key for the username.
- **passwordSecretRef.name** / **passwordSecretRef.key** — Secret and key for the password.

### Polling parameters

- **pollInterval** — How often Telegraf queries the source (default: `30s`). Maps to `agent.interval` in the rendered Telegraf TOML. Set this to match the PromQL source's scrape interval to align collection boundaries with scrape timestamps.
- **initialLookback** — The look-back window for each range query: `start = now - initialLookback` (default: `1m`). Consecutive ticks overlap by this window; widen the step or narrow the window to reduce duplicate delivery.
- **requestTimeout** — HTTP timeout for PromQL requests (default: `25s`).

### Metrics list

**spec.source.metrics** is a required list of at least one metric definition. Each entry has:

- **name** (required) — Fallback metric name used when the PromQL result lacks a `__name__` label.
- **query** (required) — Raw PromQL expression. Written directly by the operator.
- **step** — Range query resolution step (default: `30s`).
- **limit** — Caps the number of series returned per tick. Without a limit, large queries can cause Mimir to silently truncate results or spike Telegraf memory. Set to the expected series count plus around 20% headroom.

## Sink configuration

The **spec.sink** section selects the output destination using a discriminated union. Exactly one sink type must be specified. Specifying zero or more than one type is rejected by the XRD schema.

### elastic

The **elastic** sink renders an `outputs.http` Telegraf section with the `elasticcommonschema` serializer that POSTs an **NDJSON stream of ECS-compliant JSON documents** (one document per line, no Elasticsearch `_bulk` action lines) to an ingest gateway. Kubernetes resource labels are renamed to the correct ECS fieldsets: cluster and workload identity to [`orchestrator.*`](https://www.elastic.co/docs/reference/ecs/ecs-orchestrator) (`orchestrator.cluster.name`, `orchestrator.namespace`, `orchestrator.resource.name`), container to [`container.name`](https://www.elastic.co/docs/reference/ecs/ecs-container), node to [`host.name`](https://www.elastic.co/docs/reference/ecs/ecs-host), and `service` to `service.name`. The serializer expands these dotted tag keys into nested objects at the document root, so each document contains `@timestamp`, `ecs.version`, `event.dataset` (the measurement name), the metric value nested under the measurement name, and the ECS fieldsets as nested objects at the root. Index routing is the gateway's responsibility.

#### Transport options

- **timeout** — HTTP request timeout for the gateway endpoint (default: `30s`).
- **batchSize** — Maximum number of metrics per request (default: `5000`).
- **flushInterval** — How often Telegraf flushes the output buffer (default: `30s`).
- **enableGzip** — Enable gzip compression on requests (default: `true`).

#### TLS options

The **spec.sink.elastic.tls** block is optional.

- **insecureSkipVerify** — Skip TLS certificate verification (default: `false`). Use only for development or testing.
- **caCertSecretRef.name** / **caCertSecretRef.key** — Secret and key holding the PEM-encoded CA certificate to trust for the Elasticsearch endpoint.

#### Authentication

The **spec.sink.elastic.auth** block is optional but required to deliver authenticated requests. It uses the same discriminated-union pattern as `spec.sink`: exactly one auth type must be specified.

**oauth2** configures the Telegraf `secretstores.oauth2` plugin for OAuth 2.0 client-credentials token management. The resulting bearer token is passed to `outputs.http` as an `Authorization: Bearer` header.

- **secretRef.name** (required) — Name of a core/v1 Secret in the same namespace. The Secret must contain four keys: `client_id`, `client_secret`, `token_endpoint`, and `api_endpoint`. The composition projects these as environment variables on the Telegraf container. `api_endpoint` is the exact URL the NDJSON document stream is POSTed to (the ingest gateway endpoint); it is used verbatim, with no path appended.
- **scopes** — Optional list of OAuth 2.0 scopes to request (for example, `["metrics:write"]`).
- **audience** — Optional audience claim for the token request.

See the full configuration example:

```yaml
apiVersion: monitoring.cennso.com/v1alpha1
kind: Exporter
metadata:
  name: platform-metrics
  namespace: my-namespace
spec:
  deployment:
    resources:
      requests:
        memory: "256Mi"
        cpu: "200m"
      limits:
        memory: "512Mi"
        cpu: "1000m"
  source:
    metricsURL: http://mimir-gateway.cennso-monitoring/prometheus
    pollInterval: "30s"
    initialLookback: "1m"
    requestTimeout: "25s"
    metrics:
      - name: up
        query: 'up{job=~"cennso-.*"}'
        step: "30s"
        limit: 500
      - name: smc_session_active_total
        query: 'smc_session_active_total{namespace="cennso-system"}'
        step: "60s"
        limit: 200
  sink:
    elastic:
      timeout: "30s"
      batchSize: 5000
      flushInterval: "30s"
      enableGzip: true
      tls:
        insecureSkipVerify: false
      auth:
        oauth2:
          secretRef:
            name: elastic-oauth-credentials
          scopes: ["metrics:write"]
          audience: elastic
```

## Status

The **status** section reflects the observed state of the export pipeline.

- **phase** — Current deployment phase, mirrored from the underlying Helm Release: `Pending`, `Ready`, or `Failed`.
- **renderedConfigMap** — Name of the ConfigMap holding the rendered `telegraf.conf`.
- **conditions** — Standard Crossplane conditions (`Ready`, `Synced`) with details about the last reconciliation.
