Skip to content

Commit

Permalink
Add RecordCustomMetric to *Application
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhellberg committed Oct 25, 2017
1 parent 8caf4d5 commit b4a4c1d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
18 changes: 17 additions & 1 deletion nrmock/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type Application struct {
AllTransactions []*Transaction
LatestTransaction *Transaction

CustomEvents map[string][]map[string]interface{}
CustomEvents map[string][]map[string]interface{}
CustomMetrics map[string][]float64
}

// NewApplication creates a new *Application
Expand Down Expand Up @@ -53,6 +54,21 @@ func (a *Application) RecordCustomEvent(eventType string, params map[string]inte
return nil
}

// RecordCustomMetric records a custom metric.
func (a *Application) RecordCustomMetric(name string, value float64) error {
if a.CustomMetrics == nil {
a.CustomMetrics = map[string][]float64{}
}

if a.CustomMetrics[name] == nil {
a.CustomMetrics[name] = []float64{}
}

a.CustomMetrics[name] = append(a.CustomMetrics[name], value)

return nil
}

// WaitForConnection does nothing
func (a *Application) WaitForConnection(timeout time.Duration) error {
return nil
Expand Down
17 changes: 17 additions & 0 deletions nrmock/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ func TestRecordCustomEvent(t *testing.T) {
}
}

func TestRecordCustomMetric(t *testing.T) {
app := &Application{}

app.RecordCustomMetric("foo", 12.3)
app.RecordCustomMetric("foo", 45.6)

foo := app.CustomMetrics["foo"]

if got, want := len(foo), 2; got != want {
t.Fatalf("len(foo) = %d, want %d", got, want)
}

if got, want := foo[1], 45.6; got != want {
t.Fatalf("foo[1] = %v, want %v", got, want)
}
}

func TestWaitForConnection(t *testing.T) {
app := &Application{}

Expand Down

0 comments on commit b4a4c1d

Please sign in to comment.