Repository: prometheus/prometheus
File: model/textparse/interface.go (Go)

Code before:
		retErr := fmt.Errorf("could not parse received Content-Type %q, using fallback_scrape_protocol %q", contentType, fallbackType)
		return fallbackType, errors.Join(retErr, err)
	}

	// We have a valid media type, either we recognise it and can use it
	// or we have to error.
	switch mediaType {
	case "application/openmetrics-text", "application/vnd.google.protobuf", "text/plain":
		return mediaType, nil
	}
	// We're here because we have no recognised mediaType.
	if fallbackType == "" {
		return "", fmt.Errorf("received unsupported Content-Type %q and no fallback_scrape_protocol specified for target", contentType)
	}
	return fallbackType, fmt.Errorf("received unsupported Content-Type %q, using fallback_scrape_protocol %q", contentType, fallbackType)
}

type parserOptions struct {
	enableTypeAndUnitLabels        bool
	convertClassicHistogramsToNHCB bool

	// Proto parsing only.
	parseClassicHistograms bool

	// OpenMetrics only.
	skipOMCTSeries bool

	fallbackType string

	st *labels.SymbolTable
}

type ParserOptions func(*parserOptions)

// WithTypeAndUnitLabels tells parser to include type and unit metadata as labels
// in the parsed metrics.
func WithTypeAndUnitLabels() ParserOptions {
	return func(o *parserOptions) {
		o.enableTypeAndUnitLabels = true
	}
}

// WithClassicHistogramsToNHCB tells parser to convert classic histograms
// to Native Histogram with Custom Buckets (NHCB) format.
func WithClassicHistogramsToNHCB() ParserOptions {
	return func(o *parserOptions) {
		o.convertClassicHistogramsToNHCB = true
	}
}

// WithKeepClassicOnClassicAndNativeHistograms tells parser to keep classic histograms in

Review comment (suggestion):
Aren't these comments abit hard to understand what the vars are doing?

Maybe over parseClassicHistograms use:
```go
// Whether to also parse a classic histogram that is also present as a native histogram.
```

That is the same comment here:

https://github.com/Naman-B-Parlecha/prometheus/blob/9d4432e11d4dfcbcd58ec8b8a49e97cee7399841/model/textparse/protobufparse.go#L80-L81

---

The most confusing for me is the OMCTSeries...

I think that this is related to the OpenMetrics Created Timestamp? And if we want to or not create the `_created suffix` to improve compatibility between OpenMetrics.

If that makes sense, maybe include some comment about it over the var.

Code after:
		retErr := fmt.Errorf("could not parse received Content-Type %q, using fallback_scrape_protocol %q", contentType, fallbackType)
		return fallbackType, errors.Join(retErr, err)
	}

	// We have a valid media type, either we recognise it and can use it
	// or we have to error.
	switch mediaType {
	case "application/openmetrics-text", "application/vnd.google.protobuf", "text/plain":
		return mediaType, nil
	}
	// We're here because we have no recognised mediaType.
	if fallbackType == "" {
		return "", fmt.Errorf("received unsupported Content-Type %q and no fallback_scrape_protocol specified for target", contentType)
	}
	return fallbackType, fmt.Errorf("received unsupported Content-Type %q, using fallback_scrape_protocol %q", contentType, fallbackType)
}

type ParserOptions struct {
	// EnableTypeAndUnitLabels enables parsing and inclusion of type and unit labels
	// in the parsed metrics.
	EnableTypeAndUnitLabels bool

	// ConvertClassicHistogramsToNHCB enables conversion of classic histograms
	// to native histogram custom buckets (NHCB) format.
	ConvertClassicHistogramsToNHCB bool

	// KeepClassicOnClassicAndNativeHistograms causes parser to output classic histogram
	// that is also present as a native histogram. (Proto parsing only).
	KeepClassicOnClassicAndNativeHistograms bool

	// OpenMetricsSkipCTSeries determines whether to skip `_created` timestamp series
	// during (OpenMetrics parsing only).
	OpenMetricsSkipCTSeries bool

	// FallbackContentType specifies the fallback content type to use when the provided
	// Content-Type header cannot be parsed or is not supported.
	FallbackContentType string
}

// New returns a new parser of the byte slice.
//
// This function no longer guarantees to return a valid parser.
//
// It only returns a valid parser if the supplied contentType and fallbackType allow.
// An error may also be returned if fallbackType had to be used or there was some
// other error parsing the supplied Content-Type.
// If the returned parser is nil then the scrape must fail.
func New(b []byte, contentType string, st *labels.SymbolTable, opts ParserOptions) (Parser, error) {
	if st == nil {
		st = labels.NewSymbolTable()
	}