Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Commit

Permalink
adds Recorder.Finish() method
Browse files Browse the repository at this point in the history
in order to reduce the number of `InfluxDBStore.Collect()` calls
  • Loading branch information
chris-ramon committed Apr 8, 2016
1 parent e664d3f commit 0d35bda
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions httptrace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (t *Transport) RoundTrip(original *http.Request) (*http.Response, error) {
e.Response.StatusCode = -1
}
child.Event(e)
child.Finish()
return resp, err
}

Expand Down
1 change: 1 addition & 0 deletions httptrace/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func Middleware(c appdash.Collector, conf *MiddlewareConfig) func(rw http.Respon
rec.Name(r.URL.Host + r.URL.Path)
}
rec.Event(e)
rec.Finish()
}
}

Expand Down
9 changes: 7 additions & 2 deletions recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
// A Recorder is associated with a span and records annotations on the
// span by sending them to a collector.
type Recorder struct {
SpanID // the span ID that annotations are about
SpanID // the span ID that annotations are about
annotations []Annotation // SpanID's annotations to be collected

collector Collector // the collector to send to

Expand Down Expand Up @@ -65,7 +66,11 @@ func (r *Recorder) Event(e Event) {
r.error("Event", err)
return
}
r.Annotation(as...)
r.annotations = append(r.annotations, as...)
}

func (r *Recorder) Finish() {
r.Annotation(r.annotations...)
}

// Annotation records raw annotations on the span.
Expand Down
13 changes: 8 additions & 5 deletions recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ func TestRecorder(t *testing.T) {
r := NewRecorder(id, c)

r.Msg("msg")
if calledCollect != 1 {
t.Errorf("got calledCollect %d, want 1", calledCollect)
if calledCollect != 0 {
t.Errorf("got calledCollect %d, want 0", calledCollect)
}
r.Finish()
if diff := diffAnnotationsFromEvent(anns, Msg("msg")); len(diff) > 0 {
t.Errorf("got diff annotations for Msg event:\n%s", strings.Join(diff, "\n"))
}

r.Name("name")
r.Finish()
if calledCollect != 2 {
t.Errorf("got calledCollect %d, want 1", calledCollect)
t.Errorf("got calledCollect %d, want 2", calledCollect)
}
if diff := diffAnnotationsFromEvent(anns, spanName{"name"}); len(diff) > 0 {
t.Errorf("got diff annotations for spanName event:\n%s", strings.Join(diff, "\n"))
Expand All @@ -53,9 +55,10 @@ func TestRecorder_Errors(t *testing.T) {
r := NewRecorder(SpanID{}, c)

r.Msg("msg")
if calledCollect != 2 {
t.Errorf("got calledCollect %d, want 1", calledCollect)
if calledCollect != 0 {
t.Errorf("got calledCollect %d, want 0", calledCollect)
}
r.Finish()
errs := r.Errors()
if want := []error{collectErr}; !reflect.DeepEqual(errs, want) {
t.Errorf("got errors %v, want %v", errs, want)
Expand Down

0 comments on commit 0d35bda

Please sign in to comment.