apple/swift-statsd-client

Support other formats for metric dimensions

開放

#13 建立於 2020年2月19日

 (2 則留言) (0 個反應) (0 位負責人)Swift (23 個分叉)auto 404
good first issuekind/enhancement

倉庫指標

星標
 (71 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

At present, the use of metrics dimensions results in some metrics being emitted in an unexpected way:

Timer(label: "my_event", dimensions: [("foo", "bar")]).recordNanoseconds(someDuration)

will emit a packet roughly like

my_event.foo.bar:123.45|ms

However, using the tag format for dimensions would be more appropriate in many applications:

my_event:123.45|ms#foo:bar

Unfortunately, there's not a standard syntax for tags (see https://github.com/statsd/statsd/issues/619), but I think this could be addressed by having an optional init parameter to specify the format:

enum DimensionFormat {
  case datadog
  case influxdb
  case inline
  // ..
}

class StatsdClient: MetricsFactory {
  public init(eventLoopGroupProvider: EventLoopGroupProvider = .createNew, host: String, port: Int, format: DimensionFormat = .inline) throws {
    // ...
  }
  // ...
}

// User initialization code
let statsdClient = try StatsdClient(host: statsdHost, port: statsdPort, format: .datadog)
MetricsSystem.bootstrap(statsdClient)

It may be preferable to avoid specific vendor names in the enum cases to avoid any sort of endorsement, but I'm confident that could be addressed.

Thoughts?

貢獻者指南