Quellcode durchsuchen

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

he2ss vor 1 Jahr
Ursprung
Commit
ec59302a8e
2 geänderte Dateien mit 0 neuen und 30 gelöschten Zeilen
  1. 0 15
      pkg/apiserver/apic_metrics.go
  2. 0 15
      pkg/database/lock.go

+ 0 - 15
pkg/apiserver/apic_metrics.go

@@ -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()

+ 0 - 15
pkg/database/lock.go

@@ -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)