Fix upstream gauge metric

It wasn't decremented on error. While at it, increment it when
connecting to the upstream network.
This commit is contained in:
Simon Ser 2021-12-02 11:03:56 +01:00
parent 73287f242e
commit d11216917b

View File

@ -202,10 +202,13 @@ func (net *network) run() {
}
lastTry = time.Now()
net.user.srv.metrics.upstreams.Add(1)
uc, err := connectToUpstream(context.TODO(), net)
if err != nil {
net.logger.Printf("failed to connect to upstream server %q: %v", net.Addr, err)
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to connect: %v", err)}
net.user.srv.metrics.upstreams.Add(-1)
continue
}
@ -213,8 +216,6 @@ func (net *network) run() {
net.user.srv.Identd.Store(uc.RemoteAddr().String(), uc.LocalAddr().String(), userIdent(&net.user.User))
}
net.user.srv.metrics.upstreams.Add(1)
uc.register()
if err := uc.runUntilRegistered(); err != nil {
text := err.Error()
@ -224,6 +225,7 @@ func (net *network) run() {
uc.logger.Printf("failed to register: %v", text)
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", text)}
uc.Close()
net.user.srv.metrics.upstreams.Add(-1)
continue
}