wavefrontHQ / wavefront-sdk-go

Wavefront Core Go SDK
Apache License 2.0
4 stars 21 forks source link

refactor: type-specific 'handlers' #176

Open LukeWinikates opened 10 months ago

LukeWinikates commented 10 months ago

This PR consolidates a repetitive trySendWith pattern in senders.realSender into a simpler pattern.

This PR assumes that #175 will be merged first

Old Pattern

func (sender *realSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
    line, err := metric.Line(name, value, ts, source, tags, sender.defaultSource)
    return trySendWith(
        line,
        err,
        sender.pointHandler,
        sender.internalRegistry.PointsTracker(),
    )
}

New Pattern

func (sender *realSender) SendMetric(name string, value float64, ts int64, source string, tags map[string]string) error {
    return sender.pointSender.TrySend(metric.Line(name, value, ts, source, tags, sender.defaultSource))
}

In the new pattern, the caller of trySendWith only needs to tie together two related things (metric.Line and pointSender), whereas before they needed to chose correctly 3 times (metric.Line, pointHandler, PointsTracker).

The new pattern also mostly allows us to avoid line, err as local variables, so that the Send* methods can be as short as 1 line.

Other opportunistic changes

Issues