Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
use conn.Close() to remove closed connections from tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jul 15, 2021
1 parent 544cba2 commit 4fe8055
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions metrics.go
Expand Up @@ -123,7 +123,6 @@ func (c *aggregatingCollector) cron() {
info, err := conn.getTCPInfo()
if err != nil {
if strings.Contains(err.Error(), "use of closed network connection") {
c.closedConn(conn)
continue
}
log.Errorf("Failed to get TCP info: %s", err)
Expand All @@ -139,9 +138,6 @@ func (c *aggregatingCollector) cron() {
}
c.rtts.Observe(info.RTT.Seconds())
c.connDurations.Observe(now.Sub(conn.startTime).Seconds())
if info.State == tcpinfo.Closed {
c.closedConn(conn)
}
}
c.mutex.Unlock()
}
Expand Down Expand Up @@ -183,9 +179,11 @@ func (c *aggregatingCollector) Collect(metrics chan<- prometheus.Metric) {
}
}

func (c *aggregatingCollector) closedConn(conn *tracingConn) {
func (c *aggregatingCollector) ClosedConn(conn *tracingConn, direction string) {
c.mutex.Lock()
collector.removeConn(conn.id)
closedConns.WithLabelValues(conn.getDirection()).Inc()
c.mutex.Unlock()
closedConns.WithLabelValues(direction).Inc()
}

type tracingConn struct {
Expand Down Expand Up @@ -222,6 +220,7 @@ func (c *tracingConn) getDirection() string {
}

func (c *tracingConn) Close() error {
collector.ClosedConn(c, c.getDirection())
return c.Conn.Close()
}

Expand Down

0 comments on commit 4fe8055

Please sign in to comment.