Skip to content

Commit

Permalink
Avoid the defer and move the success metric under
Browse files Browse the repository at this point in the history
  • Loading branch information
Achooo committed Aug 1, 2023
1 parent d3522ee commit aaec9a6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions agent/hcp/telemetry_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,13 @@ func (h *hcpProviderImpl) getUpdate(ctx context.Context) *dynamicConfig {
Labels: telemetryCfg.MetricsConfig.Labels,
RefreshInterval: newRefreshInterval,
}
// Any success metric must be recorded before acquiring a write lock for config modifications
// to avoid a deadlock. The metric gets registered in the OTELSink via the FanoutSink of Go Metrics.
// The OTELSink tries to acquire a read lock to determine the metric filters using GetFilters().
metrics.IncrCounter(internalMetricRefreshSuccess, 1)

// Acquire write lock to update new configuration.
h.rw.Lock()
defer h.rw.Unlock()

h.cfg = newDynamicConfig
h.rw.Unlock()

metrics.IncrCounter(internalMetricRefreshSuccess, 1)

return newDynamicConfig
}
Expand Down

0 comments on commit aaec9a6

Please sign in to comment.