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
11 changes: 5 additions & 6 deletions metrics/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func NewStatsdMonitor(client statsdClient, prefix string) *StatsdMonitor {
// RecordRun records a run behavior
func (m *StatsdMonitor) RecordRun(run agent.Run) {
m.client.Timing(
m.createMetricName(runDurationMetricName, run.Recipe, run.Success, run.RecordCount),
m.createMetricName(runDurationMetricName, run.Recipe, run.Success),
int64(run.DurationInMs),
)
m.client.Increment(
m.createMetricName(runMetricName, run.Recipe, run.Success, run.RecordCount),
m.createMetricName(runMetricName, run.Recipe, run.Success),
)
m.client.IncrementByValue(
m.createMetricName(runRecordCountMetricName, run.Recipe, run.Success, run.RecordCount),
m.createMetricName(runRecordCountMetricName, run.Recipe, run.Success),
run.RecordCount,
)
}
Expand All @@ -64,19 +64,18 @@ func (m *StatsdMonitor) RecordPlugin(recipeName, pluginName, pluginType string,
}

// createMetricName creates a metric name for a given recipe and success
func (m *StatsdMonitor) createMetricName(metricName string, recipe recipe.Recipe, success bool, recordCount int) string {
func (m *StatsdMonitor) createMetricName(metricName string, recipe recipe.Recipe, success bool) string {
var successText = "false"
if success {
successText = "true"
}

return fmt.Sprintf(
"%s.%s,name=%s,success=%s,records=%d,extractor=%s",
"%s.%s,name=%s,success=%s,extractor=%s",
m.prefix,
metricName,
recipe.Name,
successText,
recordCount,
recipe.Source.Name,
)
}
Expand Down
22 changes: 8 additions & 14 deletions metrics/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,24 @@ func TestStatsdMonitorRecordRun(t *testing.T) {
duration := 100
recordCount := 2
timingMetric := fmt.Sprintf(
"%s.runDuration,name=%s,success=%s,records=%d,extractor=%s",
"%s.runDuration,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"false",
recordCount,
recipe.Source.Name,
)
incrementMetric := fmt.Sprintf(
"%s.run,name=%s,success=%s,records=%d,extractor=%s",
"%s.run,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"false",
recordCount,
recipe.Source.Name,
)
recordIncrementMetric := fmt.Sprintf(
"%s.runRecordCount,name=%s,success=%s,records=%d,extractor=%s",
"%s.runRecordCount,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"false",
recordCount,
recipe.Source.Name,
)

Expand All @@ -118,7 +115,7 @@ func TestStatsdMonitorRecordRun(t *testing.T) {
defer client.AssertExpectations(t)

monitor := metrics.NewStatsdMonitor(client, statsdPrefix)
monitor.RecordRun(agent.Run{Recipe: recipe, DurationInMs: duration, RecordCount: 2, Success: false})
monitor.RecordRun(agent.Run{Recipe: recipe, DurationInMs: duration, RecordCount: recordCount, Success: false})
})

t.Run("should set success field to true on success", func(t *testing.T) {
Expand All @@ -131,27 +128,24 @@ func TestStatsdMonitorRecordRun(t *testing.T) {
duration := 100
recordCount := 2
timingMetric := fmt.Sprintf(
"%s.runDuration,name=%s,success=%s,records=%d,extractor=%s",
"%s.runDuration,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"true",
recordCount,
recipe.Source.Name,
)
incrementMetric := fmt.Sprintf(
"%s.run,name=%s,success=%s,records=%d,extractor=%s",
"%s.run,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"true",
recordCount,
recipe.Source.Name,
)
recordIncrementMetric := fmt.Sprintf(
"%s.runRecordCount,name=%s,success=%s,records=%d,extractor=%s",
"%s.runRecordCount,name=%s,success=%s,extractor=%s",
statsdPrefix,
recipe.Name,
"true",
recordCount,
recipe.Source.Name,
)

Expand All @@ -162,7 +156,7 @@ func TestStatsdMonitorRecordRun(t *testing.T) {
defer client.AssertExpectations(t)

monitor := metrics.NewStatsdMonitor(client, statsdPrefix)
monitor.RecordRun(agent.Run{Recipe: recipe, DurationInMs: duration, RecordCount: 2, Success: true})
monitor.RecordRun(agent.Run{Recipe: recipe, DurationInMs: duration, RecordCount: recordCount, Success: true})
})
}

Expand Down