Rename convert_classic_histograms to convert_classic_histograms_to_nhcb

On reviewer request.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
György Krajcsovits 2024-10-21 13:22:58 +02:00
parent a23aed5634
commit 4283ae73dc
4 changed files with 29 additions and 26 deletions

View file

@ -656,7 +656,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.
ConvertClassicHistograms bool `yaml:"convert_classic_histograms,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.

View file

@ -178,7 +178,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.ConvertClassicHistograms && m.opts.EnableCreatedTimestampZeroIngestion { if scrapeConfig.ConvertClassicHistogramsToNHCB && 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

View file

@ -113,7 +113,7 @@ type scrapeLoopOptions struct {
interval time.Duration interval time.Duration
timeout time.Duration timeout time.Duration
alwaysScrapeClassicHist bool alwaysScrapeClassicHist bool
convertClassicHistograms bool convertClassicHistToNHCB bool
validationScheme model.ValidationScheme validationScheme model.ValidationScheme
fallbackScrapeProtocol string fallbackScrapeProtocol string
@ -182,7 +182,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.Appendable, offsetSeed
opts.interval, opts.interval,
opts.timeout, opts.timeout,
opts.alwaysScrapeClassicHist, opts.alwaysScrapeClassicHist,
opts.convertClassicHistograms, opts.convertClassicHistToNHCB,
options.EnableNativeHistogramsIngestion, options.EnableNativeHistogramsIngestion,
options.EnableCreatedTimestampZeroIngestion, options.EnableCreatedTimestampZeroIngestion,
options.ExtraMetrics, options.ExtraMetrics,
@ -488,7 +488,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
convertClassicHistograms = sp.config.ConvertClassicHistograms convertClassicHistToNHCB = sp.config.ConvertClassicHistogramsToNHCB
) )
validationScheme := model.UTF8Validation validationScheme := model.UTF8Validation
@ -530,7 +530,7 @@ func (sp *scrapePool) sync(targets []*Target) {
interval: interval, interval: interval,
timeout: timeout, timeout: timeout,
alwaysScrapeClassicHist: alwaysScrapeClassicHist, alwaysScrapeClassicHist: alwaysScrapeClassicHist,
convertClassicHistograms: convertClassicHistograms, convertClassicHistToNHCB: convertClassicHistToNHCB,
validationScheme: validationScheme, validationScheme: validationScheme,
fallbackScrapeProtocol: fallbackScrapeProtocol, fallbackScrapeProtocol: fallbackScrapeProtocol,
}) })
@ -894,7 +894,7 @@ type scrapeLoop struct {
interval time.Duration interval time.Duration
timeout time.Duration timeout time.Duration
alwaysScrapeClassicHist bool alwaysScrapeClassicHist bool
convertClassicHistograms bool convertClassicHistToNHCB bool
validationScheme model.ValidationScheme validationScheme model.ValidationScheme
fallbackScrapeProtocol string fallbackScrapeProtocol string
@ -1196,7 +1196,7 @@ func newScrapeLoop(ctx context.Context,
interval time.Duration, interval time.Duration,
timeout time.Duration, timeout time.Duration,
alwaysScrapeClassicHist bool, alwaysScrapeClassicHist bool,
convertClassicHistograms bool, convertClassicHistToNHCB bool,
enableNativeHistogramIngestion bool, enableNativeHistogramIngestion bool,
enableCTZeroIngestion bool, enableCTZeroIngestion bool,
reportExtraMetrics bool, reportExtraMetrics bool,
@ -1252,7 +1252,7 @@ func newScrapeLoop(ctx context.Context,
interval: interval, interval: interval,
timeout: timeout, timeout: timeout,
alwaysScrapeClassicHist: alwaysScrapeClassicHist, alwaysScrapeClassicHist: alwaysScrapeClassicHist,
convertClassicHistograms: convertClassicHistograms, convertClassicHistToNHCB: convertClassicHistToNHCB,
enableNativeHistogramIngestion: enableNativeHistogramIngestion, enableNativeHistogramIngestion: enableNativeHistogramIngestion,
enableCTZeroIngestion: enableCTZeroIngestion, enableCTZeroIngestion: enableCTZeroIngestion,
reportExtraMetrics: reportExtraMetrics, reportExtraMetrics: reportExtraMetrics,
@ -1563,7 +1563,7 @@ func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string,
) )
return return
} }
if sl.convertClassicHistograms { if sl.convertClassicHistToNHCB {
p = textparse.NewNHCBParser(p, sl.symbolTable, sl.alwaysScrapeClassicHist) p = textparse.NewNHCBParser(p, sl.symbolTable, sl.alwaysScrapeClassicHist)
} }
if err != nil { if err != nil {
@ -1751,6 +1751,9 @@ loop:
} else { } else {
ref, err = app.AppendHistogram(ref, lset, t, nil, fh) ref, err = app.AppendHistogram(ref, lset, t, nil, fh)
} }
if err != nil {
fmt.Printf("Error when appending histogram in scrape loop: %s\n", err)
}
} else { } else {
ref, err = app.Append(ref, lset, t, val) ref, err = app.Append(ref, lset, t, val)
} }

View file

@ -3478,7 +3478,7 @@ test_summary_count 199
} }
// Testing whether we can automatically convert scraped classic histograms into native histograms with custom buckets. // Testing whether we can automatically convert scraped classic histograms into native histograms with custom buckets.
func TestConvertClassicHistograms(t *testing.T) { func TestConvertClassicHistogramsToNHCB(t *testing.T) {
genTestCounterText := func(name string, value int, withMetadata bool) string { genTestCounterText := func(name string, value int, withMetadata bool) string {
if withMetadata { if withMetadata {
return fmt.Sprintf(` return fmt.Sprintf(`
@ -3839,23 +3839,23 @@ metric: <
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
convertClassicHistograms bool convertClassicHistToNHCB bool
}{ }{
"convert with scrape": { "convert with scrape": {
alwaysScrapeClassicHistograms: true, alwaysScrapeClassicHistograms: true,
convertClassicHistograms: true, convertClassicHistToNHCB: true,
}, },
"convert without scrape": { "convert without scrape": {
alwaysScrapeClassicHistograms: false, alwaysScrapeClassicHistograms: false,
convertClassicHistograms: true, convertClassicHistToNHCB: true,
}, },
"scrape without convert": { "scrape without convert": {
alwaysScrapeClassicHistograms: true, alwaysScrapeClassicHistograms: true,
convertClassicHistograms: false, convertClassicHistToNHCB: false,
}, },
"neither scrape nor convert": { "neither scrape nor convert": {
alwaysScrapeClassicHistograms: false, alwaysScrapeClassicHistograms: false,
convertClassicHistograms: false, convertClassicHistToNHCB: false,
}, },
} { } {
var expectedClassicHistCount, expectedNativeHistCount int var expectedClassicHistCount, expectedNativeHistCount int
@ -3869,15 +3869,15 @@ metric: <
} }
} else if metricsText.hasClassic { } else if metricsText.hasClassic {
switch { switch {
case tc.alwaysScrapeClassicHistograms && tc.convertClassicHistograms: case tc.alwaysScrapeClassicHistograms && tc.convertClassicHistToNHCB:
expectedClassicHistCount = 1 expectedClassicHistCount = 1
expectedNativeHistCount = 1 expectedNativeHistCount = 1
expectCustomBuckets = true expectCustomBuckets = true
case !tc.alwaysScrapeClassicHistograms && tc.convertClassicHistograms: case !tc.alwaysScrapeClassicHistograms && tc.convertClassicHistToNHCB:
expectedClassicHistCount = 0 expectedClassicHistCount = 0
expectedNativeHistCount = 1 expectedNativeHistCount = 1
expectCustomBuckets = true expectCustomBuckets = true
case !tc.convertClassicHistograms: case !tc.convertClassicHistToNHCB:
expectedClassicHistCount = 1 expectedClassicHistCount = 1
expectedNativeHistCount = 0 expectedNativeHistCount = 0
} }
@ -3888,13 +3888,13 @@ metric: <
defer simpleStorage.Close() defer simpleStorage.Close()
config := &config.ScrapeConfig{ config := &config.ScrapeConfig{
JobName: "test", JobName: "test",
SampleLimit: 100, SampleLimit: 100,
Scheme: "http", Scheme: "http",
ScrapeInterval: model.Duration(100 * time.Millisecond), ScrapeInterval: model.Duration(100 * time.Millisecond),
ScrapeTimeout: model.Duration(100 * time.Millisecond), ScrapeTimeout: model.Duration(100 * time.Millisecond),
AlwaysScrapeClassicHistograms: tc.alwaysScrapeClassicHistograms, AlwaysScrapeClassicHistograms: tc.alwaysScrapeClassicHistograms,
ConvertClassicHistograms: tc.convertClassicHistograms, ConvertClassicHistogramsToNHCB: tc.convertClassicHistToNHCB,
} }
scrapeCount := 0 scrapeCount := 0