Skip to content

Commit 86b3c7d

Browse files
authored
Support scraping native histograms from the prometheus CRDs (#4750)
* Support scraping native histograms from the prometheus CRDs * Rename based on PR feedback
1 parent 1ab7f12 commit 86b3c7d

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Main (unreleased)
4242
- replace the internal `server_id` label attribution in favor of a hash composed from `@@server_uuid` and `@@hostname`
4343
- add `setup_actors` collector that checks and optionally updates settings to avoid tracking queries for the currently connected user (@cristiangreco)
4444

45+
- Fix the `prometheus.operator.*` components internal scrape manager now having a way to enable ingesting native histograms. (@dehaansa)
46+
4547
v1.12.0
4648
-----------------
4749

docs/sources/shared/reference/components/prom-operator-scrape.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ description: Shared content, prom operator scrape
44
headless: true
55
---
66

7-
| Name | Type | Description | Default | Required |
8-
| ------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
9-
| `default_scrape_interval` | `duration` | The default interval between scraping targets. Used as the default if the target resource doesn't provide a scrape interval. | `1m` | no |
10-
| `default_scrape_timeout` | `duration` | The default timeout for scrape requests. Used as the default if the target resource doesn't provide a scrape timeout. | `10s` | no |
7+
| Name | Type | Description | Default | Required |
8+
|----------------------------|------------|------------------------------------------------------------------------------------------------------------------------------|---------|----------|
9+
| `default_scrape_interval` | `duration` | The default interval between scraping targets. Used as the default if the target resource doesn't provide a scrape interval. | `1m` | no |
10+
| `default_scrape_timeout` | `duration` | The default timeout for scrape requests. Used as the default if the target resource doesn't provide a scrape timeout. | `10s` | no |
11+
| `scrape_native_histograms` | `bool` | Allow the scrape manager to ingest native histograms. | `false` | no |

internal/component/prometheus/operator/common/crdmanager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ func (c *crdManager) Run(ctx context.Context) error {
146146

147147
// Start prometheus scrape manager.
148148
alloyAppendable := prometheus.NewFanout(c.args.ForwardTo, c.opts.ID, c.opts.Registerer, c.ls)
149-
opts := &scrape.Options{}
149+
150+
opts := &scrape.Options{
151+
EnableNativeHistogramsIngestion: c.args.Scrape.ScrapeNativeHistograms,
152+
}
150153
c.scrapeManager, err = scrape.NewManager(opts, slog.New(logging.NewSlogGoKitHandler(c.logger)), nil, alloyAppendable, unregisterer)
151154
if err != nil {
152155
return fmt.Errorf("creating scrape manager: %w", err)

internal/component/prometheus/operator/configgen/config_gen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ func (cg *ConfigGenerator) generateDefaultScrapeConfig() *config.ScrapeConfig {
190190
c.ScrapeTimeout = model.Duration(opt.DefaultScrapeTimeout)
191191
}
192192

193+
if opt.ScrapeNativeHistograms {
194+
c.ScrapeProtocols = config.DefaultProtoFirstScrapeProtocols
195+
}
196+
193197
return &c
194198
}
195199

internal/component/prometheus/operator/configgen/config_gen_podmonitor_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
529529
{TargetLabel: "__meta_foo", Replacement: "bar"},
530530
},
531531
ScrapeOptions: operator.ScrapeOptions{
532-
DefaultScrapeInterval: time.Hour,
533-
DefaultScrapeTimeout: 42 * time.Second,
532+
DefaultScrapeInterval: time.Hour,
533+
DefaultScrapeTimeout: 42 * time.Second,
534+
ScrapeNativeHistograms: false,
534535
},
535536
}
536537
cfg, err := cg.GeneratePodMonitorConfig(tc.m, tc.ep, 1)

internal/component/prometheus/operator/configgen/config_gen_scrapeconfig_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ func TestGenerateStaticScrapeConfigConfig(t *testing.T) {
217217
{TargetLabel: "__meta_foo", Replacement: "bar"},
218218
},
219219
ScrapeOptions: operator.ScrapeOptions{
220-
DefaultScrapeInterval: time.Hour,
221-
DefaultScrapeTimeout: 42 * time.Second,
220+
DefaultScrapeInterval: time.Hour,
221+
DefaultScrapeTimeout: 42 * time.Second,
222+
ScrapeNativeHistograms: false,
222223
},
223224
}
224225
cfg, err := cg.generateStaticScrapeConfigConfig(tc.m, tc.ep, 1)

internal/component/prometheus/operator/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type ScrapeOptions struct {
4949

5050
// DefaultScrapeTimeout is the default timeout to scrape targets.
5151
DefaultScrapeTimeout time.Duration `alloy:"default_scrape_timeout,attr,optional"`
52+
53+
// ScrapeNativeHistograms enables scraping of Prometheus native histograms.
54+
ScrapeNativeHistograms bool `alloy:"scrape_native_histograms,attr,optional"`
5255
}
5356

5457
func (s *ScrapeOptions) GlobalConfig() promconfig.GlobalConfig {

0 commit comments

Comments
 (0)