Repository: prometheus/prometheus
File: config/config.go (Go)

Code before:
	return DefaultRuntimeConfig.GoGC
}

type translationStrategyOption string

var (
	// NoUTF8EscapingWithSuffixes will accept metric/label names as they are.
	// Unit and type suffixes may be added to metric names, according to certain rules.
	NoUTF8EscapingWithSuffixes translationStrategyOption = "NoUTF8EscapingWithSuffixes"
	// UnderscoreEscapingWithSuffixes is the default option for translating OTLP to Prometheus.
	// This option will translate metric name characters that are not alphanumerics/underscores/colons to underscores,
	// and label name characters that are not alphanumerics/underscores to underscores.
	// Unit and type suffixes may be appended to metric names, according to certain rules.
	UnderscoreEscapingWithSuffixes translationStrategyOption = "UnderscoreEscapingWithSuffixes"
	// NoTranslation (EXPERIMENTAL): disables all translation of incoming metric
	// and label names.
	//
	// Note that because metrics in Open Telemetry are considered
	// distinct if they share the same name but have different Type or Units, for
	// instance "foo.bar" with units Seconds is a separate series from "foo.bar"
	// with units Milliseconds. Because prometheus can't differentiate timeseries
	// based on type and unit metadata, these two series would be conflated in
	// Prometheus. Therefore this setting is experimental and should not be used in
	// production systems.
	NoTranslation translationStrategyOption = "NoTranslation"
)

// OTLPConfig is the configuration for writing to the OTLP endpoint.
type OTLPConfig struct {
	PromoteResourceAttributes         []string                  `yaml:"promote_resource_attributes,omitempty"`
	TranslationStrategy               translationStrategyOption `yaml:"translation_strategy,omitempty"`
	KeepIdentifyingResourceAttributes bool                      `yaml:"keep_identifying_resource_attributes,omitempty"`
	ConvertHistogramsToNHCB           bool                      `yaml:"convert_histograms_to_nhcb,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *OTLPConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
	*c = DefaultOTLPConfig
	type plain OTLPConfig
	if err := unmarshal((*plain)(c)); err != nil {
		return err
	}

	seen := map[string]struct{}{}
	var err error
	for i, attr := range c.PromoteResourceAttributes {
		attr = strings.TrimSpace(attr)
		if attr == "" {
			err = errors.Join(err, errors.New("empty promoted OTel resource attribute"))
			continue
		}

Review comment (suggestion):
I think we missed explaining the main problem of not having those suffixes.

We wanted to add mention about those problems in our docs, so I proposed some changes https://github.com/prometheus/docs/pull/2626 (PTAL!). For now, we can mention https://prometheus.io/docs/practices/naming/ which already mentions the recommendations and might be updated with more context.

```suggestion
	// NoTranslation (EXPERIMENTAL) disables all translation of the incoming metric
	// and label names. This offers a way for the OTLP users to use native metric names, reducing confusion.
	//
	// WARNING: This setting has significant known risks and limitations (see 
	// https://prometheus.io/docs/practices/naming/  for details):
	// * Impaired UX when using PromQL in plain YAML (e.g. alerts, rules, dashboard, autoscaling configuration).
	// * Series collisions which in the best case may result in OOO errors, in the worst case a silently malformed
	// time series. For instance, you may end up in situation of ingesting `foo.bar` series with units 
	//`seconds` and a separate series  `foo.bar` with units `milliseconds`. 
	//
	// As a result, this setting is experimental and currently, should not be used in
	// production systems.
	//
	// TODO(ArthurSens): Mention `type-and-unit-labels` feature (https://github.com/prometheus/proposals/pull/39) once released, as potential mitigation of the above risks.
```

Code after:
	return DefaultRuntimeConfig.GoGC
}

type translationStrategyOption string

var (
	// NoUTF8EscapingWithSuffixes will accept metric/label names as they are.
	// Unit and type suffixes may be added to metric names, according to certain rules.
	NoUTF8EscapingWithSuffixes translationStrategyOption = "NoUTF8EscapingWithSuffixes"
	// UnderscoreEscapingWithSuffixes is the default option for translating OTLP to Prometheus.
	// This option will translate metric name characters that are not alphanumerics/underscores/colons to underscores,
	// and label name characters that are not alphanumerics/underscores to underscores.
	// Unit and type suffixes may be appended to metric names, according to certain rules.
	UnderscoreEscapingWithSuffixes translationStrategyOption = "UnderscoreEscapingWithSuffixes"
	// NoTranslation (EXPERIMENTAL): disables all translation of incoming metric
	// and label names. This offers a way for the OTLP users to use native metric names, reducing confusion.
	//
	// WARNING: This setting has significant known risks and limitations (see
	// https://prometheus.io/docs/practices/naming/  for details):
	// * Impaired UX when using PromQL in plain YAML (e.g. alerts, rules, dashboard, autoscaling configuration).
	// * Series collisions which in the best case may result in OOO errors, in the worst case a silently malformed
	// time series. For instance, you may end up in situation of ingesting `foo.bar` series with unit
	// `seconds` and a separate series `foo.bar` with unit `milliseconds`.
	//
	// As a result, this setting is experimental and currently, should not be used in
	// production systems.
	//
	// TODO(ArthurSens): Mention `type-and-unit-labels` feature (https://github.com/prometheus/proposals/pull/39) once released, as potential mitigation of the above risks.
	NoTranslation translationStrategyOption = "NoTranslation"
)

// OTLPConfig is the configuration for writing to the OTLP endpoint.
type OTLPConfig struct {
	PromoteResourceAttributes         []string                  `yaml:"promote_resource_attributes,omitempty"`
	TranslationStrategy               translationStrategyOption `yaml:"translation_strategy,omitempty"`
	KeepIdentifyingResourceAttributes bool                      `yaml:"keep_identifying_resource_attributes,omitempty"`
	ConvertHistogramsToNHCB           bool                      `yaml:"convert_histograms_to_nhcb,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *OTLPConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
	*c = DefaultOTLPConfig
	type plain OTLPConfig
	if err := unmarshal((*plain)(c)); err != nil {
		return err
	}

	seen := map[string]struct{}{}
	var err error
	for i, attr := range c.PromoteResourceAttributes {
		attr = strings.TrimSpace(attr)