Skip to content

Commit

Permalink
prometheus.scrape: add options for enabling native histograms scraping (
Browse files Browse the repository at this point in the history
#5335)

Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
  • Loading branch information
tpaschalis authored Sep 29, 2023
1 parent 3b8fc4a commit e3b5856
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Main (unreleased)
This will load all River files in the directory as a single configuration;
component names must be unique across all loaded files. (@rfratto, @hainenber)

- Flow: the `prometheus.scrape` component can now configure the scraping of
Prometheus native histograms. (@tpaschalis)

### Enhancements

Expand Down
7 changes: 6 additions & 1 deletion component/prometheus/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Arguments struct {
HonorTimestamps bool `river:"honor_timestamps,attr,optional"`
// A set of query parameters with which the target is scraped.
Params url.Values `river:"params,attr,optional"`
// Whether to scrape a classic histogram that is also exposed as a native histogram.
ScrapeClassicHistograms bool `river:"scrape_classic_histogram,attr,optional"`
// How frequently to scrape the targets of this scrape config.
ScrapeInterval time.Duration `river:"scrape_interval,attr,optional"`
// The timeout for scraping targets of this config.
Expand Down Expand Up @@ -83,7 +85,8 @@ type Arguments struct {
HTTPClientConfig component_config.HTTPClientConfig `river:",squash"`

// Scrape Options
ExtraMetrics bool `river:"extra_metrics,attr,optional"`
ExtraMetrics bool `river:"extra_metrics,attr,optional"`
EnableProtobufNegotiation bool `river:"enable_protobuf_negotiation,attr,optional"`

Clustering Clustering `river:"clustering,block,optional"`
}
Expand Down Expand Up @@ -155,6 +158,7 @@ func New(o component.Options, args Arguments) (*Component, error) {
HTTPClientOptions: []config_util.HTTPClientOption{
config_util.WithDialContextFunc(httpData.DialFunc),
},
EnableProtobufNegotiation: args.EnableProtobufNegotiation,
}
scraper := scrape.NewManager(scrapeOptions, o.Logger, flowAppendable)

Expand Down Expand Up @@ -284,6 +288,7 @@ func getPromScrapeConfigs(jobName string, c Arguments) *config.ScrapeConfig {
dec.HonorLabels = c.HonorLabels
dec.HonorTimestamps = c.HonorTimestamps
dec.Params = c.Params
dec.ScrapeClassicHistograms = c.ScrapeClassicHistograms
dec.ScrapeInterval = model.Duration(c.ScrapeInterval)
dec.ScrapeTimeout = model.Duration(c.ScrapeTimeout)
dec.MetricsPath = c.MetricsPath
Expand Down
8 changes: 8 additions & 0 deletions docs/sources/flow/reference/components/prometheus.scrape.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ Name | Type | Description | Default | Required
`forward_to` | `list(MetricsReceiver)` | List of receivers to send scraped metrics to. | | yes
`job_name` | `string` | The job name to override the job label with. | component name | no
`extra_metrics` | `bool` | Whether extra metrics should be generated for scrape targets. | `false` | no
`enable_protobuf_negotiation` | `bool` | Whether to enable protobuf negotiation with the client. | `false` | no
`honor_labels` | `bool` | Indicator whether the scraped metrics should remain unmodified. | `false` | no
`honor_timestamps` | `bool` | Indicator whether the scraped timestamps should be respected. | `true` | no
`params` | `map(list(string))` | A set of query parameters with which the target is scraped. | | no
`scrape_classic_histogram` | `bool` | Whether to scrape a classic histogram that is also exposed as a native histogram. | `false` | no
`scrape_interval` | `duration` | How frequently to scrape the targets of this scrape config. | `"60s"` | no
`scrape_timeout` | `duration` | The timeout for scraping targets of this config. | `"10s"` | no
`metrics_path` | `string` | The HTTP resource path on which to fetch metrics from targets. | `/metrics` | no
Expand Down Expand Up @@ -230,6 +232,12 @@ times out while scraping, or because the samples from the target could not be
processed. When the target is behaving normally, the `up` metric is set to
`1`.

To enable scraping of Prometheus' native histograms over gRPC, the
`enable_protobuf_negotiation` must be set to true. The
`scrape_classic_histogram` argument controls whether the component should also
scrape the 'classic' histogram equivalent of a native histogram, if it is
present.

[in-memory traffic]: {{< relref "../../concepts/component_controller.md#in-memory-traffic" >}}
[run command]: {{< relref "../cli/run.md" >}}

Expand Down

0 comments on commit e3b5856

Please sign in to comment.