Skip to content

Commit

Permalink
Add project IDs to error logs
Browse files Browse the repository at this point in the history
When exporting metrics from multiple projects at once, it's useful to
know which of the projects is generating metrics errors.
  • Loading branch information
TylerLubeck committed Aug 21, 2024
1 parent 8ae3d33 commit a081613
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (c *MonitoringCollector) Collect(ch chan<- prometheus.Metric) {
if err := c.reportMonitoringMetrics(ch, begun); err != nil {
errorMetric = float64(1)
c.scrapeErrorsTotalMetric.Inc()
level.Error(c.logger).Log("msg", "Error while getting Google Stackdriver Monitoring metrics", "err", err)
level.Error(c.logger).Log("msg", "Error while getting Google Stackdriver Monitoring metrics", "err", err, "project_id", c.projectID)
}
c.scrapeErrorsTotalMetric.Collect(ch)

Expand Down Expand Up @@ -311,7 +311,7 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
}
}

level.Debug(c.logger).Log("msg", "retrieving Google Stackdriver Monitoring metrics with filter", "filter", filter)
level.Debug(c.logger).Log("msg", "retrieving Google Stackdriver Monitoring metrics with filter", "filter", filter, "project_id", c.projectID)

timeSeriesListCall := c.monitoringService.Projects.TimeSeries.List(utils.ProjectResource(c.projectID)).
Filter(filter).
Expand All @@ -322,15 +322,15 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
c.apiCallsTotalMetric.Inc()
page, err := timeSeriesListCall.Do()
if err != nil {
level.Error(c.logger).Log("msg", "error retrieving Time Series metrics for descriptor", "descriptor", metricDescriptor.Type, "err", err)
level.Error(c.logger).Log("msg", "error retrieving Time Series metrics for descriptor", "descriptor", metricDescriptor.Type, "err", err, "project_id", c.projectID)
errChannel <- err
break
}
if page == nil {
break
}
if err := c.reportTimeSeriesMetrics(page, metricDescriptor, ch, begun); err != nil {
level.Error(c.logger).Log("msg", "error reporting Time Series metrics for descriptor", "descriptor", metricDescriptor.Type, "err", err)
level.Error(c.logger).Log("msg", "error reporting Time Series metrics for descriptor", "descriptor", metricDescriptor.Type, "err", err, "project_id", c.projectID)
errChannel <- err
break
}
Expand Down Expand Up @@ -416,7 +416,7 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
c.aggregateDeltas,
)
if err != nil {
return fmt.Errorf("error creating the TimeSeriesMetrics %v", err)
return fmt.Errorf("error creating the TimeSeriesMetrics for project %s %v", c.projectID, err)
}
for _, timeSeries := range page.TimeSeries {
newestEndTime := time.Unix(0, 0)
Expand Down

0 comments on commit a081613

Please sign in to comment.