-
Notifications
You must be signed in to change notification settings - Fork 24
/
factory.go
73 lines (66 loc) · 1.92 KB
/
factory.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package metricsprocessor
import (
"context"
"github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"github.com/fluxninja/aperture/v2/pkg/cache"
"github.com/fluxninja/aperture/v2/pkg/policies/flowcontrol/iface"
"github.com/fluxninja/aperture/v2/pkg/policies/flowcontrol/selectors"
)
const (
// The value of "type" key in configuration.
typeStr = "metrics"
)
// NewFactory returns a new factory for the metrics processor.
func NewFactory(
promRegistry *prometheus.Registry,
engine iface.Engine,
clasEng iface.ClassificationEngine,
controlPointCache *cache.Cache[selectors.TypedControlPointID],
) processor.Factory {
return processor.NewFactory(
typeStr,
createDefaultConfig(promRegistry, engine, clasEng, controlPointCache),
processor.WithLogs(createLogsProcessor, component.StabilityLevelDevelopment),
)
}
func createDefaultConfig(
promRegistry *prometheus.Registry,
engine iface.Engine,
clasEng iface.ClassificationEngine,
controlPointCache *cache.Cache[selectors.TypedControlPointID],
) component.CreateDefaultConfigFunc {
return func() component.Config {
return &Config{
promRegistry: promRegistry,
engine: engine,
classificationEngine: clasEng,
controlPointCache: controlPointCache,
}
}
}
func createLogsProcessor(
ctx context.Context,
params processor.CreateSettings,
cfg component.Config,
nextLogsConsumer consumer.Logs,
) (processor.Logs, error) {
cfgTyped := cfg.(*Config)
proc, err := newProcessor(cfgTyped)
if err != nil {
return nil, err
}
return processorhelper.NewLogsProcessor(
ctx,
params,
cfg,
nextLogsConsumer,
proc.ConsumeLogs,
processorhelper.WithCapabilities(proc.Capabilities()),
processorhelper.WithStart(proc.Start),
processorhelper.WithShutdown(proc.Shutdown),
)
}