Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/extension/jaeger_remote_sampling/internal/jaegerremotesampling/config.go
4096 views
1
// Copyright The OpenTelemetry Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
package jaegerremotesampling
16
17
import (
18
"errors"
19
"time"
20
21
"go.opentelemetry.io/collector/config"
22
"go.opentelemetry.io/collector/config/configgrpc"
23
"go.opentelemetry.io/collector/config/confighttp"
24
)
25
26
var (
27
errTooManySources = errors.New("too many sources specified, has to be either 'file' or 'remote'")
28
errNoSources = errors.New("no sources specified, has to be either 'file' or 'remote'")
29
errAtLeastOneProtocol = errors.New("no protocols selected to serve the strategies, use 'grpc', 'http', or both")
30
)
31
32
// Config has the configuration for the extension enabling the health check
33
// extension, used to report the health status of the service.
34
type Config struct {
35
config.ExtensionSettings `mapstructure:",squash"`
36
*confighttp.HTTPServerSettings `mapstructure:"http"`
37
*configgrpc.GRPCServerSettings `mapstructure:"grpc"`
38
39
// Source configures the source for the strategies file. One of `remote` or `file` has to be specified.
40
Source Source `mapstructure:"source"`
41
}
42
43
type Source struct {
44
// Remote defines the remote location for the file
45
Remote *configgrpc.GRPCClientSettings `mapstructure:"remote"`
46
47
// File specifies a local file as the strategies source
48
File string `mapstructure:"file"`
49
50
// ReloadInterval determines the periodicity to refresh the strategies
51
ReloadInterval time.Duration `mapstructure:"reload_interval"`
52
53
// Contents is a field added for the Grafana Agent that allows dynamic mapping of sampling rules
54
// through flow
55
Contents string `mapstructure:"contents"`
56
}
57
58
var _ config.Extension = (*Config)(nil)
59
60
// Validate checks if the extension configuration is valid
61
func (cfg *Config) Validate() error {
62
if cfg.HTTPServerSettings == nil && cfg.GRPCServerSettings == nil {
63
return errAtLeastOneProtocol
64
}
65
66
if cfg.Source.File != "" && cfg.Source.Remote != nil {
67
return errTooManySources
68
}
69
70
if cfg.Source.File == "" && cfg.Source.Remote == nil {
71
return errNoSources
72
}
73
74
return nil
75
}
76
77