remove lock for push metrics: each lapi needs to push metrics for the console view

This commit is contained in:
he2ss 2023-10-05 17:10:51 +02:00
parent 3665e6214f
commit ec59302a8e
2 changed files with 0 additions and 30 deletions

View file

@ -127,16 +127,6 @@ func (a *apic) SendMetrics(stop chan (bool)) {
}
case <-metTicker.C:
metTicker.Stop()
log.Debug("capi metrics: acquiring lock")
err := a.dbClient.AcquirePushMetricsLock()
if a.dbClient.IsLocked(err) {
log.Infof("another instance of crowdsec is already pushing metrics, skipping")
metTicker.Reset(nextMetInt())
return
}
if err != nil {
log.Errorf("unable to acquire pushMetrics lock (%s)", err)
}
metrics, err := a.GetMetrics()
if err != nil {
log.Errorf("unable to get metrics (%s)", err)
@ -149,11 +139,6 @@ func (a *apic) SendMetrics(stop chan (bool)) {
log.Errorf("capi metrics: failed: %s", err)
}
}
log.Debug("capi metrics: releasing lock")
err = a.dbClient.ReleasePushMetricsLock()
if err != nil {
log.Errorf("unable to release metrics lock (%s)", err)
}
metTicker.Reset(nextMetInt())
case <-a.metricsTomb.Dying(): // if one apic routine is dying, do we kill the others?
checkTicker.Stop()

View file

@ -13,11 +13,9 @@ import (
const (
CAPIPullLockTimeout = 120
MetricsLockTimeout = 30
)
func (c *Client) AcquireLock(name string) error {
// pessimistic lock
_, err := c.Ent.Lock.Create().
SetName(name).
SetCreatedAt(types.UtcNow()).
@ -55,19 +53,6 @@ func (c *Client) IsLocked(err error) bool {
return ent.IsConstraintError(err)
}
func (c *Client) AcquirePushMetricsLock() error {
lockName := "pushMetrics"
err := c.ReleaseLockWithTimeout(lockName, MetricsLockTimeout)
if err != nil {
log.Errorf("unable to release pushMetrics lock: %s", err)
}
return c.AcquireLock(lockName)
}
func (c *Client) ReleasePushMetricsLock() error {
return c.ReleaseLock("pushMetrics")
}
func (c *Client) AcquirePullCAPILock() error {
lockName := "pullCAPI"
err := c.ReleaseLockWithTimeout(lockName, CAPIPullLockTimeout)