-
Notifications
You must be signed in to change notification settings - Fork 90
/
config_controller.go
55 lines (47 loc) · 1.69 KB
/
config_controller.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
package otelcol
import (
"time"
"github.com/grafana/alloy/syntax"
"go.opentelemetry.io/collector/receiver/scraperhelper"
)
// ControllerArguments defines common settings for a scraper controller
// configuration. Scraper controller receivers can squash this struct, instead
// of receiver.Settings, and extend it with more fields if needed.
type ControllerArguments struct {
// CollectionInterval sets how frequently the scraper should be called and
// used as the context timeout to ensure that scrapers don't exceed the
// interval.
CollectionInterval time.Duration `alloy:"collection_interval,attr,optional"`
// InitialDelay sets the initial start delay for the scraper, any non
// positive value is assumed to be immediately.
InitialDelay time.Duration `alloy:"initial_delay,attr,optional"`
// Timeout is an optional value used to set scraper's context deadline.
Timeout time.Duration `alloy:"timeout,attr,optional"`
}
var (
_ syntax.Defaulter = (*ControllerArguments)(nil)
_ syntax.Validator = (*ControllerArguments)(nil)
)
// SetToDefault implements syntax.Defaulter.
func (args *ControllerArguments) SetToDefault() {
*args = ControllerArguments{
CollectionInterval: time.Minute,
InitialDelay: time.Second,
Timeout: 0,
}
}
// Validate implements syntax.Validator.
func (args *ControllerArguments) Validate() error {
return args.Convert().Validate()
}
// Convert converts args to the upstream type.
func (args *ControllerArguments) Convert() *scraperhelper.ControllerConfig {
if args == nil {
return nil
}
return &scraperhelper.ControllerConfig{
CollectionInterval: args.CollectionInterval,
InitialDelay: args.InitialDelay,
Timeout: args.Timeout,
}
}