-
Notifications
You must be signed in to change notification settings - Fork 11
/
host.go
174 lines (145 loc) · 5.95 KB
/
host.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package provider
import (
"encoding/json"
"fmt"
"strings"
)
type RedactedString string
func (rs RedactedString) String() string {
if rs != "" {
return "redacted(string)"
}
return ""
}
func (rs RedactedString) MarshalJSON() ([]byte, error) {
return json.Marshal(rs.String())
}
func (rs RedactedString) Reveal() string {
return string(rs)
}
type OtelConfig struct {
EnableObservability bool `json:"enable_observability"`
EnableTraces bool `json:"enable_traces,omitempty"`
EnableMetrics bool `json:"enable_metrics,omitempty"`
EnableLogs bool `json:"enable_logs,omitempty"`
ObservabilityEndpoint string `json:"observability_endpoint,omitempty"`
TracesEndpoint string `json:"traces_endpoint,omitempty"`
MetricsEndpoint string `json:"metrics_endpoint,omitempty"`
LogsEndpoint string `json:"logs_endpoint,omitempty"`
Protocol string `json:"protocol,omitempty"`
}
type otelSignal int
const (
traces otelSignal = iota
metrics
logs
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_endpoint
OtelExporterGrpcEndpoint = "http://localhost:4317"
OtelExporterHttpEndpoint = "http://localhost:4318"
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_traces_endpoint
OtelExporterHttpTracesPath = "/v1/traces"
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_metrics_endpoint
OtelExporterHttpMetricsPath = "/v1/metrics"
// https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_logs_endpoint
OtelExporterHttpLogsPath = "/v1/logs"
)
// OtelProtocol returns the configured OpenTelemetry protocol if one is provided,
// otherwise defaulting to http.
func (config *OtelConfig) OtelProtocol() string {
if config.Protocol != "" {
return strings.ToLower(config.Protocol)
}
return OtelProtocolHTTP
}
// TracesURL returns the configured TracesEndpoint as-is if one is provided,
// otherwise it resolves the URL based on ObservabilityEndpoint value and the
// Protocol appropriate path.
func (config *OtelConfig) TracesURL() string {
if config.TracesEndpoint != "" {
return config.TracesEndpoint
}
return config.resolveSignalUrl(traces)
}
// MetricsURL returns the configured MetricsEndpoint as-is if one is provided,
// otherwise it resolves the URL based on ObservabilityEndpoint value and the
// Protocol appropriate path.
func (config *OtelConfig) MetricsURL() string {
if config.MetricsEndpoint != "" {
return config.MetricsEndpoint
}
return config.resolveSignalUrl(metrics)
}
// LogsURL returns the configured LogsEndpoint as-is if one is provided,
// otherwise it resolves the URL based on ObservabilityEndpoint value and the
// Protocol appropriate path.
func (config *OtelConfig) LogsURL() string {
if config.LogsEndpoint != "" {
return config.LogsEndpoint
}
return config.resolveSignalUrl(logs)
}
// TracesEnabled returns whether emitting traces has been enabled.
func (config *OtelConfig) TracesEnabled() bool {
return config.EnableObservability || config.EnableTraces
}
// MetricsEnabled returns whether emitting metrics has been enabled.
func (config *OtelConfig) MetricsEnabled() bool {
return config.EnableObservability || config.EnableMetrics
}
// LogsEnabled returns whether emitting logs has been enabled.
func (config *OtelConfig) LogsEnabled() bool {
return config.EnableObservability || config.EnableLogs
}
func (config *OtelConfig) resolveSignalUrl(signal otelSignal) string {
endpoint := config.defaultEndpoint()
if config.ObservabilityEndpoint != "" {
endpoint = config.ObservabilityEndpoint
}
endpoint = strings.TrimRight(endpoint, "/")
return fmt.Sprintf("%s%s", endpoint, config.defaultSignalPath(signal))
}
func (config *OtelConfig) defaultEndpoint() string {
if config.OtelProtocol() == OtelProtocolGRPC {
return OtelExporterGrpcEndpoint
}
return OtelExporterHttpEndpoint
}
func (config *OtelConfig) defaultSignalPath(signal otelSignal) string {
// In case of gRPC, we return empty string gRPC doesn't need a path to be set for it.
if config.OtelProtocol() == OtelProtocolGRPC {
return ""
}
switch signal {
case traces:
return OtelExporterHttpTracesPath
case metrics:
return OtelExporterHttpMetricsPath
case logs:
return OtelExporterHttpLogsPath
}
return ""
}
type HostData struct {
HostID string `json:"host_id,omitempty"`
LatticeRPCPrefix string `json:"lattice_rpc_prefix,omitempty"`
LatticeRPCUserJWT string `json:"lattice_rpc_user_jwt,omitempty"`
LatticeRPCUserSeed string `json:"lattice_rpc_user_seed,omitempty"`
LatticeRPCURL string `json:"lattice_rpc_url,omitempty"`
ProviderKey string `json:"provider_key,omitempty"`
EnvValues map[string]string `json:"env_values,omitempty"`
InstanceID string `json:"instance_id,omitempty"`
LinkDefinitions []linkWithEncryptedSecrets `json:"link_definitions,omitempty"`
ClusterIssuers []string `json:"cluster_issuers,omitempty"`
Config map[string]string `json:"config,omitempty"`
Secrets map[string]SecretValue `json:"secrets,omitempty"`
HostXKeyPublicKey string `json:"host_xkey_public_key,omitempty"`
ProviderXKeyPrivateKey RedactedString `json:"provider_xkey_private_key,omitempty"`
DefaultRPCTimeoutMS *uint64 `json:"default_rpc_timeout_ms,omitempty"`
StructuredLogging bool `json:"structured_logging,omitempty"`
LogLevel *Level `json:"log_level,omitempty"`
OtelConfig OtelConfig `json:"otel_config,omitempty"`
}
type HealthCheckResponse struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
}