mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
context propagation: pkg/database/{lock,decision} (#3251)
* context propagation: pkg/database/lock * QueryAllDecisionsWithFilters(ctx...), QueryExpiredDecisionsWithFilters(ctx...) * more Query...Decision...(ctx..) * rest of decisions * lint
This commit is contained in:
parent
4a2a663227
commit
1133afe58d
6 changed files with 133 additions and 100 deletions
|
@ -2,6 +2,7 @@ package exprhelpers
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -592,7 +593,10 @@ func GetDecisionsCount(params ...any) (any, error) {
|
|||
return 0, nil
|
||||
|
||||
}
|
||||
count, err := dbClient.CountDecisionsByValue(value)
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
count, err := dbClient.CountDecisionsByValue(ctx, value)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get decisions count from value '%s'", value)
|
||||
return 0, nil //nolint:nilerr // This helper did not return an error before the move to expr.Function, we keep this behavior for backward compatibility
|
||||
|
@ -613,8 +617,11 @@ func GetDecisionsSinceCount(params ...any) (any, error) {
|
|||
log.Errorf("Failed to parse since parameter '%s' : %s", since, err)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
sinceTime := time.Now().UTC().Add(-sinceDuration)
|
||||
count, err := dbClient.CountDecisionsSinceByValue(value, sinceTime)
|
||||
|
||||
count, err := dbClient.CountDecisionsSinceByValue(ctx, value, sinceTime)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get decisions count from value '%s'", value)
|
||||
return 0, nil //nolint:nilerr // This helper did not return an error before the move to expr.Function, we keep this behavior for backward compatibility
|
||||
|
@ -628,7 +635,8 @@ func GetActiveDecisionsCount(params ...any) (any, error) {
|
|||
log.Error("No database config to call GetActiveDecisionsCount()")
|
||||
return 0, nil
|
||||
}
|
||||
count, err := dbClient.CountActiveDecisionsByValue(value)
|
||||
ctx := context.TODO()
|
||||
count, err := dbClient.CountActiveDecisionsByValue(ctx, value)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get active decisions count from value '%s'", value)
|
||||
return 0, err
|
||||
|
@ -642,7 +650,8 @@ func GetActiveDecisionsTimeLeft(params ...any) (any, error) {
|
|||
log.Error("No database config to call GetActiveDecisionsTimeLeft()")
|
||||
return 0, nil
|
||||
}
|
||||
timeLeft, err := dbClient.GetActiveDecisionsTimeLeftByValue(value)
|
||||
ctx := context.TODO()
|
||||
timeLeft, err := dbClient.GetActiveDecisionsTimeLeftByValue(ctx, value)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get active decisions time left from value '%s'", value)
|
||||
return 0, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue