Skip to content

Commit

Permalink
Revert "Fix concurrent map write panic in monitoring middleware"
Browse files Browse the repository at this point in the history
This reverts commit 527da5c.
  • Loading branch information
carsonip committed Oct 10, 2024
1 parent 26496c1 commit 06ff323
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions internal/beater/middleware/monitoring_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package middleware
import (
"context"
"net/http"
"sync"
"time"

"go.opentelemetry.io/otel"
Expand All @@ -37,13 +36,9 @@ const (
type monitoringMiddleware struct {
meter metric.Meter

ints map[request.ResultID]*monitoring.Int

counters map[string]metric.Int64Counter
countersRWMutex sync.RWMutex

histograms map[string]metric.Int64Histogram
histogramsRWMutex sync.RWMutex
ints map[request.ResultID]*monitoring.Int
counters map[string]metric.Int64Counter
histograms map[string]metric.Int64Histogram
}

func (m *monitoringMiddleware) Middleware() Middleware {
Expand Down Expand Up @@ -84,40 +79,21 @@ func (m *monitoringMiddleware) inc(id request.ResultID) {

func (m *monitoringMiddleware) getCounter(n string) metric.Int64Counter {
name := "http.server." + n

m.countersRWMutex.RLock()
if met, ok := m.counters[name]; ok {
m.countersRWMutex.RUnlock()
return met
}

m.countersRWMutex.RUnlock()
m.countersRWMutex.Lock()
defer m.countersRWMutex.Unlock()
if met, ok := m.counters[name]; ok {
return met
}
nm, _ := m.meter.Int64Counter(name)
m.counters[name] = nm
return nm
}

func (m *monitoringMiddleware) getHistogram(n string, opts ...metric.Int64HistogramOption) metric.Int64Histogram {
name := "http.server." + n

m.histogramsRWMutex.RLock()
if met, ok := m.histograms[name]; ok {
m.histogramsRWMutex.RUnlock()
return met
}

m.histogramsRWMutex.RUnlock()
m.histogramsRWMutex.Lock()
defer m.histogramsRWMutex.Unlock()

if met, ok := m.histograms[name]; ok {
return met
}
nm, _ := m.meter.Int64Histogram(name, opts...)
m.histograms[name] = nm
return nm
Expand Down

0 comments on commit 06ff323

Please sign in to comment.