Skip to content

Allow PrometheusClient to init with a predefined set of common dimensions. #36

Open
@avolokhov

Description

@avolokhov

Feature Request

When reporting Prometheus metrics, it's sometimes useful to always append a certain set of dimensions to every published metric (e.g. nodeId, appName, etc.).

Motivation Behind Feature

We don't control metrics creation in dependencies and can't set dimensions to their metrics. This would mean we won't be able to distinguish such metrics published from different apps or nodes.

Feature Description

PrometheusClient may accept a set of common dimensions it'll append to every published metric.

class PrometheusClient {
  let dimensions: [(String, String)]

  <...>
}

I can see it might clash with current Labels signature and may require a "merge" method on the MetricLabels protocol:

public protocol MetricLabels: Encodable, Hashable {
    /// Create empty labels
    init()

    func append(dimensions: [(String, String)])
}

Alternatives or Workarounds

Currently I'm trying to use a custom conformance to MetricsFactory

class DimensionalPrometheusMetrics: MetricsFactory {
    let prometheus: PrometheusClient
    let commonDimensions: [(String, String)]

    <...>
}

Which is not ideal because it will only work when I publish metrics via swift-metrics api. If need custom buckets/quantiles I'll have to set dimensions manually.

Metadata

Metadata

Assignees

Labels

kind/enhancementImprovements to existing feature.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions