Skip to content

Commit

Permalink
receiver/prometheus: Ensure AdjustMetrics doesn't partially modify me…
Browse files Browse the repository at this point in the history
…trics
  • Loading branch information
ridwanmsharif committed Dec 11, 2024
1 parent b4af9c7 commit bb2a3b4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions receiver/prometheusreceiver/internal/metrics_adjuster.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,21 @@ func NewInitialPointAdjuster(logger *zap.Logger, gcInterval time.Duration, useCr
func (a *initialPointAdjuster) AdjustMetrics(metrics pmetric.Metrics) error {
for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
rm := metrics.ResourceMetrics().At(i)
job, found := rm.Resource().Attributes().Get(semconv.AttributeServiceName)
_, found := rm.Resource().Attributes().Get(semconv.AttributeServiceName)
if !found {
return errors.New("adjusting metrics without job")
}

instance, found := rm.Resource().Attributes().Get(semconv.AttributeServiceInstanceID)
_, found = rm.Resource().Attributes().Get(semconv.AttributeServiceInstanceID)
if !found {
return errors.New("adjusting metrics without instance")
}
}

for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
rm := metrics.ResourceMetrics().At(i)
job, _ := rm.Resource().Attributes().Get(semconv.AttributeServiceName)
instance, _ := rm.Resource().Attributes().Get(semconv.AttributeServiceInstanceID)
tsm := a.jobsMap.get(job.Str(), instance.Str())

// The lock on the relevant timeseriesMap is held throughout the adjustment process to ensure that
Expand Down

0 comments on commit bb2a3b4

Please sign in to comment.