refac: allow opt-in to OM CT ingestion

Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
Manik Rana 2024-08-27 21:01:21 +05:30
parent 82064d42b8
commit d14eb733e8
3 changed files with 7 additions and 4 deletions

View file

@ -80,7 +80,7 @@ type Parser interface {
//
// This function always returns a valid parser, but might additionally
// return an error if the content type cannot be parsed.
func New(b []byte, contentType string, parseClassicHistograms bool, st *labels.SymbolTable) (Parser, error) {
func New(b []byte, contentType string, parseClassicHistograms bool, skipOMSeries bool, st *labels.SymbolTable) (Parser, error) {
if contentType == "" {
return NewPromParser(b, st), nil
}
@ -91,7 +91,10 @@ func New(b []byte, contentType string, parseClassicHistograms bool, st *labels.S
}
switch mediaType {
case "application/openmetrics-text":
return NewOpenMetricsParser(b, st, WithOMParserCTSeriesSkipped()), nil
opts := func(o * openMetricsParserOptions) {
o.SkipCTSeries = skipOMSeries
}
return NewOpenMetricsParser(b, st, opts), nil
case "application/vnd.google.protobuf":
return NewProtobufParser(b, parseClassicHistograms, st), nil
default:

View file

@ -1489,7 +1489,7 @@ type appendErrors struct {
}
func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) {
p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms, sl.symbolTable)
p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms, sl.enableCTZeroIngestion, sl.symbolTable)
if err != nil {
level.Debug(sl.l).Log(
"msg", "Invalid content type on scrape, using prometheus parser as fallback.",

View file

@ -1482,7 +1482,7 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
fakeRef := storage.SeriesRef(1)
expValue := float64(1)
metric := []byte(`metric{n="1"} 1`)
p, warning := textparse.New(metric, "", false, labels.NewSymbolTable())
p, warning := textparse.New(metric, "", false, false, labels.NewSymbolTable())
require.NoError(t, warning)
var lset labels.Labels