Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ type MigrationContext struct {
AbortError error
abortMutex *sync.Mutex

Metrics metrics.MemStatsGaugeEmitter
Metrics metrics.Emitter

OriginalTableColumnsOnApplier *sql.ColumnList
OriginalTableColumns *sql.ColumnList
Expand Down
6 changes: 6 additions & 0 deletions go/logic/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ func (s *progressGaugeSpy) Gauge(name string, value float64, tags ...string) {
s.tags = append(s.tags, append([]string(nil), tags...))
}

func (s *progressGaugeSpy) Count(name string, value int64, tags ...string) {
}

func (s *progressGaugeSpy) Histogram(name string, value float64, tags ...string) {
}

func TestReportStatusEmitsProgressGaugesEveryTick(t *testing.T) {
spy := &progressGaugeSpy{}
ctx := base.NewMigrationContext()
Expand Down
2 changes: 1 addition & 1 deletion go/metrics/binlog_backlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package metrics

// EmitBinlogBacklogGauges emits apply-events queue depth gauges (namespace is applied by the client):
// gh_ost.binlog.backlog_size, gh_ost.binlog.backlog_capacity, gh_ost.binlog.backlog_utilization.
func EmitBinlogBacklogGauges(emit MemStatsGaugeEmitter, backlogSize, backlogCapacity int) {
func EmitBinlogBacklogGauges(emit Emitter, backlogSize, backlogCapacity int) {
if emit == nil {
return
}
Expand Down
13 changes: 11 additions & 2 deletions go/metrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type Client struct {
sd *statsd.Client
}

// MemStatsGaugeEmitter is implemented by *Client; used for tests without UDP.
type MemStatsGaugeEmitter interface {
// Emitter is implemented by *Client; used for tests without UDP.
type Emitter interface {
Gauge(name string, value float64, tags ...string)
Count(name string, value int64, tags ...string)
Histogram(name string, value float64, tags ...string)
}

// NewClient connects to addr for StatsD. If addr is empty, returns Noop and nil error.
Expand Down Expand Up @@ -65,6 +67,13 @@ func (c *Client) Count(name string, value int64, tags ...string) {
_ = c.sd.Count(name, value, tags, 1.0)
}

func (c *Client) Histogram(name string, value float64, tags ...string) {
if c.sd == nil {
return
}
_ = c.sd.Histogram(name, value, tags, 1.0)
}

// Close flushes buffered metrics; safe for Noop.
func (c *Client) Close() error {
if c.sd == nil {
Expand Down
2 changes: 1 addition & 1 deletion go/metrics/go_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// EmitGoRuntimeGauges emits gh_ost.go_runtime.* gauges (namespace is applied by the client).
// m and numGoroutine are typically from runtime.ReadMemStats and runtime.NumGoroutine.
func EmitGoRuntimeGauges(emit MemStatsGaugeEmitter, m *runtime.MemStats, numGoroutine int) {
func EmitGoRuntimeGauges(emit Emitter, m *runtime.MemStats, numGoroutine int) {
if emit == nil || m == nil {
return
}
Expand Down
6 changes: 6 additions & 0 deletions go/metrics/go_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func (g *gaugeSpy) Gauge(name string, value float64, tags ...string) {
g.tags = append(g.tags, append([]string(nil), tags...))
}

func (g *gaugeSpy) Count(name string, value int64, tags ...string) {
}

func (g *gaugeSpy) Histogram(name string, value float64, tags ...string) {
}

func TestEmitGoRuntimeGauges(t *testing.T) {
spy := &gaugeSpy{}
m := &runtime.MemStats{
Expand Down
2 changes: 1 addition & 1 deletion go/metrics/lag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "fmt"
// These are point-in-time readings each status tick (not a distribution), so gauges are used
// rather than histograms — DogStatsD histogram aggregation exposes count/max series that do not
// match the log line lag values in Prometheus/Grafana.
func EmitLagGauges(emit MemStatsGaugeEmitter, replicationLagSeconds, heartbeatLagSeconds float64, throttled bool) {
func EmitLagGauges(emit Emitter, replicationLagSeconds, heartbeatLagSeconds float64, throttled bool) {
if emit == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion go/metrics/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package metrics

// EmitProgressGauges emits row-copy and DML progress gauges (namespace is applied by the client):
// gh_ost.row_copy.rows_copied, gh_ost.row_copy.rows_estimate, gh_ost.dml.events_applied.
func EmitProgressGauges(emit MemStatsGaugeEmitter, rowsCopied, rowsEstimate, dmlEventsApplied int64) {
func EmitProgressGauges(emit Emitter, rowsCopied, rowsEstimate, dmlEventsApplied int64) {
if emit == nil {
return
}
Expand Down
Loading