Skip to content

Commit

Permalink
Separate interface
Browse files Browse the repository at this point in the history
  • Loading branch information
njo committed Oct 15, 2024
1 parent 93282b6 commit 22d7056
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 36 deletions.
11 changes: 8 additions & 3 deletions common/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ type (

Stop(log.Logger)

// BatchStart returns a Handler that where supported, can emit a series of metrics as a single "wide event".
// StartBatch returns a BatchHandler that can emit a series of metrics as a single "wide event".
// If wide events aren't supported in the underlying implementation, metrics can still be sent individually.
BatchStart(string) (Handler, io.Closer)
StartBatch(string) BatchHandler
}

BatchHandler interface {
Handler
io.Closer
}

// CounterIface is an ever-increasing counter.
Expand All @@ -71,7 +76,7 @@ type (
// Tags provided are merged with the source MetricsHandler
Record(int64, ...Tag)
}
// GaugeIface can be set to any float and repesents a latest value instrument.
// GaugeIface can be set to any float and represents a latest value instrument.
GaugeIface interface {
// Record updates the gauge value.
// Tags provided are merged with the source MetricsHandler
Expand Down
167 changes: 151 additions & 16 deletions common/metrics/metrics_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions common/metrics/metricstest/capture_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package metricstest

import (
"io"
"sync"
"time"

Expand Down Expand Up @@ -147,8 +146,8 @@ func (c *CaptureHandler) Close() error {
return nil
}

func (c *CaptureHandler) BatchStart(_ string) (metrics.Handler, io.Closer) {
return c, c
func (c *CaptureHandler) StartBatch(_ string) metrics.BatchHandler {
return c
}

// Stop implements [metrics.Handler.Stop].
Expand Down
5 changes: 2 additions & 3 deletions common/metrics/noop_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package metrics

import (
"io"
"time"

"go.temporal.io/server/common/log"
Expand Down Expand Up @@ -73,8 +72,8 @@ func (*noopMetricsHandler) Close() error {
return nil
}

func (n *noopMetricsHandler) BatchStart(_ string) (Handler, io.Closer) {
return n, n
func (n *noopMetricsHandler) StartBatch(_ string) BatchHandler {
return n
}

var NoopCounterMetricFunc = CounterFunc(func(i int64, t ...Tag) {})
Expand Down
5 changes: 2 additions & 3 deletions common/metrics/otel_metrics_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package metrics
import (
"context"
"fmt"
"io"
"sync"
"time"

Expand Down Expand Up @@ -209,8 +208,8 @@ func (omp *otelMetricsHandler) Close() error {
return nil
}

func (omp *otelMetricsHandler) BatchStart(_ string) (Handler, io.Closer) {
return omp, omp
func (omp *otelMetricsHandler) StartBatch(_ string) BatchHandler {
return omp
}

// makeSet returns an otel attribute.Set with the given tags merged with the
Expand Down
5 changes: 2 additions & 3 deletions common/metrics/tally_metrics_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package metrics

import (
"io"
"time"

"github.com/uber-go/tally/v4"
Expand Down Expand Up @@ -125,8 +124,8 @@ func (*tallyMetricsHandler) Close() error {
return nil
}

func (tmh *tallyMetricsHandler) BatchStart(_ string) (Handler, io.Closer) {
return tmh, tmh
func (tmh *tallyMetricsHandler) StartBatch(_ string) BatchHandler {
return tmh
}

func tagsToMap(t1 []Tag, e excludeTags) map[string]string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package historybuilder

import (
"io"
"testing"
"time"

Expand Down Expand Up @@ -71,8 +70,8 @@ func (h StubHandler) Close() error {
return nil
}

func (h StubHandler) BatchStart(_ string) (metrics.Handler, io.Closer) {
return h, h
func (h StubHandler) StartBatch(_ string) metrics.BatchHandler {
return h
}

func TestHistoryBuilder_IsDirty(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions service/history/workflow/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func emitMutableStateStatus(
return
}

batchHandler, closer := metricsHandler.BatchStart("mutable_state_status")
defer closer.Close()
batchHandler := metricsHandler.StartBatch("mutable_state_status")
defer batchHandler.Close()
metrics.MutableStateSize.With(batchHandler).Record(int64(stats.TotalSize))
metrics.ExecutionInfoSize.With(batchHandler).Record(int64(stats.ExecutionInfoSize))
metrics.ExecutionStateSize.With(batchHandler).Record(int64(stats.ExecutionStateSize))
Expand Down

0 comments on commit 22d7056

Please # to comment.