> 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/guides/export-to-elastic.md).

# Export metrics to Elastic

This use case describes how to export PromQL metrics to Elasticsearch as ECS-compliant JSON documents, ready to be explored in Kibana alongside other ECS data sources.

## Scenario

A platform operator wants to forward selected Mimir metrics to a centralized Elastic deployment. The Monitoring Exporter handles the full data path: PromQL range queries from Mimir, label normalization to [ECS](https://www.elastic.co/docs/reference/ecs) field names, OAuth 2.0 token refresh, and delivery of an NDJSON stream of ECS documents to an ingest gateway.

## Prerequisites

A core/v1 Secret must exist in the same namespace as the `Exporter` CR, containing four keys:

| Key | Value |
|---|---|
| `client_id` | OAuth 2.0 client identifier |
| `client_secret` | OAuth 2.0 client secret |
| `token_endpoint` | Full URL of the OAuth 2.0 token endpoint |
| `api_endpoint` | Full URL of the Elasticsearch HTTP endpoint (for example, `https://elastic.example.com`) |

To create the Secret:

```bash
kubectl create secret generic {SECRET_NAME} \
  --namespace {NAMESPACE} \
  --from-literal=client_id={CLIENT_ID} \
  --from-literal=client_secret={CLIENT_SECRET} \
  --from-literal=token_endpoint={TOKEN_ENDPOINT} \
  --from-literal=api_endpoint={ELASTICSEARCH_URL}
```

## Configuration

Apply an `Exporter` CR in the same namespace:

```yaml
apiVersion: monitoring.cennso.com/v1alpha1
kind: Exporter
metadata:
  name: platform-metrics
  namespace: my-namespace
spec:
  source:
    metricsURL: http://mimir-gateway.cennso-monitoring/prometheus
    pollInterval: "30s"
    metrics:
      - name: up
        query: 'up{job=~"cennso-.*"}'
        limit: 500
      - name: smc_session_active_total
        query: 'smc_session_active_total{namespace="cennso-system"}'
        limit: 200
  sink:
    elastic:
      enableGzip: true
      auth:
        oauth2:
          secretRef:
            name: elastic-oauth-credentials
          scopes: ["metrics:write"]
```

## ECS document shape

Each document sent to the gateway is ECS-compliant, with ECS fieldsets as nested objects at the document root. The documents are streamed as NDJSON (one document per line, no Elasticsearch `_bulk` action lines). For the `smc_session_active_total` metric with typical Kubernetes tags, a single document looks like:

```json
{
  "@timestamp": "2026-06-17T12:00:00Z",
  "ecs": { "version": "9.3.0" },
  "event": { "dataset": "smc_session_active_total" },
  "orchestrator": {
    "cluster": { "name": "my-cluster" },
    "namespace": "cennso-system",
    "resource": { "name": "my-pod" }
  },
  "container": { "name": "my-container" },
  "service": { "name": "my-service" },
  "smc_session_active_total": { "gauge": 42.0 }
}
```

The composition sends this through Telegraf's `outputs.http` plugin using the `elasticcommonschema` serializer, which expands the dotted tag keys produced by `processors.rename` (`orchestrator.cluster.name`, `container.name`, …) into nested objects at the root — no `tag` wrapper and no Elasticsearch-side ingest pipeline required. Tags without an ECS mapping (for example Prometheus `job`, `instance`) remain as top-level keys.

## Field notes

- **`spec.sink.elastic.auth.oauth2.secretRef.name`** — References the Secret created above. The Secret must be in the same namespace as the `Exporter`.
- **`spec.sink.elastic.enableGzip`** — Enable gzip compression on requests (default: `true`). Set to `false` only for debugging or when the network path already compresses traffic.
- **`spec.source.pollInterval`** — Controls how often Telegraf queries Mimir. Set it to match the Mimir scrape interval (usually `30s` or `60s`) to avoid sampling artifacts.
- **`spec.source.metrics[].limit`** — Caps series returned per query tick. Without a limit, large queries may cause silent truncation in Mimir or spike Telegraf memory. Set to the expected series count plus roughly 20% headroom.
