From d6393c3381701e01a2bef26c8d197fcecef9e8b2 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Fri, 29 Dec 2023 17:59:39 +0200 Subject: [PATCH] Reduce cardinality of invite error metric. (#40) --- pkg/sip/inbound.go | 4 ++-- pkg/stats/monitor.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/sip/inbound.go b/pkg/sip/inbound.go index 499be86a..254d03dd 100644 --- a/pkg/sip/inbound.go +++ b/pkg/sip/inbound.go @@ -126,14 +126,14 @@ func (s *Server) onInvite(req *sip.Request, tx sip.ServerTransaction) { username, password, err := s.authHandler(from.Address.User, to.Address.User, to.Address.Host, src) if err != nil { - cmon.InviteError("no-rule") + cmon.InviteErrorShort("no-rule") logger.Warnw("Rejecting inbound, doesn't match any Trunks", err, "tag", tag, "src", src, "from", from, "to", to, "to-host", to.Address.Host) sipErrorResponse(tx, req) return } if !s.handleInviteAuth(req, tx, from.Address.User, username, password) { - cmon.InviteError("unauthorized") + cmon.InviteErrorShort("unauthorized") // handleInviteAuth will generate the SIP Response as needed return } diff --git a/pkg/stats/monitor.go b/pkg/stats/monitor.go index 1f0f40f3..87feb8f4 100644 --- a/pkg/stats/monitor.go +++ b/pkg/stats/monitor.go @@ -45,6 +45,7 @@ type Monitor struct { inviteReqRaw prometheus.Counter inviteReq *prometheus.CounterVec inviteAccept *prometheus.CounterVec + inviteErrShort *prometheus.CounterVec inviteErr *prometheus.CounterVec callsActive *prometheus.GaugeVec callsTerminated *prometheus.CounterVec @@ -96,6 +97,13 @@ func (m *Monitor) Start(conf *config.Config) error { Help: "Number of rejected SIP INVITE requests", ConstLabels: prometheus.Labels{"node_id": conf.NodeID}, }, []string{"dir", "from", "to", "reason"}) + m.inviteErrShort = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: "livekit", + Subsystem: "sip", + Name: "invite_error", + Help: "Number of rejected SIP INVITE requests", + ConstLabels: prometheus.Labels{"node_id": conf.NodeID}, + }, []string{"dir", "reason"}) m.callsActive = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "livekit", @@ -202,6 +210,14 @@ type CallMonitor struct { from, to string } +func (c *CallMonitor) labelsShort(l prometheus.Labels) prometheus.Labels { + out := prometheus.Labels{"dir": c.dir.String()} + for k, v := range l { + out[k] = v + } + return out +} + func (c *CallMonitor) labels(l prometheus.Labels) prometheus.Labels { out := prometheus.Labels{"dir": c.dir.String(), "from": c.from, "to": c.to} for k, v := range l { @@ -218,6 +234,10 @@ func (c *CallMonitor) InviteAccept() { c.m.inviteAccept.With(c.labels(nil)).Inc() } +func (c *CallMonitor) InviteErrorShort(reason string) { + c.m.inviteErrShort.With(c.labelsShort(prometheus.Labels{"reason": reason})).Inc() +} + func (c *CallMonitor) InviteError(reason string) { c.m.inviteErr.With(c.labels(prometheus.Labels{"reason": reason})).Inc() }