Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#362): adds flush method to http reporter. #417

Merged
merged 4 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zipkin/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ declare namespace zipkin {
class BatchRecorder implements Recorder {
constructor(args: { logger: Logger, timeout?: number });
record: (rec: Record) => void;
flush: () => void;
}

class ConsoleRecorder implements Recorder {
Expand Down
11 changes: 11 additions & 0 deletions packages/zipkin/src/batch-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class BatchRecorder {
}
}

/**
* Calling this will flush any pending spans to the transport.
jcchavezs marked this conversation as resolved.
Show resolved Hide resolved
*
* Note: the transport itself may be batching, in such case you may need to flush that also.
*/
flush() {
this.partialSpans.forEach((span, id) => {
this._writeSpan(id, span);
});
}

record(rec) {
const id = rec.traceId;

Expand Down
27 changes: 27 additions & 0 deletions packages/zipkin/test/batch-recorder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,35 @@ describe('Batch Recorder - integration test', () => {
'http.status_code': '200'
}
});
});

it('should only flush spans when calling flush method', () => {
const clock = lolex.install();
recorder = new BatchRecorder({
logger: {
logSpan: (span) => {
spans.push(JSON.parse(JSON_V2.encode(span)));
}
}
});

recorder.record(record(rootId, now(), new Annotation.ServerRecv()));

expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions

clock.tick(100); // 1000 is de batching interval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally remove the lolex stuff as it is irrelevant. For example, we have other tests in the same file which show that records are not flushed until complete. The only responsibility this one should have is that when you hit flush the data is expected. The clock ticking stuff distracts from an otherwise simple goal IOTW. For this test you can even use fake timestamps like other things here

Copy link
Contributor Author

@jcchavezs jcchavezs Jul 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think for me it was better to make it clear that the flush occurs when it was not yet the time for a scheduled flush but definitively I can remove it.


expect(spans).to.be.empty; // eslint-disable-line no-unused-expressions

recorder.flush();

expect(popSpan()).to.deep.equal({
traceId: rootId.traceId,
id: rootId.spanId,
kind: 'SERVER'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised the timestamp didn't make it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it was because of lolex. I think this is ready to be merged.

});

clock.uninstall();
});

it('should handle overlapping server and client', () => {
Expand Down