mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-07 06:37:17 +02:00
Add global config option for convert_classic_histograms_to_nhcb
Addresses the global part of https://github.com/prometheus/prometheus/issues/13532 Signed-off-by: chardch <otwordsne@gmail.com>
This commit is contained in:
parent
7d73c1d3f8
commit
2f59d38054
@ -167,7 +167,8 @@ var (
|
|||||||
RuleQueryOffset: model.Duration(0 * time.Minute),
|
RuleQueryOffset: model.Duration(0 * time.Minute),
|
||||||
// When native histogram feature flag is enabled, ScrapeProtocols default
|
// When native histogram feature flag is enabled, ScrapeProtocols default
|
||||||
// changes to DefaultNativeHistogramScrapeProtocols.
|
// changes to DefaultNativeHistogramScrapeProtocols.
|
||||||
ScrapeProtocols: DefaultScrapeProtocols,
|
ScrapeProtocols: DefaultScrapeProtocols,
|
||||||
|
ConvertClassicHistogramsToNHCB: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultRuntimeConfig = RuntimeConfig{
|
DefaultRuntimeConfig = RuntimeConfig{
|
||||||
@ -486,6 +487,8 @@ type GlobalConfig struct {
|
|||||||
// blank in config files but must have a value if a ScrepeConfig is created
|
// blank in config files but must have a value if a ScrepeConfig is created
|
||||||
// programmatically.
|
// programmatically.
|
||||||
MetricNameEscapingScheme string `yaml:"metric_name_escaping_scheme,omitempty"`
|
MetricNameEscapingScheme string `yaml:"metric_name_escaping_scheme,omitempty"`
|
||||||
|
// Whether to convert all scraped classic histograms into native histograms with custom buckets.
|
||||||
|
ConvertClassicHistogramsToNHCB bool `yaml:"convert_classic_histograms_to_nhcb,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScrapeProtocol represents supported protocol for scraping metrics.
|
// ScrapeProtocol represents supported protocol for scraping metrics.
|
||||||
@ -641,7 +644,8 @@ func (c *GlobalConfig) isZero() bool {
|
|||||||
c.RuleQueryOffset == 0 &&
|
c.RuleQueryOffset == 0 &&
|
||||||
c.QueryLogFile == "" &&
|
c.QueryLogFile == "" &&
|
||||||
c.ScrapeFailureLogFile == "" &&
|
c.ScrapeFailureLogFile == "" &&
|
||||||
c.ScrapeProtocols == nil
|
c.ScrapeProtocols == nil &&
|
||||||
|
!c.ConvertClassicHistogramsToNHCB
|
||||||
}
|
}
|
||||||
|
|
||||||
// RuntimeConfig configures the values for the process behavior.
|
// RuntimeConfig configures the values for the process behavior.
|
||||||
@ -688,7 +692,7 @@ type ScrapeConfig struct {
|
|||||||
// Whether to scrape a classic histogram, even if it is also exposed as a native histogram.
|
// Whether to scrape a classic histogram, even if it is also exposed as a native histogram.
|
||||||
AlwaysScrapeClassicHistograms bool `yaml:"always_scrape_classic_histograms,omitempty"`
|
AlwaysScrapeClassicHistograms bool `yaml:"always_scrape_classic_histograms,omitempty"`
|
||||||
// Whether to convert all scraped classic histograms into a native histogram with custom buckets.
|
// Whether to convert all scraped classic histograms into a native histogram with custom buckets.
|
||||||
ConvertClassicHistogramsToNHCB bool `yaml:"convert_classic_histograms_to_nhcb,omitempty"`
|
ConvertClassicHistogramsToNHCB *bool `yaml:"convert_classic_histograms_to_nhcb,omitempty"`
|
||||||
// File to which scrape failures are logged.
|
// File to which scrape failures are logged.
|
||||||
ScrapeFailureLogFile string `yaml:"scrape_failure_log_file,omitempty"`
|
ScrapeFailureLogFile string `yaml:"scrape_failure_log_file,omitempty"`
|
||||||
// The HTTP resource path on which to fetch metrics from targets.
|
// The HTTP resource path on which to fetch metrics from targets.
|
||||||
@ -895,6 +899,11 @@ func (c *ScrapeConfig) Validate(globalConfig GlobalConfig) error {
|
|||||||
return fmt.Errorf("unknown scrape config name escaping method specified, must be one of '%s', '%s', '%s', or '%s', got %s", model.AllowUTF8, model.EscapeUnderscores, model.EscapeDots, model.EscapeValues, c.MetricNameValidationScheme)
|
return fmt.Errorf("unknown scrape config name escaping method specified, must be one of '%s', '%s', '%s', or '%s', got %s", model.AllowUTF8, model.EscapeUnderscores, model.EscapeDots, model.EscapeValues, c.MetricNameValidationScheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.ConvertClassicHistogramsToNHCB == nil {
|
||||||
|
globalVal := &globalConfig.ConvertClassicHistogramsToNHCB
|
||||||
|
c.ConvertClassicHistogramsToNHCB = globalVal
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,6 +926,11 @@ func ToValidationScheme(s string) (validationScheme model.ValidationScheme, err
|
|||||||
return validationScheme, nil
|
return validationScheme, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConvertClassicHistogramsToNHCBEnabled returns whether to convert classic histograms to NHCB
|
||||||
|
func (c *ScrapeConfig) ConvertClassicHistogramsToNHCBEnabled() bool {
|
||||||
|
return c.ConvertClassicHistogramsToNHCB != nil && *c.ConvertClassicHistogramsToNHCB
|
||||||
|
}
|
||||||
|
|
||||||
// StorageConfig configures runtime reloadable configuration options.
|
// StorageConfig configures runtime reloadable configuration options.
|
||||||
type StorageConfig struct {
|
type StorageConfig struct {
|
||||||
TSDBConfig *TSDBConfig `yaml:"tsdb,omitempty"`
|
TSDBConfig *TSDBConfig `yaml:"tsdb,omitempty"`
|
||||||
|
File diff suppressed because it is too large
Load Diff
6
config/testdata/global_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
6
config/testdata/global_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
global:
|
||||||
|
convert_classic_histograms_to_nhcb: true
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: prometheus
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:8080']
|
7
config/testdata/local_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
7
config/testdata/local_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
global:
|
||||||
|
convert_classic_histograms_to_nhcb: false
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: prometheus
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:8080']
|
||||||
|
convert_classic_histograms_to_nhcb: true
|
7
config/testdata/local_disable_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
7
config/testdata/local_disable_convert_classic_hist_to_nhcb.good.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
global:
|
||||||
|
convert_classic_histograms_to_nhcb: true
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: prometheus
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:8080']
|
||||||
|
convert_classic_histograms_to_nhcb: false
|
@ -140,6 +140,10 @@ global:
|
|||||||
# and underscores.
|
# and underscores.
|
||||||
[ metric_name_validation_scheme <string> | default "utf8" ]
|
[ metric_name_validation_scheme <string> | default "utf8" ]
|
||||||
|
|
||||||
|
# Specifies whether to convert all scraped classic histograms into native
|
||||||
|
# histograms with custom buckets.
|
||||||
|
[ convert_classic_histograms_to_nhcb <bool> | default = false]
|
||||||
|
|
||||||
runtime:
|
runtime:
|
||||||
# Configure the Go garbage collector GOGC parameter
|
# Configure the Go garbage collector GOGC parameter
|
||||||
# See: https://tip.golang.org/doc/gc-guide#GOGC
|
# See: https://tip.golang.org/doc/gc-guide#GOGC
|
||||||
@ -531,6 +535,11 @@ metric_relabel_configs:
|
|||||||
# 0 results in the smallest supported factor (which is currently ~1.0027 or
|
# 0 results in the smallest supported factor (which is currently ~1.0027 or
|
||||||
# schema 8, but might change in the future).
|
# schema 8, but might change in the future).
|
||||||
[ native_histogram_min_bucket_factor: <float> | default = 0 ]
|
[ native_histogram_min_bucket_factor: <float> | default = 0 ]
|
||||||
|
|
||||||
|
# Specifies whether to convert scraped classic histograms from this into
|
||||||
|
# native histogram with custom buckets.
|
||||||
|
[ convert_classic_histograms_to_nhcb <bool> | default = false
|
||||||
|
or global.convert_classic_histograms_to_nhcb if unset]
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `<job_name>` must be unique across all scrape configurations.
|
Where `<job_name>` must be unique across all scrape configurations.
|
||||||
|
@ -176,7 +176,7 @@ func (m *Manager) reload() {
|
|||||||
m.logger.Error("error reloading target set", "err", "invalid config id:"+setName)
|
m.logger.Error("error reloading target set", "err", "invalid config id:"+setName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if scrapeConfig.ConvertClassicHistogramsToNHCB && m.opts.EnableCreatedTimestampZeroIngestion {
|
if scrapeConfig.ConvertClassicHistogramsToNHCBEnabled() && m.opts.EnableCreatedTimestampZeroIngestion {
|
||||||
// TODO(krajorama): fix https://github.com/prometheus/prometheus/issues/15137
|
// TODO(krajorama): fix https://github.com/prometheus/prometheus/issues/15137
|
||||||
m.logger.Error("error reloading target set", "err", "cannot convert classic histograms to native histograms with custom buckets and ingest created timestamp zero samples at the same time due to https://github.com/prometheus/prometheus/issues/15137")
|
m.logger.Error("error reloading target set", "err", "cannot convert classic histograms to native histograms with custom buckets and ingest created timestamp zero samples at the same time due to https://github.com/prometheus/prometheus/issues/15137")
|
||||||
continue
|
continue
|
||||||
|
@ -367,7 +367,7 @@ func (sp *scrapePool) restartLoops(reuseCache bool) {
|
|||||||
mrc = sp.config.MetricRelabelConfigs
|
mrc = sp.config.MetricRelabelConfigs
|
||||||
fallbackScrapeProtocol = sp.config.ScrapeFallbackProtocol.HeaderMediaType()
|
fallbackScrapeProtocol = sp.config.ScrapeFallbackProtocol.HeaderMediaType()
|
||||||
alwaysScrapeClassicHist = sp.config.AlwaysScrapeClassicHistograms
|
alwaysScrapeClassicHist = sp.config.AlwaysScrapeClassicHistograms
|
||||||
convertClassicHistToNHCB = sp.config.ConvertClassicHistogramsToNHCB
|
convertClassicHistToNHCB = sp.config.ConvertClassicHistogramsToNHCBEnabled()
|
||||||
)
|
)
|
||||||
|
|
||||||
sp.targetMtx.Lock()
|
sp.targetMtx.Lock()
|
||||||
@ -523,7 +523,7 @@ func (sp *scrapePool) sync(targets []*Target) {
|
|||||||
mrc = sp.config.MetricRelabelConfigs
|
mrc = sp.config.MetricRelabelConfigs
|
||||||
fallbackScrapeProtocol = sp.config.ScrapeFallbackProtocol.HeaderMediaType()
|
fallbackScrapeProtocol = sp.config.ScrapeFallbackProtocol.HeaderMediaType()
|
||||||
alwaysScrapeClassicHist = sp.config.AlwaysScrapeClassicHistograms
|
alwaysScrapeClassicHist = sp.config.AlwaysScrapeClassicHistograms
|
||||||
convertClassicHistToNHCB = sp.config.ConvertClassicHistogramsToNHCB
|
convertClassicHistToNHCB = sp.config.ConvertClassicHistogramsToNHCB != nil && *sp.config.ConvertClassicHistogramsToNHCB
|
||||||
)
|
)
|
||||||
|
|
||||||
sp.targetMtx.Lock()
|
sp.targetMtx.Lock()
|
||||||
|
@ -4631,26 +4631,31 @@ metric: <
|
|||||||
require.Equal(t, expectedCount, count, "number of histogram series not as expected")
|
require.Equal(t, expectedCount, count, "number of histogram series not as expected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tru := true
|
||||||
|
fals := false
|
||||||
for metricsTextName, metricsText := range metricsTexts {
|
for metricsTextName, metricsText := range metricsTexts {
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
alwaysScrapeClassicHistograms bool
|
alwaysScrapeClassicHistograms bool
|
||||||
convertClassicHistToNHCB bool
|
convertClassicHistToNHCB *bool
|
||||||
}{
|
}{
|
||||||
"convert with scrape": {
|
"convert with scrape": {
|
||||||
alwaysScrapeClassicHistograms: true,
|
alwaysScrapeClassicHistograms: true,
|
||||||
convertClassicHistToNHCB: true,
|
convertClassicHistToNHCB: &tru,
|
||||||
},
|
},
|
||||||
"convert without scrape": {
|
"convert without scrape": {
|
||||||
alwaysScrapeClassicHistograms: false,
|
alwaysScrapeClassicHistograms: false,
|
||||||
convertClassicHistToNHCB: true,
|
convertClassicHistToNHCB: &tru,
|
||||||
},
|
},
|
||||||
"scrape without convert": {
|
"scrape without convert": {
|
||||||
alwaysScrapeClassicHistograms: true,
|
alwaysScrapeClassicHistograms: true,
|
||||||
convertClassicHistToNHCB: false,
|
convertClassicHistToNHCB: &fals,
|
||||||
|
},
|
||||||
|
"scrape with nil convert": {
|
||||||
|
alwaysScrapeClassicHistograms: true,
|
||||||
},
|
},
|
||||||
"neither scrape nor convert": {
|
"neither scrape nor convert": {
|
||||||
alwaysScrapeClassicHistograms: false,
|
alwaysScrapeClassicHistograms: false,
|
||||||
convertClassicHistToNHCB: false,
|
convertClassicHistToNHCB: &fals,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
var expectedClassicHistCount, expectedNativeHistCount int
|
var expectedClassicHistCount, expectedNativeHistCount int
|
||||||
@ -4664,17 +4669,17 @@ metric: <
|
|||||||
}
|
}
|
||||||
} else if metricsText.hasClassic {
|
} else if metricsText.hasClassic {
|
||||||
switch {
|
switch {
|
||||||
case tc.alwaysScrapeClassicHistograms && tc.convertClassicHistToNHCB:
|
case tc.convertClassicHistToNHCB == nil || !*tc.convertClassicHistToNHCB:
|
||||||
|
expectedClassicHistCount = 1
|
||||||
|
expectedNativeHistCount = 0
|
||||||
|
case tc.alwaysScrapeClassicHistograms && *tc.convertClassicHistToNHCB:
|
||||||
expectedClassicHistCount = 1
|
expectedClassicHistCount = 1
|
||||||
expectedNativeHistCount = 1
|
expectedNativeHistCount = 1
|
||||||
expectCustomBuckets = true
|
expectCustomBuckets = true
|
||||||
case !tc.alwaysScrapeClassicHistograms && tc.convertClassicHistToNHCB:
|
case !tc.alwaysScrapeClassicHistograms && *tc.convertClassicHistToNHCB:
|
||||||
expectedClassicHistCount = 0
|
expectedClassicHistCount = 0
|
||||||
expectedNativeHistCount = 1
|
expectedNativeHistCount = 1
|
||||||
expectCustomBuckets = true
|
expectCustomBuckets = true
|
||||||
case !tc.convertClassicHistToNHCB:
|
|
||||||
expectedClassicHistCount = 1
|
|
||||||
expectedNativeHistCount = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user