grafana / alloy

OpenTelemetry Collector distribution with programmable pipelines
https://grafana.com/oss/alloy
Apache License 2.0
1.25k stars 157 forks source link

Proposal: static metric source component #331

Open captncraig opened 10 months ago

captncraig commented 10 months ago

Background

In some cases, it may be desirable to create metrics without any external source. A few possible scenarios include:

Currently, the k8s-monitoring helm chart is creating some static files and using textfile collector to scrape them. I'd like to eliminate some moving pieces there.

Proposal

A new component: prometheus.static_metrics (accepting better names).

prometheus.static_metrics "chart_metadata" {
  forward_to = [prometheus.remote_write.default.receiver]
  interval = "30s"
  // any number of metrics. Maybe only gauges make sense.
  metric {
    name = "helm.chart.version"
    description = "version of helm chart in use"
    value = 1
    labels = {
      version = "1.2.3"
    }
  }
  //  value or labels can be any expression
  metric {
     name = "test.metric"
     description = "this is a test metric"
     labels = { arch = constants.arch }
     value = 42
  }
}

The interface is fairly simple. Given some number of receivers, it synthesizes metrics every interval, and forwards them to the requested backend.

Option 2: Pull metrics

WE could just host our own registry with a metrics endpoint and pull it like any other exporter by exporting a static target.

That would eliminate the forward_to and interval arguments.

rfratto commented 10 months ago

I like the idea.

What would be the pros/cons between this component pushing metrics to another component, and it exposing a metrics endpoint to be collected from another component?

captncraig commented 10 months ago

Honestly, I hadn't considered exposing our own metrics endpoint. It is a good idea, since I'm not entirely sure of the apis required to push metrics.

It is probably simpler to think of this more like an exporter now that I think about it.

How do you feel about naming in that case?

rfratto commented 10 months ago

Good question. prometheus.exporter.custom?