Skip to content

Commit

Permalink
fix: record previous value of sampler counter metrics so they report …
Browse files Browse the repository at this point in the history
…correctly (#1281)

## Which problem is this PR solving?

- Fixes #1279 

## Short description of the changes

- Update the previous values 
- Fix a test that was sensitive to existing standard envvar
  • Loading branch information
kentquirk authored Aug 19, 2024
1 parent cde0584 commit e14617a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,17 @@ func TestHoneycombLoggerConfig(t *testing.T) {
config, rules := createTempConfigs(t, cm, rm)
defer os.Remove(rules)
defer os.Remove(config)
// Set the environment variable to test that it overrides the config
oldenv := os.Getenv("REFINERY_HONEYCOMB_API_KEY")
os.Setenv("REFINERY_HONEYCOMB_API_KEY", "321cba")
defer os.Setenv("REFINERY_HONEYCOMB_API_KEY", oldenv)
c, err := getConfig([]string{"--no-validate", "--config", config, "--rules_config", rules})
assert.NoError(t, err)

loggerConfig := c.GetHoneycombLoggerConfig()

assert.Equal(t, "http://honeycomb.io", loggerConfig.APIHost)
assert.Equal(t, "1234", loggerConfig.APIKey)
assert.Equal(t, "321cba", loggerConfig.APIKey)
assert.Equal(t, "loggerDataset", loggerConfig.Dataset)
assert.Equal(t, true, loggerConfig.GetSamplerEnabled())
assert.Equal(t, 5, loggerConfig.SamplerThroughput)
Expand Down
1 change: 1 addition & 0 deletions sample/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (d *DynamicSampler) GetSampleRate(trace *types.Trace) (rate uint, keep bool
case "counter":
delta := val - d.lastMetrics[name]
d.Metrics.Count(name, delta)
d.lastMetrics[name] = val
case "gauge":
d.Metrics.Gauge(name, val)
}
Expand Down
1 change: 1 addition & 0 deletions sample/dynamic_ema.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (d *EMADynamicSampler) GetSampleRate(trace *types.Trace) (rate uint, keep b
case "counter":
delta := val - d.lastMetrics[name]
d.Metrics.Count(name, delta)
d.lastMetrics[name] = val
case "gauge":
d.Metrics.Gauge(name, val)
}
Expand Down
1 change: 1 addition & 0 deletions sample/ema_throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (d *EMAThroughputSampler) GetSampleRate(trace *types.Trace) (rate uint, kee
case "counter":
delta := val - d.lastMetrics[name]
d.Metrics.Count(name, delta)
d.lastMetrics[name] = val
case "gauge":
d.Metrics.Gauge(name, val)
}
Expand Down
1 change: 1 addition & 0 deletions sample/totalthroughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (d *TotalThroughputSampler) GetSampleRate(trace *types.Trace) (rate uint, k
case "counter":
delta := val - d.lastMetrics[name]
d.Metrics.Count(name, delta)
d.lastMetrics[name] = val
case "gauge":
d.Metrics.Gauge(name, val)
}
Expand Down
1 change: 1 addition & 0 deletions sample/windowed_throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (d *WindowedThroughputSampler) GetSampleRate(trace *types.Trace) (rate uint
case "counter":
delta := val - d.lastMetrics[name]
d.Metrics.Count(name, delta)
d.lastMetrics[name] = val
case "gauge":
d.Metrics.Gauge(name, val)
}
Expand Down

0 comments on commit e14617a

Please sign in to comment.