This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.go
66 lines (53 loc) · 1.79 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
60
61
62
63
64
65
66
package receiver
import (
"context"
"errors"
"time"
"google.golang.org/grpc/metadata"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configgrpc"
"github.com/cilium/hubble-otel/common"
)
type Config struct {
config.ReceiverSettings `mapstructure:",squash"`
configgrpc.GRPCClientSettings `mapstructure:",squash"`
BufferSize int `mapstructure:"buffer_size"`
FlowEncodingOptions FlowEncodingOptions `mapstructure:"flow_encoding_options"`
IncludeFlowTypes IncludeFlowTypes `mapstructure:"include_flow_types"`
FallbackServiceNamePrefix string `mapstructure:"fallback_service_name_prefix"`
TraceCacheWindow time.Duration `mapstructure:"trace_cache_window"`
ParseTraceHeaders bool `mapstructure:"parse_trace_headers"`
}
type FlowEncodingOptions struct {
Traces common.EncodingOptions `mapstructure:"traces"`
Logs common.EncodingOptions `mapstructure:"logs"`
}
type IncludeFlowTypes struct {
Traces common.IncludeFlowTypes `mapstructure:"traces"`
Logs common.IncludeFlowTypes `mapstructure:"logs"`
}
var _ config.Receiver = (*Config)(nil)
func (cfg *Config) Validate() error {
if cfg.Endpoint == "" {
return errors.New("hubble endpoint must be specified")
}
if err := cfg.FlowEncodingOptions.Traces.ValidForTraces(); err != nil {
return err
}
if err := cfg.FlowEncodingOptions.Logs.ValidForLogs(); err != nil {
return err
}
if err := cfg.IncludeFlowTypes.Traces.Validate(); err != nil {
return err
}
if err := cfg.IncludeFlowTypes.Logs.Validate(); err != nil {
return err
}
return nil
}
func (cfg *Config) NewOutgoingContext(ctx context.Context) context.Context {
if cfg.GRPCClientSettings.Headers == nil {
return ctx
}
return metadata.NewOutgoingContext(ctx, metadata.New(cfg.GRPCClientSettings.Headers))
}