-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.go
More file actions
77 lines (66 loc) · 2.15 KB
/
Copy pathfactory.go
File metadata and controls
77 lines (66 loc) · 2.15 KB
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
package incusattrprocessor
import (
"context"
"fmt"
"time"
"github.com/bmarinov/incusattrprocessor/internal/incus"
"github.com/bmarinov/incusattrprocessor/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/xconsumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper/xprocessorhelper"
"go.opentelemetry.io/collector/processor/xprocessor"
)
// typeStr defines the unique type identifier for the processor.
var typeStr = component.MustNewType("incusattr")
const defaultProcRoot = "/proc"
func NewFactory() processor.Factory {
return xprocessor.NewFactory(
typeStr,
createDefaultConfig,
xprocessor.WithProfiles(createProfilesProcessor, component.StabilityLevelAlpha),
)
}
func createProfilesProcessor(
ctx context.Context,
params processor.Settings,
cfg component.Config,
nextProfilesConsumer xconsumer.Profiles,
) (xprocessor.Profiles, error) {
pConfig := cfg.(*processorConfig)
var incusClient *incus.Client
if pConfig.Connection.HTTPS != nil {
httpsCfg, err := pConfig.Connection.HTTPS.load()
if err != nil {
return nil, fmt.Errorf("loading HTTPS config: %w", err)
}
incusClient = incus.NewHTTPS(httpsCfg, params.Logger, 3, time.Second)
} else {
incusClient = incus.New(pConfig.Connection.SocketPath, params.Logger, 3, time.Second)
}
cache := metadata.NewCache(
incusClient,
incusClient,
func(ctx context.Context) ([]incus.InstanceInfo, error) {
return incusClient.GetAllInstances(ctx)
},
params.Logger,
)
lookup := metadata.NewSource(cache, defaultProcRoot)
p := newIncusAttrProcessor(params, pConfig, lookup, func(ctx context.Context) error {
err := incusClient.Start(ctx)
if err != nil {
return err
}
return cache.Start(ctx)
})
consumerCapabilities := consumer.Capabilities{MutatesData: true}
processor, err := xprocessorhelper.NewProfiles(ctx, params, cfg, nextProfilesConsumer,
p.processProfiles,
xprocessorhelper.WithCapabilities(consumerCapabilities),
xprocessorhelper.WithStart(p.startup),
xprocessorhelper.WithShutdown(p.shutdown),
)
return processor, err
}