mirror of
https://github.com/mjl-/mox.git
synced 2025-06-27 21:48:16 +03:00

We normally recover from those situations, printing stack traces instead of crashing the program. But during tests, we're not looking at the prometheus metrics or all the output. Without these checks, such panics could go unnoticed. Seems like a reasonable thing to add, unhandled panics haven't been encountered in tests.
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package metrics
|
|
|
|
import (
|
|
"sync/atomic"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var metricPanic = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "mox_panic_total",
|
|
Help: "Number of unhandled panics, by package.",
|
|
},
|
|
[]string{
|
|
"pkg",
|
|
},
|
|
)
|
|
|
|
type Panic string
|
|
|
|
const (
|
|
Ctl Panic = "ctl"
|
|
Import Panic = "import"
|
|
Serve Panic = "serve"
|
|
Imapserver Panic = "imapserver"
|
|
Dmarcdb Panic = "dmarcdb"
|
|
Mtastsdb Panic = "mtastsdb"
|
|
Queue Panic = "queue"
|
|
Smtpclient Panic = "smtpclient"
|
|
Smtpserver Panic = "smtpserver"
|
|
Tlsrptdb Panic = "tlsrptdb"
|
|
Dkimverify Panic = "dkimverify"
|
|
Spfverify Panic = "spfverify"
|
|
Upgradethreads Panic = "upgradethreads"
|
|
Importmanage Panic = "importmanage"
|
|
Importmessages Panic = "importmessages"
|
|
Store Panic = "store"
|
|
Webadmin Panic = "webadmin"
|
|
Webapi Panic = "webapi"
|
|
Webmailsendevent Panic = "webmailsendevent"
|
|
Webmail Panic = "webmail"
|
|
Webmailrequest Panic = "webmailrequest"
|
|
Webmailquery Panic = "webmailquery"
|
|
Webmailhandle Panic = "webmailhandle"
|
|
)
|
|
|
|
func init() {
|
|
// Ensure the panic counts are initialized to 0, so the query for change also picks
|
|
// up the first panic.
|
|
names := []Panic{
|
|
Ctl,
|
|
Import,
|
|
Serve,
|
|
Imapserver,
|
|
Mtastsdb,
|
|
Queue,
|
|
Smtpclient,
|
|
Smtpserver,
|
|
Dkimverify,
|
|
Spfverify,
|
|
Upgradethreads,
|
|
Importmanage,
|
|
Importmessages,
|
|
Webadmin,
|
|
Webmailsendevent,
|
|
Webmail,
|
|
Webmailrequest,
|
|
Webmailquery,
|
|
Webmailhandle,
|
|
}
|
|
for _, name := range names {
|
|
metricPanic.WithLabelValues(string(name)).Add(0)
|
|
}
|
|
}
|
|
|
|
var Panics atomic.Int64
|
|
|
|
func PanicInc(name Panic) {
|
|
Panics.Add(1)
|
|
metricPanic.WithLabelValues(string(name)).Inc()
|
|
}
|