Skip to content

Commit

Permalink
move registerDeviceMetrics call and delete metric if device is gone
Browse files Browse the repository at this point in the history
  • Loading branch information
DerRockWolf committed May 4, 2024
1 parent c73844b commit 1ee846d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/connections/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ func (s *service) handleHellos(ctx context.Context) error {
// connections are limited.
rd, wr := s.limiter.getLimiters(remoteID, c, c.IsLocal())

registerDeviceMetrics(remoteID.String())

protoConn := protocol.NewConnection(remoteID, rd, wr, c, s.model, c, deviceCfg.Compression, s.cfg.FolderPasswords(remoteID), s.keyGen)
s.accountAddedConnection(protoConn, hello, s.cfg.Options().ConnectionPriorityUpgradeThreshold)
go func() {
Expand Down Expand Up @@ -848,13 +846,15 @@ func (s *service) CommitConfiguration(from, to config.Configuration) bool {
newDevices := make(map[protocol.DeviceID]bool, len(to.Devices))
for _, dev := range to.Devices {
newDevices[dev.DeviceID] = true
registerDeviceMetrics(dev.DeviceID.String())
}

for _, dev := range from.Devices {
if !newDevices[dev.DeviceID] {
warningLimitersMut.Lock()
delete(warningLimiters, dev.DeviceID)
warningLimitersMut.Unlock()
metricDeviceActiveConnections.DeleteLabelValues(dev.DeviceID.String())
}
}

Expand Down

0 comments on commit 1ee846d

Please sign in to comment.