Skip to content

Commit

Permalink
Also compute average and percentiles async
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-timcu committed Jan 8, 2025
1 parent 5c92a20 commit 177bb40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/request-processor/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,19 @@ func OnAttackDetected(attackDetected *protos.AttackDetected) {
log.Debugf("Attack detected event sent via socket")
}

func OnMonitoredSinkStats(sink string, attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total int32, averageInMs float64, percentiles map[string]float64) {
func OnMonitoredSinkStats(sink string, attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total int32, timings []int64) {
if client == nil {
return
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

averageInMs := utils.ComputeAverage(timings)
percentiles := utils.ComputePercentiles(timings)

log.Debugf("Got stats for sink \"%s\": attacksDetected = %d, attacksBlocked = %d, interceptorThrewError = %d, withoutContext = %d, total = %d, averageInMs = %f, percentiles = %v", sink, attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total, averageInMs, percentiles)

_, err := client.OnMonitoredSinkStats(ctx, &protos.MonitoredSinkStats{Sink: sink, AttacksDetected: attacksDetected,
InterceptorThrewError: interceptorThrewError, WithoutContext: withoutContext, Total: total,
CompressedTiming: &protos.CompressedTiming{
Expand Down
9 changes: 3 additions & 6 deletions lib/request-processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,9 @@ func RequestProcessorGetBlockingMode() int {

//export RequestProcessorReportStats
func RequestProcessorReportStats(sink string, attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total int32, timings []int64) {
averageInMs := utils.ComputeAverage(timings)
percentiles := utils.ComputePercentiles(timings)

log.Debugf("Got stats for sink \"%s\": attacksDetected = %d, attacksBlocked = %d, interceptorThrewError = %d, withoutContext = %d, total = %d, averageInMs = %f, percentiles = %v", sink, attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total, averageInMs, percentiles)

go grpc.OnMonitoredSinkStats(strings.Clone(sink), attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total, averageInMs, percentiles)
clonedTimings := make([]int64, len(timings))
copy(clonedTimings, timings)
go grpc.OnMonitoredSinkStats(strings.Clone(sink), attacksDetected, attacksBlocked, interceptorThrewError, withoutContext, total, clonedTimings)
}

//export RequestProcessorUninit
Expand Down

0 comments on commit 177bb40

Please sign in to comment.