Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
avolokhov opened this issue Nov 13, 2020 · 2 comments
Assignees
Labels
1 - triaged enhancement New feature or request
Milestone

Comments

@avolokhov
Copy link
Contributor

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.

@ktoso ktoso added the enhancement New feature or request label Nov 16, 2020
@MrLotU
Copy link
Collaborator

MrLotU commented Nov 27, 2020

@avolokhov Thanks for opening this issue! I think this is a great feature to add.

However, with regards to "identifying metrics", the prometheus backend will automatically add job and instance labels to ALL metrics. Job being the job_name and instance being the host:port of the instance the metric was scraped from. I would suggest using these when possible, instead of adding them manually.

For other use-cases, I will look into adding base labels to PrometheusClient 👍

@MrLotU MrLotU self-assigned this Nov 27, 2020
@MrLotU MrLotU added this to the 1.0.0 milestone Jun 9, 2022
@ktoso ktoso modified the milestones: 1.0.0, 1.0.1 Jun 23, 2022
@ktoso
Copy link
Collaborator

ktoso commented Jun 23, 2022

1.0 shipped, so moving to 1.0.1

@ktoso ktoso modified the milestones: 1.0.1, 1.0.2 Oct 18, 2022
@ktoso ktoso modified the milestones: 1.0.2, 1.0.3 Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants