-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.go
91 lines (79 loc) · 3.51 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package servicegraphprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/servicegraphprocessor"
import (
"context"
"time"
"go.opencensus.io/stats/view"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/processor"
)
const (
// The value of "type" key in configuration.
typeStr = "servicegraph"
// The stability level of the processor.
connectorStability = component.StabilityLevelDevelopment
virtualNodeFeatureGateID = "processor.servicegraph.virtualNode"
legacyLatencyMetricNamesFeatureGateID = "processor.servicegraph.legacyLatencyMetricNames"
)
var virtualNodeFeatureGate, legacyMetricNamesFeatureGate *featuregate.Gate
func init() {
virtualNodeFeatureGate = featuregate.GlobalRegistry().MustRegister(
virtualNodeFeatureGateID,
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, when the edge expires, processor checks if it has peer attributes(`db.name, net.sock.peer.addr, net.peer.name, rpc.service, http.url, http.target`), and then aggregate the metrics with virtual node."),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/17196"),
)
// TODO: Remove this feature gate when the legacy metric names are removed.
legacyMetricNamesFeatureGate = featuregate.GlobalRegistry().MustRegister(
legacyLatencyMetricNamesFeatureGateID,
featuregate.StageAlpha, // Alpha because we want it disabled by default.
featuregate.WithRegisterDescription("When enabled, processor uses legacy latency metric names."),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18743,https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16578"),
)
}
// NewFactory creates a factory for the servicegraph processor.
func NewFactory() processor.Factory {
// TODO: Handle this err
_ = view.Register(serviceGraphProcessorViews()...)
return processor.NewFactory(
typeStr,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, connectorStability),
)
}
// NewConnectorFactoryFunc creates a function that returns a factory for the servicegraph connector.
func NewConnectorFactoryFunc(cfgType component.Type, tracesToMetricsStability component.StabilityLevel) func() connector.Factory {
return func() connector.Factory {
// TODO: Handle this err
_ = view.Register(serviceGraphProcessorViews()...)
return connector.NewFactory(
cfgType,
createDefaultConfig,
connector.WithTracesToMetrics(createTracesToMetricsConnector, tracesToMetricsStability),
)
}
}
func createDefaultConfig() component.Config {
return &Config{
Store: StoreConfig{
TTL: 2 * time.Second,
MaxItems: 1000,
},
CacheLoop: time.Minute,
StoreExpirationLoop: 2 * time.Second,
}
}
func createTracesProcessor(_ context.Context, params processor.CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (processor.Traces, error) {
p := newProcessor(params.Logger, cfg)
p.tracesConsumer = nextConsumer
return p, nil
}
func createTracesToMetricsConnector(_ context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (connector.Traces, error) {
c := newProcessor(params.Logger, cfg)
c.metricsConsumer = nextConsumer
return c, nil
}