~emersion/soju

2351fc8b83d34c072958efcafde33305b580501c — Simon Ser 1 year, 1 month ago 64196d5
server: add metric for goroutine panics

This is useful to setup an alert when a panic occurs.
1 files changed, 7 insertions(+), 0 deletions(-)

M server.go
M server.go => server.go +7 -0
@@ 175,6 175,7 @@ type Server struct {
		downstreamInMessagesTotal  prometheus.Counter

		upstreamConnectErrorsTotal prometheus.Counter
		workerPanicsTotal          prometheus.Counter
	}

	webPush *database.WebPushConfig


@@ 282,6 283,11 @@ func (s *Server) registerMetrics() {
		Name: "soju_upstream_connect_errors_total",
		Help: "Total number of upstream connection errors",
	})

	s.metrics.workerPanicsTotal = factory.NewCounter(prometheus.CounterOpts{
		Name: "soju_worker_panics_total",
		Help: "Total number of panics in worker goroutines",
	})
}

func (s *Server) loadWebPushConfig(ctx context.Context) error {


@@ 426,6 432,7 @@ func (s *Server) addUserLocked(user *database.User) *user {
		defer func() {
			if err := recover(); err != nil {
				s.Logger.Printf("panic serving user %q: %v\n%v", user.Username, err, string(debug.Stack()))
				s.metrics.workerPanicsTotal.Inc()
			}

			s.lock.Lock()