/
factory.go
77 lines (62 loc) · 2.15 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package groupbytraceprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbytraceprocessor"
import (
"context"
"fmt"
"time"
"go.opencensus.io/stats/view"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbytraceprocessor/internal/metadata"
)
const (
defaultWaitDuration = time.Second
defaultNumTraces = 1_000_000
defaultNumWorkers = 1
defaultDiscardOrphans = false
defaultStoreOnDisk = false
)
var (
errDiskStorageNotSupported = fmt.Errorf("option 'disk storage' not supported in this release")
errDiscardOrphansNotSupported = fmt.Errorf("option 'discard orphans' not supported in this release")
)
// NewFactory returns a new factory for the Filter processor.
func NewFactory() processor.Factory {
// TODO: find a more appropriate way to get this done, as we are swallowing the error here
_ = view.Register(metricViews()...)
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, metadata.TracesStability))
}
// createDefaultConfig creates the default configuration for the processor.
func createDefaultConfig() component.Config {
return &Config{
NumTraces: defaultNumTraces,
NumWorkers: defaultNumWorkers,
WaitDuration: defaultWaitDuration,
// not supported for now
DiscardOrphans: defaultDiscardOrphans,
StoreOnDisk: defaultStoreOnDisk,
}
}
// createTracesProcessor creates a trace processor based on this config.
func createTracesProcessor(
_ context.Context,
params processor.CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces) (processor.Traces, error) {
oCfg := cfg.(*Config)
var st storage
if oCfg.StoreOnDisk {
return nil, errDiskStorageNotSupported
}
if oCfg.DiscardOrphans {
return nil, errDiscardOrphansNotSupported
}
// the only supported storage for now
st = newMemoryStorage()
return newGroupByTraceProcessor(params.Logger, st, nextConsumer, *oCfg), nil
}