Commit 221326bc authored by Tulir Asokan's avatar Tulir Asokan 🐈

Add metric for users locked in post-login sync

parent bf5be3fe
Pipeline #1784 passed with stages
in 1 minute and 19 seconds
......@@ -55,10 +55,12 @@ type MetricsHandler struct {
unencryptedGroupCount prometheus.Gauge
unencryptedPrivateCount prometheus.Gauge
connected prometheus.Gauge
connectedState map[types.WhatsAppID]bool
loggedIn prometheus.Gauge
loggedInState map[types.WhatsAppID]bool
connected prometheus.Gauge
connectedState map[types.WhatsAppID]bool
loggedIn prometheus.Gauge
loggedInState map[types.WhatsAppID]bool
syncLocked prometheus.Gauge
syncLockedState map[types.WhatsAppID]bool
}
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
......@@ -112,6 +114,11 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
Help: "Bridge users connected to WhatsApp",
}),
connectedState: make(map[types.WhatsAppID]bool),
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
Name: "bridge_sync_locked",
Help: "Bridge users locked in post-login sync",
}),
syncLockedState: make(map[types.WhatsAppID]bool),
}
}
......@@ -167,6 +174,21 @@ func (mh *MetricsHandler) TrackConnectionState(jid types.WhatsAppID, connected b
}
}
func (mh *MetricsHandler) TrackSyncLock(jid types.WhatsAppID, locked bool) {
if !mh.running {
return
}
currentVal, ok := mh.syncLockedState[jid]
if !ok || currentVal != locked {
mh.syncLockedState[jid] = locked
if locked {
mh.syncLocked.Inc()
} else {
mh.syncLocked.Dec()
}
}
}
func (mh *MetricsHandler) updateStats() {
start := time.Now()
var puppetCount int
......
......@@ -798,7 +798,9 @@ func (user *User) handleMessageLoop() {
user.GetPortalByJID(msg.chat).messages <- msg
case <-user.syncStart:
user.log.Debugln("Processing of incoming messages is locked")
user.bridge.Metrics.TrackSyncLock(user.JID, true)
user.syncWait.Wait()
user.bridge.Metrics.TrackSyncLock(user.JID, false)
user.log.Debugln("Processing of incoming messages unlocked")
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment