diff --git a/cmd/google_cloud_ops_agent_diagnostics/main.go b/cmd/google_cloud_ops_agent_diagnostics/main.go index 41908489f0..79b7299ab7 100644 --- a/cmd/google_cloud_ops_agent_diagnostics/main.go +++ b/cmd/google_cloud_ops_agent_diagnostics/main.go @@ -44,7 +44,7 @@ func getUserAndMergedConfigs(ctx context.Context, userConfPath string) (*confgen func main() { defer func() { if r := recover(); r != nil { - log.Fatal("Recovered in run", r) + log.Fatalf("Recovering from a panic due to %v", r) } }() if err := run(context.Background()); err != nil { diff --git a/confgenerator/prometheus.go b/confgenerator/prometheus.go index e7066c0df7..d12831168b 100644 --- a/confgenerator/prometheus.go +++ b/confgenerator/prometheus.go @@ -62,27 +62,29 @@ func (r PrometheusMetrics) Type() string { func (r PrometheusMetrics) Pipelines(ctx context.Context) []otel.ReceiverPipeline { // Get the resource metadata for the instance we're running on. - resourceMetadataMap := MetadataResource.PrometheusStyleMetadata() - if p := platform.FromContext(ctx).ResourceOverride; p != nil { - resourceMetadataMap = p.PrometheusStyleMetadata() - } + if MetadataResource != nil { + resourceMetadataMap := MetadataResource.PrometheusStyleMetadata() + if p := platform.FromContext(ctx).ResourceOverride; p != nil { + resourceMetadataMap = p.PrometheusStyleMetadata() + } - // Add the GCE metadata to the prometheus config. - for i := range r.PromConfig.ScrapeConfigs { - // Iterate over the static configs. - for j := range r.PromConfig.ScrapeConfigs[i].ServiceDiscoveryConfigs { - staticConfigs := r.PromConfig.ScrapeConfigs[i].ServiceDiscoveryConfigs[j].(discovery.StaticConfig) - for k := range staticConfigs { - labels := staticConfigs[k].Labels - if labels == nil { - labels = model.LabelSet{} + // Add the GCE metadata to the prometheus config. + for i := range r.PromConfig.ScrapeConfigs { + // Iterate over the static configs. + for j := range r.PromConfig.ScrapeConfigs[i].ServiceDiscoveryConfigs { + staticConfigs := r.PromConfig.ScrapeConfigs[i].ServiceDiscoveryConfigs[j].(discovery.StaticConfig) + for k := range staticConfigs { + labels := staticConfigs[k].Labels + if labels == nil { + labels = model.LabelSet{} + } + for k, v := range resourceMetadataMap { + // If there are conflicts, the resource metadata should take precedence. + labels[model.LabelName(k)] = model.LabelValue(v) + } + + staticConfigs[k].Labels = labels } - for k, v := range resourceMetadataMap { - // If there are conflicts, the resource metadata should take precedence. - labels[model.LabelName(k)] = model.LabelValue(v) - } - - staticConfigs[k].Labels = labels } } }