Skip to content

Commit 6927e58

Browse files
committed
Make engine health metrics granular on chunk and result
Some metrics were emitting multiple times per chunk or result, so this adds logic to track it on a per chunk and result basis. This will help us describe the percentage of items getting filtered out in each stage.
1 parent 3cbcd39 commit 6927e58

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎pkg/engine/engine.go‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,13 @@ func (e *Engine) scannerWorker(ctx context.Context) {
869869
chunk.OriginalData = chunk.Data
870870
decoded := iterativeDecode(chunk, e.decoders, e.maxDecodeDepth)
871871

872+
anyMatched := false
872873
for _, d := range decoded {
873874
matchingDetectors := e.AhoCorasickCore.FindDetectorMatches(d.Data)
874875
if len(matchingDetectors) == 0 {
875-
chunksDropped.WithLabelValues("scanner", "no_matching_detectors", sourceTypeStr).Inc()
876876
continue
877877
}
878+
anyMatched = true
878879
if len(matchingDetectors) > 1 && !e.verificationOverlap {
879880
wgVerificationOverlap.Add(1)
880881
e.verificationOverlapChunksChan <- verificationOverlapChunk{
@@ -897,6 +898,9 @@ func (e *Engine) scannerWorker(ctx context.Context) {
897898
}
898899
}
899900
}
901+
if !anyMatched {
902+
chunksDropped.WithLabelValues("scanner", "no_matching_detectors", sourceTypeStr).Inc()
903+
}
900904

901905
dataSize := float64(len(chunk.Data))
902906

@@ -1012,6 +1016,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
10121016
for chunk := range e.verificationOverlapChunksChan {
10131017
sourceTypeStr := chunk.chunk.SourceType.String()
10141018
chunksEnteredStage.WithLabelValues("verification_overlap", sourceTypeStr).Inc()
1019+
hadDetectorError := false
10151020
for _, detector := range chunk.detectors {
10161021
isFalsePositive := detectors.GetFalsePositiveCheck(detector.Detector)
10171022
detectorNameStr := detector.Key.Type().String()
@@ -1027,7 +1032,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
10271032
err, "error finding results in chunk during verification overlap",
10281033
"detector", detectorNameStr,
10291034
)
1030-
chunksDropped.WithLabelValues("verification_overlap", "detector_error", sourceTypeStr).Inc()
1035+
hadDetectorError = true
10311036
}
10321037

10331038
if len(results) == 0 {
@@ -1109,6 +1114,10 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) {
11091114
delete(detectorKeysWithResults, k)
11101115
}
11111116

1117+
if hadDetectorError {
1118+
chunksDropped.WithLabelValues("verification_overlap", "detector_error", sourceTypeStr).Inc()
1119+
}
1120+
11121121
chunk.verificationOverlapWgDoneFn()
11131122
}
11141123

@@ -1146,6 +1155,7 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
11461155
isFalsePositive := detectors.GetFalsePositiveCheck(data.detector.Detector)
11471156

11481157
var matchCount int
1158+
hadDetectorError := false
11491159
// To reduce the overhead of regex calls in the detector,
11501160
// we limit the amount of data passed to each detector.
11511161
// The matches field of the DetectorMatch struct contains the
@@ -1170,7 +1180,7 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
11701180
cancel()
11711181
if err != nil {
11721182
ctx.Logger().Error(err, "error finding results in chunk")
1173-
chunksDropped.WithLabelValues("detect", "detector_error", sourceTypeStr).Inc()
1183+
hadDetectorError = true
11741184
continue
11751185
}
11761186

@@ -1220,6 +1230,10 @@ func (e *Engine) detectChunk(ctx context.Context, data detectableChunk) {
12201230

12211231
matchesPerChunk.Observe(float64(matchCount))
12221232

1233+
if hadDetectorError {
1234+
chunksDropped.WithLabelValues("detect", "detector_error", sourceTypeStr).Inc()
1235+
}
1236+
12231237
ctx.Logger().V(5).Info("Finished detecting chunk")
12241238

12251239
data.wgDoneFn()

‎pkg/engine/metrics.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var (
119119
Namespace: common.MetricsNamespace,
120120
Subsystem: common.MetricsSubsystem,
121121
Name: "chunks_dropped_total",
122-
Help: "Total number of chunks dropped by pipeline stage and reason.",
122+
Help: "Total number of chunks (or per-detector work items) dropped by pipeline stage and reason. Counted at the same granularity as chunks_entered_stage_total for the same stage.",
123123
},
124124
[]string{"stage", "reason", "source_type"},
125125
)

0 commit comments

Comments
 (0)