-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
49 lines (41 loc) · 1.19 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
package wireguardreceiver
import (
"context"
"time"
"github.com/rogercoll/wireguardreceiver/internal/metadata"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultReceiverConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}
func createDefaultConfig() *Config {
cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
cfg.CollectionInterval = 10 * time.Second
cfg.Timeout = 5 * time.Second
return &Config{
ScraperControllerSettings: cfg,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}
func createDefaultReceiverConfig() component.Config {
return createDefaultConfig()
}
func createMetricsReceiver(
_ context.Context,
params receiver.CreateSettings,
config component.Config,
consumer consumer.Metrics,
) (receiver.Metrics, error) {
wireguardConfig := config.(*Config)
dsr, err := newReceiver(wireguardConfig, params, consumer, nil)
if err != nil {
return nil, err
}
return dsr, nil
}