-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
config.go
59 lines (45 loc) · 1.88 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
55
56
57
58
59
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package jaegerremotesampling // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/jaegerremotesampling"
import (
"errors"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
)
var (
errTooManySources = errors.New("too many sources specified, has to be either 'file' or 'remote'")
errNoSources = errors.New("no sources specified, has to be either 'file' or 'remote'")
errAtLeastOneProtocol = errors.New("no protocols selected to serve the strategies, use 'grpc', 'http', or both")
)
// Config has the configuration for the extension enabling the health check
// extension, used to report the health status of the service.
type Config struct {
HTTPServerConfig *confighttp.ServerConfig `mapstructure:"http"`
GRPCServerConfig *configgrpc.ServerConfig `mapstructure:"grpc"`
// Source configures the source for the strategies file. One of `remote` or `file` has to be specified.
Source Source `mapstructure:"source"`
}
type Source struct {
// Remote defines the remote location for the file
Remote *configgrpc.ClientConfig `mapstructure:"remote"`
// File specifies a local file as the strategies source
File string `mapstructure:"file"`
// ReloadInterval determines the periodicity to refresh the strategies
ReloadInterval time.Duration `mapstructure:"reload_interval"`
}
var _ component.Config = (*Config)(nil)
// Validate checks if the extension configuration is valid
func (cfg *Config) Validate() error {
if cfg.HTTPServerConfig == nil && cfg.GRPCServerConfig == nil {
return errAtLeastOneProtocol
}
if cfg.Source.File != "" && cfg.Source.Remote != nil {
return errTooManySources
}
if cfg.Source.File == "" && cfg.Source.Remote == nil {
return errNoSources
}
return nil
}