/
config.go
54 lines (44 loc) · 1.52 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
52
53
54
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package chronyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/chronyreceiver"
import (
"errors"
"fmt"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/chronyreceiver/internal/chrony"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/chronyreceiver/internal/metadata"
)
type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
metadata.MetricsBuilderConfig `mapstructure:",squash"`
// Endpoint is the published address or unix socket
// that allows clients to connect to:
// The allowed format is:
// unix:///path/to/chronyd/unix.sock
// udp://localhost:323
//
// The default value is unix:///var/run/chrony/chronyd.sock
Endpoint string `mapstructure:"endpoint"`
}
var (
_ component.Config = (*Config)(nil)
errInvalidValue = errors.New("invalid value")
)
func newDefaultCongfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
cfg.Timeout = 10 * time.Second
return &Config{
ControllerConfig: cfg,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Endpoint: "unix:///var/run/chrony/chronyd.sock",
}
}
func (c *Config) Validate() error {
if c.Timeout < 1 {
return fmt.Errorf("must have a positive timeout: %w", errInvalidValue)
}
_, _, err := chrony.SplitNetworkEndpoint(c.Endpoint)
return err
}