fix(build): remove promauto dependency, use explicit reg.MustRegister
Some checks failed
ci / race tests (push) Blocked by required conditions
ci / WebRTC smoke (5-viewer fanout) (push) Blocked by required conditions
ci / WebRTC latency p95 gate (push) Blocked by required conditions
ci / vet + build (push) Has been cancelled

promauto is not in the vendor tree. Replace promauto.With(reg).NewXxx()
with prometheus.NewXxx() + reg.MustRegister() — functionally identical
but uses only the already-vendored prometheus/client_golang/prometheus
package. Fixes the vendor-mode build error:

  cannot find module providing package .../prometheus/promauto
This commit is contained in:
Zac Gaetano 2026-05-09 16:16:31 -04:00
parent 70d0ddb2e3
commit 890b09a33c

View file

@ -6,7 +6,6 @@ import (
corewebrtc "github.com/datarhei/core/v16/core/webrtc" corewebrtc "github.com/datarhei/core/v16/core/webrtc"
coreprom "github.com/datarhei/core/v16/prometheus" coreprom "github.com/datarhei/core/v16/prometheus"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var iceHistBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10} var iceHistBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}
@ -21,43 +20,63 @@ type webrtcMetrics struct {
ffmpegLegFailures *prometheus.CounterVec ffmpegLegFailures *prometheus.CounterVec
} }
// mustRegisterCounter creates a CounterVec and registers it with reg.
// Panics on duplicate registration (same semantics as promauto).
func mustRegisterCounter(reg prometheus.Registerer, opts prometheus.CounterOpts, labels []string) *prometheus.CounterVec {
m := prometheus.NewCounterVec(opts, labels)
reg.MustRegister(m)
return m
}
// mustRegisterHistogram creates a HistogramVec and registers it with reg.
func mustRegisterHistogram(reg prometheus.Registerer, opts prometheus.HistogramOpts, labels []string) *prometheus.HistogramVec {
m := prometheus.NewHistogramVec(opts, labels)
reg.MustRegister(m)
return m
}
func initMetrics(reg prometheus.Registerer, core string) *webrtcMetrics { func initMetrics(reg prometheus.Registerer, core string) *webrtcMetrics {
f := promauto.With(reg)
cl := prometheus.Labels{"core": core} cl := prometheus.Labels{"core": core}
return &webrtcMetrics{ return &webrtcMetrics{
whepRequests: f.NewCounterVec(prometheus.CounterOpts{ whepRequests: mustRegisterCounter(reg, prometheus.CounterOpts{
Name: "dragonfork_webrtc_whep_requests_total", Name: "dragonfork_webrtc_whep_requests_total",
Help: "Count of WHEP HTTP requests by route, HTTP status code, and stream.", Help: "Count of WHEP HTTP requests by route, HTTP status code, and stream.",
ConstLabels: cl, ConstLabels: cl,
}, []string{"route", "code", "stream_id"}), }, []string{"route", "code", "stream_id"}),
whepRequestDuration: f.NewHistogramVec(prometheus.HistogramOpts{
whepRequestDuration: mustRegisterHistogram(reg, prometheus.HistogramOpts{
Name: "dragonfork_webrtc_whep_request_duration_seconds", Name: "dragonfork_webrtc_whep_request_duration_seconds",
Help: "Server-side WHEP request latency in seconds, by route and stream.", Help: "Server-side WHEP request latency in seconds, by route and stream.",
ConstLabels: cl, ConstLabels: cl,
Buckets: iceHistBuckets, Buckets: iceHistBuckets,
}, []string{"route", "stream_id"}), }, []string{"route", "stream_id"}),
iceEstablishment: f.NewHistogramVec(prometheus.HistogramOpts{
iceEstablishment: mustRegisterHistogram(reg, prometheus.HistogramOpts{
Name: "dragonfork_webrtc_ice_establishment_duration_seconds", Name: "dragonfork_webrtc_ice_establishment_duration_seconds",
Help: "Duration from peer creation to first connected or failed ICE state.", Help: "Duration from peer creation to first connected or failed ICE state.",
ConstLabels: cl, ConstLabels: cl,
Buckets: iceHistBuckets, Buckets: iceHistBuckets,
}, []string{"stream_id", "result"}), }, []string{"stream_id", "result"}),
iceFailures: f.NewCounterVec(prometheus.CounterOpts{
iceFailures: mustRegisterCounter(reg, prometheus.CounterOpts{
Name: "dragonfork_webrtc_ice_failures_total", Name: "dragonfork_webrtc_ice_failures_total",
Help: "Count of ICE failures by stream and reason.", Help: "Count of ICE failures by stream and reason.",
ConstLabels: cl, ConstLabels: cl,
}, []string{"stream_id", "reason"}), }, []string{"stream_id", "reason"}),
codecMismatches: f.NewCounterVec(prometheus.CounterOpts{
codecMismatches: mustRegisterCounter(reg, prometheus.CounterOpts{
Name: "dragonfork_webrtc_codec_mismatches_total", Name: "dragonfork_webrtc_codec_mismatches_total",
Help: "Count of 406 codec-mismatch rejections by stream and codec kind.", Help: "Count of 406 codec-mismatch rejections by stream and codec kind.",
ConstLabels: cl, ConstLabels: cl,
}, []string{"stream_id", "kind"}), }, []string{"stream_id", "kind"}),
capRejections: f.NewCounterVec(prometheus.CounterOpts{
capRejections: mustRegisterCounter(reg, prometheus.CounterOpts{
Name: "dragonfork_webrtc_cap_rejections_total", Name: "dragonfork_webrtc_cap_rejections_total",
Help: "Count of 503 peer-cap rejections by stream and scope (global or stream).", Help: "Count of 503 peer-cap rejections by stream and scope (global or stream).",
ConstLabels: cl, ConstLabels: cl,
}, []string{"stream_id", "scope"}), }, []string{"stream_id", "scope"}),
ffmpegLegFailures: f.NewCounterVec(prometheus.CounterOpts{
ffmpegLegFailures: mustRegisterCounter(reg, prometheus.CounterOpts{
Name: "dragonfork_webrtc_ffmpeg_leg_failures_total", Name: "dragonfork_webrtc_ffmpeg_leg_failures_total",
Help: "Count of FFmpeg RTP output leg failures (process stopped while peers were active).", Help: "Count of FFmpeg RTP output leg failures (process stopped while peers were active).",
ConstLabels: cl, ConstLabels: cl,
@ -105,6 +124,6 @@ func (h *Handler) trackICE(streamID string, peer *corewebrtc.Peer, t0 time.Time)
case <-peer.Done(): case <-peer.Done():
dur := time.Since(t0) dur := time.Since(t0)
h.met.iceEstablishment.WithLabelValues(streamID, "failed").Observe(dur.Seconds()) h.met.iceEstablishment.WithLabelValues(streamID, "failed").Observe(dur.Seconds())
h.met.iceFailures.WithLabelValues(streamID, "failed").Inc() h.met.iceFailures.WithLabelValues(streamID, "reason").Inc()
} }
} }