Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ headless: true

| Name | Type | Description | Default | Required |
|----------------------------|------------|------------------------------------------------------------------------------------------------------------------------------|---------|----------|
| `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 |
| `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 |
| `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 |
| `scrape_native_histograms` | `bool` | Whether to scrape native histograms from targets. | `false` | no |
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func (cg *ConfigGenerator) generateDefaultScrapeConfig() *config.ScrapeConfig {
c.ScrapeTimeout = model.Duration(opt.DefaultScrapeTimeout)
}

if opt.DefaultSampleLimit != 0 {
c.SampleLimit = opt.DefaultSampleLimit
}

if opt.ScrapeNativeHistograms {
c.ScrapeProtocols = config.DefaultProtoFirstScrapeProtocols
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
},
},
ScrapeNativeHistograms: falsePtr,
SampleLimit: 18,
AlwaysScrapeClassicHistograms: falsePtr,
ConvertClassicHistogramsToNHCB: falsePtr,
MetricNameValidationScheme: model.LegacyValidation,
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
},
},
},
SampleLimit: 18,
ScrapeNativeHistograms: falsePtr,
AlwaysScrapeClassicHistograms: falsePtr,
ConvertClassicHistogramsToNHCB: falsePtr,
Expand Down Expand Up @@ -219,6 +221,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
},
},
},
SampleLimit: 18,
ScrapeNativeHistograms: falsePtr,
AlwaysScrapeClassicHistograms: falsePtr,
ConvertClassicHistogramsToNHCB: falsePtr,
Expand Down Expand Up @@ -281,6 +284,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
},
},
},
SampleLimit: 18,
ScrapeNativeHistograms: falsePtr,
AlwaysScrapeClassicHistograms: falsePtr,
ConvertClassicHistogramsToNHCB: falsePtr,
Expand Down Expand Up @@ -345,6 +349,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
},
},
},
SampleLimit: 18,
ScrapeNativeHistograms: falsePtr,
AlwaysScrapeClassicHistograms: falsePtr,
ConvertClassicHistogramsToNHCB: falsePtr,
Expand Down Expand Up @@ -538,6 +543,7 @@ func TestGeneratePodMonitorConfig(t *testing.T) {
DefaultScrapeInterval: time.Hour,
DefaultScrapeTimeout: 42 * time.Second,
ScrapeNativeHistograms: false,
DefaultSampleLimit: 18,
},
}
cfg, err := cg.GeneratePodMonitorConfig(tc.m, tc.ep, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ func TestGenerateDefaultScrapeConfig(t *testing.T) {
scrapeOptions: operator.ScrapeOptions{
DefaultScrapeInterval: 30 * time.Second,
DefaultScrapeTimeout: 5 * time.Second,
DefaultSampleLimit: 100,
},
expectedInterval: 30 * time.Second,
expectedTimeout: 5 * time.Second,
Expand All @@ -466,6 +467,7 @@ func TestGenerateDefaultScrapeConfig(t *testing.T) {
assert.Equal(t, model.Duration(tt.expectedInterval), got.ScrapeInterval)
assert.Equal(t, model.Duration(tt.expectedTimeout), got.ScrapeTimeout)
assert.Equal(t, tt.expectedFallbackProtocol, got.ScrapeFallbackProtocol)
assert.Equal(t, tt.scrapeOptions.DefaultSampleLimit, got.SampleLimit)
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/component/prometheus/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type ScrapeOptions struct {
// DefaultScrapeTimeout is the default timeout to scrape targets.
DefaultScrapeTimeout time.Duration `alloy:"default_scrape_timeout,attr,optional"`

// DefaultSampleLimit is the default sample limit per scrape.
DefaultSampleLimit uint `alloy:"default_sample_limit,attr,optional"`

// ScrapeNativeHistograms enables scraping of Prometheus native histograms.
ScrapeNativeHistograms bool `alloy:"scrape_native_histograms,attr,optional"`
}
Expand All @@ -58,6 +61,7 @@ func (s *ScrapeOptions) GlobalConfig() promconfig.GlobalConfig {
cfg := promconfig.DefaultGlobalConfig
cfg.ScrapeInterval = model.Duration(s.DefaultScrapeInterval)
cfg.ScrapeTimeout = model.Duration(s.DefaultScrapeTimeout)
cfg.SampleLimit = s.DefaultSampleLimit
// TODO: add support for choosing validation scheme: https://github.com/grafana/alloy/issues/4122
cfg.MetricNameValidationScheme = model.LegacyValidation
cfg.MetricNameEscapingScheme = model.EscapeUnderscores
Expand Down
Loading