forked from SumoLogic/sumologic-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessor.go
40 lines (32 loc) · 1.02 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package metricfrequencyprocessor
import (
"context"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/processor/processorhelper"
)
type metricsfrequencyprocessor struct {
sieve metricSieve
}
var _ processorhelper.ProcessMetricsFunc = (*metricsfrequencyprocessor)(nil).ProcessMetrics
// ProcessMetrics applies metricSieve to incoming metrics. It mutates the argument.
func (mfp *metricsfrequencyprocessor) ProcessMetrics(_ context.Context, md pmetric.Metrics) (pmetric.Metrics, error) {
rms := md.ResourceMetrics()
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)
sms := rm.ScopeMetrics()
for j := 0; j < sms.Len(); j++ {
ilm := sms.At(j)
metrics := ilm.Metrics()
metrics.RemoveIf(mfp.sieve.Sift)
}
sms.RemoveIf(metricSliceEmpty)
}
rms.RemoveIf(ilmSliceEmpty)
return md, nil
}
func metricSliceEmpty(metrics pmetric.ScopeMetrics) bool {
return metrics.Metrics().Len() == 0
}
func ilmSliceEmpty(metrics pmetric.ResourceMetrics) bool {
return metrics.ScopeMetrics().Len() == 0
}