Skip to content

Explicitly set counter values #89

@rauhul

Description

@rauhul

swift-metrics doesn't currently provide a Gauge.record api for Counters and this probably makes as Counters are supposed to be strictly incrementing. However this behavior doesn't compose if the metric source already accumulates the value.

let total = GetTotalNetworkPackets()
Counter(label: "network_packets_total")
  .increment(total) // <-- increment is wrong here (double counting)

Instead you have to use a Gauge to directly set this value. However consumers now see the value as a gauge and not a counter which is the real behavior.

I'm not sure if this is actually something we want to support, but it probably warrants some thought.


Prometheus in go provides an escape hatch for this using NewConstMetric

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions