Skip to content

Commit e474527

Browse files
committed
Support setting default scrape limit for operator components
1 parent 08796f8 commit e474527

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ headless: true
66

77
| Name | Type | Description | Default | Required |
88
|----------------------------|------------|------------------------------------------------------------------------------------------------------------------------------|---------|----------|
9+
| `default_sample_limit` | `int` | The default maximum samples per scrape. Used as the default if the target resource doesn't provide a sample limit. | | no |
910
| `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 |
1011
| `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 |
1112
| `scrape_native_histograms` | `bool` | Whether to scrape native histograms from targets. | `false` | no |

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.DefaultSampleLimit != 0 {
194+
c.SampleLimit = opt.DefaultSampleLimit
195+
}
196+
193197
if opt.ScrapeNativeHistograms {
194198
c.ScrapeProtocols = config.DefaultProtoFirstScrapeProtocols
195199
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
9292
},
9393
},
9494
ScrapeNativeHistograms: falsePtr,
95+
SampleLimit: 18,
9596
AlwaysScrapeClassicHistograms: falsePtr,
9697
ConvertClassicHistogramsToNHCB: falsePtr,
9798
MetricNameValidationScheme: model.LegacyValidation,
@@ -155,6 +156,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
155156
},
156157
},
157158
},
159+
SampleLimit: 18,
158160
ScrapeNativeHistograms: falsePtr,
159161
AlwaysScrapeClassicHistograms: falsePtr,
160162
ConvertClassicHistogramsToNHCB: falsePtr,
@@ -219,6 +221,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
219221
},
220222
},
221223
},
224+
SampleLimit: 18,
222225
ScrapeNativeHistograms: falsePtr,
223226
AlwaysScrapeClassicHistograms: falsePtr,
224227
ConvertClassicHistogramsToNHCB: falsePtr,
@@ -281,6 +284,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
281284
},
282285
},
283286
},
287+
SampleLimit: 18,
284288
ScrapeNativeHistograms: falsePtr,
285289
AlwaysScrapeClassicHistograms: falsePtr,
286290
ConvertClassicHistogramsToNHCB: falsePtr,
@@ -345,6 +349,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
345349
},
346350
},
347351
},
352+
SampleLimit: 18,
348353
ScrapeNativeHistograms: falsePtr,
349354
AlwaysScrapeClassicHistograms: falsePtr,
350355
ConvertClassicHistogramsToNHCB: falsePtr,
@@ -538,6 +543,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
538543
DefaultScrapeInterval: time.Hour,
539544
DefaultScrapeTimeout: 42 * time.Second,
540545
ScrapeNativeHistograms: false,
546+
DefaultSampleLimit: 18,
541547
},
542548
}
543549
cfg, err := cg.GeneratePodMonitorConfig(tc.m, tc.ep, 1)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ func TestGenerateDefaultScrapeConfig(t *testing.T) {
450450
scrapeOptions: operator.ScrapeOptions{
451451
DefaultScrapeInterval: 30 * time.Second,
452452
DefaultScrapeTimeout: 5 * time.Second,
453+
DefaultSampleLimit: 100,
453454
},
454455
expectedInterval: 30 * time.Second,
455456
expectedTimeout: 5 * time.Second,
@@ -466,6 +467,7 @@ func TestGenerateDefaultScrapeConfig(t *testing.T) {
466467
assert.Equal(t, model.Duration(tt.expectedInterval), got.ScrapeInterval)
467468
assert.Equal(t, model.Duration(tt.expectedTimeout), got.ScrapeTimeout)
468469
assert.Equal(t, tt.expectedFallbackProtocol, got.ScrapeFallbackProtocol)
470+
assert.Equal(t, tt.scrapeOptions.DefaultSampleLimit, got.SampleLimit)
469471
})
470472
}
471473
}

internal/component/prometheus/operator/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type ScrapeOptions struct {
5050
// DefaultScrapeTimeout is the default timeout to scrape targets.
5151
DefaultScrapeTimeout time.Duration `alloy:"default_scrape_timeout,attr,optional"`
5252

53+
// DefaultSampleLimit is the default sample limit per scrape.
54+
DefaultSampleLimit uint `alloy:"default_sample_limit,attr,optional"`
55+
5356
// ScrapeNativeHistograms enables scraping of Prometheus native histograms.
5457
ScrapeNativeHistograms bool `alloy:"scrape_native_histograms,attr,optional"`
5558
}
@@ -58,6 +61,7 @@ func (s *ScrapeOptions) GlobalConfig() promconfig.GlobalConfig {
5861
cfg := promconfig.DefaultGlobalConfig
5962
cfg.ScrapeInterval = model.Duration(s.DefaultScrapeInterval)
6063
cfg.ScrapeTimeout = model.Duration(s.DefaultScrapeTimeout)
64+
cfg.SampleLimit = s.DefaultSampleLimit
6165
// TODO: add support for choosing validation scheme: https://github.com/grafana/alloy/issues/4122
6266
cfg.MetricNameValidationScheme = model.LegacyValidation
6367
cfg.MetricNameEscapingScheme = model.EscapeUnderscores

0 commit comments

Comments
 (0)