/
config.go
51 lines (44 loc) · 1.66 KB
/
config.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package scraperhelper // import "go.opentelemetry.io/collector/receiver/scraperhelper"
import (
"errors"
"fmt"
"time"
"go.uber.org/multierr"
)
var (
errNonPositiveInterval = errors.New("requires positive value")
)
// ControllerConfig defines common settings for a scraper controller
// configuration. Scraper controller receivers can embed this struct, instead
// of receiver.Settings, and extend it with more fields if needed.
type ControllerConfig 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 `mapstructure:"collection_interval"`
// InitialDelay sets the initial start delay for the scraper,
// any non positive value is assumed to be immediately.
InitialDelay time.Duration `mapstructure:"initial_delay"`
// Timeout is an optional value used to set scraper's context deadline.
Timeout time.Duration `mapstructure:"timeout"`
}
// NewDefaultControllerConfig returns default scraper controller
// settings with a collection interval of one minute.
func NewDefaultControllerConfig() ControllerConfig {
return ControllerConfig{
CollectionInterval: time.Minute,
InitialDelay: time.Second,
Timeout: 0,
}
}
func (set *ControllerConfig) Validate() (errs error) {
if set.CollectionInterval <= 0 {
errs = multierr.Append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval))
}
if set.Timeout < 0 {
errs = multierr.Append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval))
}
return errs
}