Skip to content

Commit

Permalink
Add status names for metrics. (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Dec 12, 2024
1 parent 4c2cb5d commit c6a3cff
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (c *outboundCall) sipSignal(ctx context.Context) error {
// TODO: should we retry? maybe new offer will work
var e *ErrorStatus
if errors.As(err, &e) {
c.mon.InviteError(fmt.Sprintf("status-%d", e.StatusCode))
c.mon.InviteError(statusName(e.StatusCode))
} else {
c.mon.InviteError("other")
}
Expand Down
64 changes: 64 additions & 0 deletions pkg/sip/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,70 @@ var (
referIdRegexp = regexp.MustCompile(`^refer(;id=(\d+))?$`)
)

// TODO: Add String method to sipgo.StatusCode
var statusNamesMap = map[int]string{
100: "Trying",
180: "Ringing",
181: "CallIsForwarded",
182: "Queued",
183: "SessionInProgress",

200: "OK",
202: "Accepted",

301: "MovedPermanently",
302: "MovedTemporarily",
305: "UseProxy",

400: "BadRequest",
401: "Unauthorized",
402: "PaymentRequired",
403: "Forbidden",
404: "NotFound",
405: "MethodNotAllowed",
406: "NotAcceptable",
407: "ProxyAuthRequired",
408: "RequestTimeout",
409: "Conflict",
410: "Gone",
413: "RequestEntityTooLarge",
414: "RequestURITooLong",
415: "UnsupportedMediaType",
416: "RequestedRangeNotSatisfiable",
420: "BadExtension",
421: "ExtensionRequired",
423: "IntervalToBrief",
480: "TemporarilyUnavailable",
481: "CallTransactionDoesNotExists",
482: "LoopDetected",
483: "TooManyHops",
484: "AddressIncomplete",
485: "Ambiguous",
486: "BusyHere",
487: "RequestTerminated",
488: "NotAcceptableHere",

500: "InternalServerError",
501: "NotImplemented",
502: "BadGateway",
503: "ServiceUnavailable",
504: "GatewayTimeout",
505: "VersionNotSupported",
513: "MessageTooLarge",

600: "GlobalBusyEverywhere",
603: "GlobalDecline",
604: "GlobalDoesNotExistAnywhere",
606: "GlobalNotAcceptable",
}

func statusName(status int) string {
if name := statusNamesMap[status]; name != "" {
return fmt.Sprintf("%d-%s", status, name)
}
return fmt.Sprintf("status-%d", status)
}

type ErrorStatus struct {
StatusCode int
Message string
Expand Down
6 changes: 3 additions & 3 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
var (
// durBucketsOp lists histogram buckets for relatively short operations like SIP INVITE.
durBucketsOp = []float64{
0.1, 0.5, 1, 5, 10, 30, 60, 3 * 60,
0.1, 0.5, 1, 2.5, 5, 10, 20, 30, 60, 3 * 60,
}
// durBucketsLong lists histogram buckets for long operations like call/session durations.
durBucketsLong = []float64{
Expand All @@ -46,9 +46,9 @@ type CallDir bool

func (d CallDir) String() string {
if d == Inbound {
return "inbound"
return "in"
}
return "outbound"
return "out"
}

const (
Expand Down

0 comments on commit c6a3cff

Please sign in to comment.