Skip to content

Commit

Permalink
Fix multi reporter, ensure idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
mway committed Mar 16, 2021
1 parent 7bdd64e commit fb8157a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions m3/resource_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (r *resourcePool) releaseProto(proto thrift.TProtocol) {
}

func (r *resourcePool) releaseMetricSlice(metrics []m3thrift.Metric) {
if metrics == nil {
return
}

for i := 0; i < len(metrics); i++ {
metrics[i].Tags = nil
}
Expand All @@ -92,5 +96,9 @@ func (r *resourcePool) releaseMetricSlice(metrics []m3thrift.Metric) {

//nolint:unused
func (r *resourcePool) releaseMetricTagSlice(tags []m3thrift.MetricTag) {
if tags == nil {
return
}

r.metricSlicePool.Put(tags[:0])
}
24 changes: 24 additions & 0 deletions multi/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func (r *multiCached) AllocateCounter(
return multiMetric{counters: metrics}
}

func (r *multiCached) DeallocateCounter(counter tally.CachedCount) {
for _, rep := range r.reporters {
rep.DeallocateCounter(counter)
}
}

func (r *multiCached) AllocateGauge(
name string,
tags map[string]string,
Expand All @@ -152,6 +158,12 @@ func (r *multiCached) AllocateGauge(
return multiMetric{gauges: metrics}
}

func (r *multiCached) DeallocateGauge(gauge tally.CachedGauge) {
for _, rep := range r.reporters {
rep.DeallocateGauge(gauge)
}
}

func (r *multiCached) AllocateTimer(
name string,
tags map[string]string,
Expand All @@ -163,6 +175,12 @@ func (r *multiCached) AllocateTimer(
return multiMetric{timers: metrics}
}

func (r *multiCached) DeallocateTimer(timer tally.CachedTimer) {
for _, rep := range r.reporters {
rep.DeallocateTimer(timer)
}
}

func (r *multiCached) AllocateHistogram(
name string,
tags map[string]string,
Expand All @@ -175,6 +193,12 @@ func (r *multiCached) AllocateHistogram(
return multiMetric{histograms: metrics}
}

func (r *multiCached) DeallocateHistogram(histogram tally.CachedHistogram) {
for _, rep := range r.reporters {
rep.DeallocateHistogram(histogram)
}
}

func (r *multiCached) Capabilities() tally.Capabilities {
return r.multiBaseReporters.Capabilities()
}
Expand Down
8 changes: 8 additions & 0 deletions multi/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (r *capturingStatsReporter) AllocateCounter(
}}
}

func (r *capturingStatsReporter) DeallocateCounter(tally.CachedCount) {}

func (r *capturingStatsReporter) AllocateGauge(
name string,
tags map[string]string,
Expand All @@ -290,6 +292,8 @@ func (r *capturingStatsReporter) AllocateGauge(
}}
}

func (r *capturingStatsReporter) DeallocateGauge(tally.CachedGauge) {}

func (r *capturingStatsReporter) AllocateTimer(
name string,
tags map[string]string,
Expand All @@ -299,6 +303,8 @@ func (r *capturingStatsReporter) AllocateTimer(
}}
}

func (r *capturingStatsReporter) DeallocateTimer(tally.CachedTimer) {}

func (r *capturingStatsReporter) AllocateHistogram(
name string,
tags map[string]string,
Expand All @@ -320,6 +326,8 @@ func (r *capturingStatsReporter) AllocateHistogram(
}
}

func (r *capturingStatsReporter) DeallocateHistogram(tally.CachedHistogram) {}

func (r *capturingStatsReporter) Capabilities() tally.Capabilities {
r.capabilities++
return r
Expand Down

0 comments on commit fb8157a

Please sign in to comment.