Closed LukeWinikates closed 1 year ago
A further enhancement could be to expand the setters used in NewLineHandler for the command line parameters but that could be another pr too. Just feels like it might help with the readability of the handlers
I do like the idea trying to move the line formatting into the Factories in a way. Then the handler could have like a .send that would do all the formatting and send to the correct handler. Is this what your thinking?
I do like the idea trying to move the line formatting into the Factories in a way. Then the handler could have like a .send that would do all the formatting and send to the correct handler. Is this what your thinking?
Yep, I think that direction might work. I'm hoping to try incrementally refactoring towards that through a series of small PRs like this one.
@jbooherl thanks for looking at this PR and approving it! Since I'm confident these changes are safe, I'm going to go ahead and merge it and then in the next couple of days I might open another that keeps building on this.
The
NewSender
function currently uses a pattern like this:In this pattern, the caller must know that you send
points
with themetricsReporter
, you use thepoints
prefix, and you set theMetricFormat
.This PR moves this knowledge into dedicated factory functions for each line type, so that the factory knows the information, and the caller only needs to identify the right kind of handler to create - the factory is responsible for knowing how to create valid handlers.
idea: keep pushing type-specific logic into the
Handler
abstractionright now the
Sender
has methods that call a particular formatter and then pass its output to the correct handler. For example,SendMetric
callsmetric.Line
and then tries to send that with thesender.pointHandler
. It seems as though we could maybe package the line formatter and the line handler together somehow - why have theSender
know about so manyhandlers
and have to know which one to use which format with, when we could instead have the handler itself know the format transformation it needs to do, in the same way that it knows what prefixes and headers to put on its HTTP requests?idea: the
Handler
is actually aFormatSpecificBatchSender
or something like that.The
Handler
name seems to hide the fact that this abstraction is where formatted lines get batched together and eventually sent out.