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

Code before:
	if c.LabelLimit == 0 {
		c.LabelLimit = globalConfig.LabelLimit
	}
	if c.LabelNameLengthLimit == 0 {
		c.LabelNameLengthLimit = globalConfig.LabelNameLengthLimit
	}
	if c.LabelValueLengthLimit == 0 {
		c.LabelValueLengthLimit = globalConfig.LabelValueLengthLimit
	}
	if c.KeepDroppedTargets == 0 {
		c.KeepDroppedTargets = globalConfig.KeepDroppedTargets
	}
	if c.ScrapeFailureLogFile == "" {
		c.ScrapeFailureLogFile = globalConfig.ScrapeFailureLogFile
	}

	if c.ScrapeProtocols == nil {
		c.ScrapeProtocols = globalConfig.ScrapeProtocols
	}
	if err := validateAcceptScrapeProtocols(c.ScrapeProtocols); err != nil {
		return fmt.Errorf("%w for scrape config with job name %q", err, c.JobName)
	}

	if c.ScrapeFallbackProtocol != "" {
		if err := c.ScrapeFallbackProtocol.Validate(); err != nil {
			return fmt.Errorf("%w for fallback scrape config with job name %q", err, c.JobName)
		}
	}

	switch globalConfig.MetricNameValidationScheme {
	case LegacyValidationConfig:
	case "", UTF8ValidationConfig:
		if model.NameValidationScheme != model.UTF8Validation {
			panic("utf8 name validation requested but model.NameValidationScheme is not set to UTF8")
		}
	default:
		return fmt.Errorf("unknown name validation method specified, must be either 'legacy' or 'utf8', got %s", globalConfig.MetricNameValidationScheme)
	}
	if c.MetricNameValidationScheme == "" {
		c.MetricNameValidationScheme = globalConfig.MetricNameValidationScheme
	}

	return nil
}

// MarshalYAML implements the yaml.Marshaler interface.
func (c *ScrapeConfig) MarshalYAML() (interface{}, error) {
	return discovery.MarshalYAMLWithInlineConfigs(c)
}

// StorageConfig configures runtime reloadable configuration options.

Review comment (suggestion):
This somehow needs to refer explicitly to `fallback_scrape_protocol`, because the error message returned by `Validate` will not include it. Maybe:

```suggestion
			return fmt.Errorf("invalid fallback_scrape_protocol for scrape config with job name %q: %w", c.JobName, err)
```

Code after:
	if c.LabelLimit == 0 {
		c.LabelLimit = globalConfig.LabelLimit
	}
	if c.LabelNameLengthLimit == 0 {
		c.LabelNameLengthLimit = globalConfig.LabelNameLengthLimit
	}
	if c.LabelValueLengthLimit == 0 {
		c.LabelValueLengthLimit = globalConfig.LabelValueLengthLimit
	}
	if c.KeepDroppedTargets == 0 {
		c.KeepDroppedTargets = globalConfig.KeepDroppedTargets
	}
	if c.ScrapeFailureLogFile == "" {
		c.ScrapeFailureLogFile = globalConfig.ScrapeFailureLogFile
	}

	if c.ScrapeProtocols == nil {
		c.ScrapeProtocols = globalConfig.ScrapeProtocols
	}
	if err := validateAcceptScrapeProtocols(c.ScrapeProtocols); err != nil {
		return fmt.Errorf("%w for scrape config with job name %q", err, c.JobName)
	}

	if c.ScrapeFallbackProtocol != "" {
		if err := c.ScrapeFallbackProtocol.Validate(); err != nil {
			return fmt.Errorf("invalid fallback_scrape_protocol for scrape config with job name %q: %w", c.JobName, err)
		}
	}

	switch globalConfig.MetricNameValidationScheme {
	case LegacyValidationConfig:
	case "", UTF8ValidationConfig:
		if model.NameValidationScheme != model.UTF8Validation {
			panic("utf8 name validation requested but model.NameValidationScheme is not set to UTF8")
		}
	default:
		return fmt.Errorf("unknown name validation method specified, must be either 'legacy' or 'utf8', got %s", globalConfig.MetricNameValidationScheme)
	}
	if c.MetricNameValidationScheme == "" {
		c.MetricNameValidationScheme = globalConfig.MetricNameValidationScheme
	}

	return nil
}

// MarshalYAML implements the yaml.Marshaler interface.
func (c *ScrapeConfig) MarshalYAML() (interface{}, error) {
	return discovery.MarshalYAMLWithInlineConfigs(c)
}

// StorageConfig configures runtime reloadable configuration options.