Skip to content

Commit

Permalink
initialise metrics labels with 0
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Jun 3, 2023
1 parent e6092dc commit 726d468
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions p2p/protocol/holepunch/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ var (
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "address_outcomes_total",
Help: "Hole Punch Outcomes",
Help: "Hole Punch outcomes by Transport",
},
[]string{"side", "num_attempts", "ipv", "transport", "outcome"},
)
hpOutcomesTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "outcomes_total",
Help: "Hole Punch Failures because address mismatch",
Help: "Hole Punch outcomes overall",
},
[]string{"side", "num_attempts", "outcome"},
)
Expand Down Expand Up @@ -71,6 +71,23 @@ func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer {
opt(setting)
}
metricshelper.RegisterCollectors(setting.reg, collectors...)
// initialise metrics's labels so that the first data point is handled correctly
for _, side := range []string{"initiator", "receiver"} {
for _, numAttempts := range []string{"1", "2", "3", "4"} {
for _, outcome := range []string{"success", "failed", "cancelled", "no_suitable_address"} {
for _, ipv := range []string{"ip4", "ip6"} {
for _, transport := range []string{"quic", "quic-v1", "tcp", "webtransport"} {
hpAddressOutcomesTotal.WithLabelValues(side, numAttempts, ipv, transport, outcome)
}
}
if outcome == "cancelled" {
// not a valid outcome for the overall holepunch metric
continue
}
hpOutcomesTotal.WithLabelValues(side, numAttempts, outcome)
}
}
}
return &metricsTracer{}
}

Expand Down

0 comments on commit 726d468

Please sign in to comment.