Skip to content

Commit

Permalink
Reduce cardinality of invite error metric. (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Dec 29, 2023
1 parent bb81f38 commit d6393c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
Expand Down

0 comments on commit d6393c3

Please sign in to comment.