-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
116 lines (97 loc) · 2.33 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package tracer
import (
"fmt"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"
"os"
)
const (
TRACER_TYPE_JAEGER = "jaeger"
)
const (
CONFIG_TYPE_SIMPLE = iota
CONFIG_TYPE_ETCD
)
const (
ENV_JAEGER_AGENT_HOST = "JAEGER_AGENT_HOST"
ENV_JAEGER_AGENT_PORT = "JAEGER_AGENT_PORT"
)
const (
JAEGER_DEBUG_HEADER = "trace-debug-id"
JAEGER_BAGGAGE_HEADER = "trace-baggage"
TRACE_CONTEXT_HEADER_NAME = "banyu-trace-id"
TRACE_BAGGAGE_HEADER_PREFIX = "dyctx-"
)
var defaultConfigurator = NewSimpleConfigurator()
type Config struct {
TracerType string
ServiceName string
TracerConfig interface{}
}
type Configurator interface {
GetConfig(serviceName string) *Config
}
func NewConfigurator(configType int) (Configurator, error) {
switch configType {
case CONFIG_TYPE_SIMPLE:
return NewSimpleConfigurator(), nil
case CONFIG_TYPE_ETCD:
return NewEtcdConfigurator(), nil
default:
return nil, fmt.Errorf("configType %d error", configType)
}
}
type SimpleConfig struct {
}
func NewSimpleConfigurator() Configurator {
return &SimpleConfig{}
}
func (m *SimpleConfig) GetConfig(serviceName string) *Config {
// 测试环境
var agentHost = "127.0.0.1"
var agentPort = "6831"
if h := os.Getenv(ENV_JAEGER_AGENT_HOST); h != "" {
agentHost = h
}
if p := os.Getenv(ENV_JAEGER_AGENT_PORT); p != "" {
agentPort = p
}
return &Config{
TracerType: TRACER_TYPE_JAEGER,
ServiceName: serviceName,
TracerConfig: config.Configuration{
ServiceName: serviceName,
Disabled: false,
RPCMetrics: false,
Sampler: &config.SamplerConfig{
Type: jaeger.SamplerTypeRateLimiting,
Param: 1,
},
Reporter: &config.ReporterConfig{
LocalAgentHostPort: fmt.Sprintf("%s:%s", agentHost, agentPort),
},
Headers: &jaeger.HeadersConfig{
JaegerDebugHeader: JAEGER_DEBUG_HEADER,
JaegerBaggageHeader: JAEGER_BAGGAGE_HEADER,
TraceContextHeaderName: TRACE_CONTEXT_HEADER_NAME,
TraceBaggageHeaderPrefix: TRACE_BAGGAGE_HEADER_PREFIX,
},
},
}
}
type EtcdConfig struct {
etcdAddrs []string
}
func NewEtcdConfigurator() Configurator {
// TODO:
return &EtcdConfig{
etcdAddrs: []string{},
}
}
func (m *EtcdConfig) GetConfig(serviceName string) *Config {
return &Config{
TracerType: TRACER_TYPE_JAEGER,
ServiceName: serviceName,
TracerConfig: nil,
}
}