-
Notifications
You must be signed in to change notification settings - Fork 2
/
factory.go
57 lines (46 loc) · 1.36 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
package icmpcheckreceiver
import (
"context"
"errors"
"github.com/thmshmm/icmpcheckreceiver/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,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
)
}
func createDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
return &Config{
ControllerConfig: cfg,
Targets: []Target{},
}
}
func createMetricsReceiver(
ctx context.Context,
set receiver.Settings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
receiverCfg, ok := cfg.(*Config)
if !ok {
return nil, errors.New("config is not a valid icmpping receiver config")
}
opts := []scraperhelper.ScraperControllerOption{}
icmpScraper, err := newScraper(set.Logger, receiverCfg.Targets)
if err != nil {
return nil, err
}
scraper, err := scraperhelper.NewScraper(metadata.Type, icmpScraper.Scrape)
if err != nil {
return nil, err
}
opts = append(opts, scraperhelper.AddScraper(scraper))
return scraperhelper.NewScraperControllerReceiver(&receiverCfg.ControllerConfig, set, nextConsumer, opts...)
}