metrics20 / spec

39 stars 8 forks source link

Wire format for adapters? #11

Open digitalsadhu opened 6 years ago

digitalsadhu commented 6 years ago

I'm toying with the idea of supporting passing in metrics "adapters" to a library and then internal to the library just calling said adapters with a standardized metrics format.

Example

// pass in prometheus adapter
const instance = new Library({ metrics: prometheusAdapter })

// inside the library, use the passed in adapter to send out metrics.
prometheusAdapter({
    what: 'response_time',
    http_code: 206,
    http_method: 'GET',
    host: 'dfsproxy1',
    service: 'proxy-server'
    stat: 'upper_90',
    swift_type: 'object'
    target_type: 'gauge'
    unit: 'ms'
})

Do you think metrics2.0 would be a good choice for the wire format? It should have most things needed in order to write adapters for the various metrics systems like prometheus etc. right?

Dieterbe commented 6 years ago

Hi Richard. I guess so. The example is a bit abstract. Tbh we should sit down with the Prometheus folks and see what they think of metric naming conventions and whether they think it jives with their approach. If you want I suppose you could make a mock-up / prototype that's a bit more concrete

digitalsadhu commented 6 years ago

Hi again @Dieterbe. Thanks for the response. I may sit down and sketch some code a little.

In any case the problem I'm trying to solve is. "How can you plug in your own metrics system into an app/library"? We do this already with logging. So long as the logger supports the same interface then we don't care which logger a consumer provides.

Something like:

// we are writing some library/app `MyThing`
new MyThing({
  logger: yourOwnLogger, // consumer provides logger, this works already
  metrics: yourOwnMetrics, // <-- cool if we could also do something like this
})

Inside Library we make use of logger by calling logger.info, logger.debug, logger.error etc.

So it would be nice if we could allow the consumer to bring their own metrics function/implementation and would could make use of it internally as appropriate.

I'll see if I can find some time to sketch out something a bit more specific at some point.

Thanks!

Dieterbe commented 6 years ago

I think it makes sense