in confgenerator/prometheus.go [199:274]
func validatePrometheus(promConfig promconfig.Config) (string, error) {
if len(promConfig.ScrapeConfigs) == 0 {
return "scrape_config", errors.New("no Prometheus scrape_configs")
}
// Reject features that Prometheus supports but that the receiver doesn't support:
// See:
// * https://github.com/open-telemetry/opentelemetry-collector/issues/3863
// * https://github.com/open-telemetry/wg-prometheus/issues/3
unsupportedFeatures := make([]string, 0, 4)
if len(promConfig.RemoteWriteConfigs) != 0 {
unsupportedFeatures = append(unsupportedFeatures, "remote_write")
}
if len(promConfig.RemoteReadConfigs) != 0 {
unsupportedFeatures = append(unsupportedFeatures, "remote_read")
}
if len(promConfig.RuleFiles) != 0 {
unsupportedFeatures = append(unsupportedFeatures, "rule_files")
}
if len(promConfig.AlertingConfig.AlertRelabelConfigs) != 0 {
unsupportedFeatures = append(unsupportedFeatures, "alert_config.relabel_configs")
}
if len(promConfig.AlertingConfig.AlertmanagerConfigs) != 0 {
unsupportedFeatures = append(unsupportedFeatures, "alert_config.alertmanagers")
}
if len(unsupportedFeatures) != 0 {
// Sort the values for deterministic error messages.
sort.Strings(unsupportedFeatures)
return strings.Join(unsupportedFeatures, ","), fmt.Errorf("unsupported features:\n\t%s", strings.Join(unsupportedFeatures, "\n\t"))
}
for _, sc := range promConfig.ScrapeConfigs {
if sc.ScrapeInterval < minScrapeInterval {
sc.ScrapeInterval = minScrapeInterval
log.Printf("scrape_interval must be at least %v; adjusting to minimum accepted value\n", minScrapeInterval)
}
if sc.HonorLabels {
return "honor_labels", fmt.Errorf("error validating scrape_config for job %v: %v", sc.JobName, "honor_labels is not supported")
}
for _, rc := range sc.RelabelConfigs {
if rc.TargetLabel == "location" || rc.TargetLabel == "namespace" || rc.TargetLabel == "cluster" {
return "relabel_config", fmt.Errorf("error validating scrape_config for job %v: %v", sc.JobName, "relabel_configs cannot rename location, namespace or cluster")
}
}
for _, rc := range sc.MetricRelabelConfigs {
if rc.TargetLabel == "__name__" {
// TODO(#2297): Remove validation after renaming is fixed
return "metric_relabel_config", fmt.Errorf("error validating scrape_config for job %v: %v", sc.JobName, "metric_relabel_configs cannot rename __name__")
}
if rc.TargetLabel == "location" || rc.TargetLabel == "namespace" || rc.TargetLabel == "cluster" {
return "metric_relabel_config", fmt.Errorf("error validating scrape_config for job %v: %v", sc.JobName, "metric_relabel_configs cannot rename location, namespace or cluster")
}
}
if sc.HTTPClientConfig.Authorization != nil {
if err := checkFile(sc.HTTPClientConfig.Authorization.CredentialsFile); err != nil {
return "authorization.credentials_file", fmt.Errorf("error checking authorization credentials file %q: %w", sc.HTTPClientConfig.Authorization.CredentialsFile, err)
}
}
if err := checkTLSConfig(sc.HTTPClientConfig.TLSConfig); err != nil {
return "tls_config", err
}
for _, c := range sc.ServiceDiscoveryConfigs {
switch c := c.(type) {
case discovery.StaticConfig:
default:
return fmt.Sprintf("%T", c), fmt.Errorf("unsupported service discovery config %T", c)
}
}
}
return "", nil
}