/
options.go
321 lines (295 loc) · 13.6 KB
/
options.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Copyright 2022 Tigris Data, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"time"
"github.com/tigrisdata/tigris/util/log"
)
type ServerConfig struct {
Host string
Port int16
FDBHardDrop bool `mapstructure:"fdb_hard_drop" yaml:"fdb_hard_drop" json:"fdb_hard_drop"`
}
type Config struct {
Log log.LogConfig
Server ServerConfig `yaml:"server" json:"server"`
Auth AuthConfig `yaml:"auth" json:"auth"`
Cdc CdcConfig `yaml:"cdc" json:"cdc"`
Search SearchConfig `yaml:"search" json:"search"`
Tracing TracingConfig `yaml:"tracing" json:"tracing"`
Metrics MetricsConfig `yaml:"metrics" json:"metrics"`
Profiling ProfilingConfig `yaml:"profiling" json:"profiling"`
FoundationDB FoundationDBConfig
Quota QuotaConfig
Observability ObservabilityConfig `yaml:"observability" json:"observability"`
Management ManagementConfig `yaml:"management" json:"management"`
}
type AuthConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
IssuerURL string `mapstructure:"issuer_url" yaml:"issuer_url" json:"issuer_url"`
Audience string `mapstructure:"audience" yaml:"audience" json:"audience"`
JWKSCacheTimeout time.Duration `mapstructure:"jwks_cache_timeout" yaml:"jwks_cache_timeout" json:"jwks_cache_timeout"`
LogOnly bool `mapstructure:"log_only" yaml:"log_only" json:"log_only"`
EnableNamespaceIsolation bool `mapstructure:"enable_namespace_isolation" yaml:"enable_namespace_isolation" json:"enable_namespace_isolation"`
AdminNamespaces []string `mapstructure:"admin_namespaces" yaml:"admin_namespaces" json:"admin_namespaces"`
OAuthProvider string `mapstructure:"oauth_provider" yaml:"oauth_provider" json:"oauth_provider"`
ClientId string `mapstructure:"client_id" yaml:"client_id" json:"client_id"`
ExternalTokenURL string `mapstructure:"external_token_url" yaml:"external_token_url" json:"external_token_url"`
EnableOauth bool `mapstructure:"enable_oauth" yaml:"enable_oauth" json:"enable_oauth"`
TokenCacheSize int `mapstructure:"token_cache_size" yaml:"token_cache_size" json:"token_cache_size"`
ExternalDomain string `mapstructure:"external_domain" yaml:"external_domain" json:"external_domain"`
ManagementClientId string `mapstructure:"management_client_id" yaml:"management_client_id" json:"management_client_id"`
ManagementClientSecret string `mapstructure:"management_client_secret" yaml:"management_client_secret" json:"management_client_secret"`
TokenClockSkewDurationSec int `mapstructure:"token_clock_skew_duration_sec" yaml:"token_clock_skew_duration_sec" json:"token_clock_skew_duration_sec"`
}
type CdcConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
StreamInterval time.Duration
StreamBatch int
StreamBuffer int
}
type TracingConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
SampleRate float64 `mapstructure:"sample_rate" yaml:"sample_rate" json:"sample_rate"`
CodeHotspotsEnabled bool `mapstructure:"codehotspots_enabled" yaml:"codehotspots_enabled" json:"codehotspots_enabled"`
EndpointsEnabled bool `mapstructure:"endpoints_enabled" yaml:"endpoints_enabled" json:"endpoints_enabled"`
WithUDS string `mapstructure:"agent_socket" yaml:"agent_socket" json:"agent_socket"`
WithAgentAddr string `mapstructure:"agent_addr" yaml:"agent_addr" json:"agent_addr"`
WithDogStatsdAddr string `mapstructure:"dogstatsd_addr" yaml:"dogstatsd_addr" json:"dogstatsd_addr"`
}
type MetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
TimerQuantiles []float64 `mapstructure:"quantiles" yaml:"quantiles" json:"quantiles"`
Requests RequestsMetricGroupConfig `mapstructure:"requests" yaml:"requests" json:"requests"`
Fdb FdbMetricGroupConfig `mapstructure:"fdb" yaml:"fdb" json:"fdb"`
Search SearchMetricGroupConfig `mapstructure:"search" yaml:"search" json:"search"`
Session SessionMetricGroupConfig `mapstructure:"session" yaml:"session" json:"session"`
Size SizeMetricGroupConfig `mapstructure:"size" yaml:"size" json:"size"`
Network NetworkMetricGroupConfig `mapstructure:"network" yaml:"network" json:"network"`
Auth AuthMetricsConfig `mapstructure:"auth" yaml:"auth" json:"auth"`
}
type TimerConfig struct {
TimerEnabled bool `mapstructure:"timer_enabled" yaml:"timer_enabled" json:"timer_enabled"`
HistogramEnabled bool `mapstructure:"histogram_enabled" yaml:"histogram_enabled" json:"histogram_enabled"`
}
type CounterConfig struct {
OkEnabled bool `mapstructure:"ok_enabled" yaml:"ok_enabled" json:"ok_enabled"`
ErrorEnabled bool `mapstructure:"error_enabled" yaml:"error_enabled" json:"error_enabled"`
}
type RequestsMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type FdbMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type SearchMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type SessionMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type SizeMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Namespace bool `mapstructure:"namespace" yaml:"namespace" json:"namespace"`
Db bool `mapstructure:"db" yaml:"db" json:"db"`
Collection bool `mapstructure:"collection" yaml:"collection" json:"collection"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type NetworkMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type AuthMetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}
type ProfilingConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
EnableCPU bool `mapstructure:"enable_cpu" yaml:"enable_cpu" json:"enable_cpu"`
EnableHeap bool `mapstructure:"enable_heap" yaml:"enable_heap" json:"enable_heap"`
EnableBlock bool `mapstructure:"enable_block" yaml:"enable_block" json:"enable_block"`
EnableMutex bool `mapstructure:"enable_mutex" yaml:"enable_mutex" json:"enable_mutex"`
EnableGoroutine bool `mapstructure:"enable_goroutine" yaml:"enable_goroutine" json:"enable_goroutine"`
}
type ManagementConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
}
type ObservabilityConfig struct {
Provider string `mapstructure:"provider" yaml:"provider" json:"provider"`
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
ApiKey string `mapstructure:"api_key" yaml:"api_key" json:"api_key"`
AppKey string `mapstructure:"app_key" yaml:"app_key" json:"app_key"`
ProviderUrl string `mapstructure:"provider_url" yaml:"provider_url" json:"provider_url"`
}
var DefaultConfig = Config{
Log: log.LogConfig{
Level: "info",
SampleRate: 0.01,
},
Server: ServerConfig{
Host: "0.0.0.0",
Port: 8081,
FDBHardDrop: false,
},
Auth: AuthConfig{
Enabled: false,
IssuerURL: "https://tigrisdata-dev.us.auth0.com/",
Audience: "https://tigris-api",
JWKSCacheTimeout: 5 * time.Minute,
LogOnly: true,
AdminNamespaces: []string{"tigris-admin"},
},
Cdc: CdcConfig{
Enabled: false,
StreamInterval: 500 * time.Millisecond,
StreamBatch: 100,
StreamBuffer: 200,
},
Search: SearchConfig{
Host: "localhost",
Port: 8108,
ReadEnabled: true,
WriteEnabled: true,
},
Tracing: TracingConfig{
Enabled: false,
SampleRate: 0.01,
CodeHotspotsEnabled: true,
EndpointsEnabled: true,
},
Metrics: MetricsConfig{
Enabled: true,
TimerQuantiles: []float64{0.5, 0.95},
Requests: RequestsMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Fdb: FdbMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Search: SearchMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Session: SessionMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Size: SizeMetricGroupConfig{
Enabled: true,
Namespace: true,
Db: true,
Collection: true,
FilteredTags: nil,
},
Network: NetworkMetricGroupConfig{
Enabled: true,
FilteredTags: nil,
},
Auth: AuthMetricsConfig{
Enabled: true,
FilteredTags: nil,
},
},
Profiling: ProfilingConfig{
Enabled: false,
EnableCPU: true,
EnableHeap: true,
},
Quota: QuotaConfig{
Enabled: false,
RateLimit: 1000, // requests per second both reads and writes
WriteThroughputLimit: 10000000, // bytes per second
ReadThroughputLimit: 10000000, // bytes per second
DataSizeLimit: 10000000000, // bytes
LimitUpdateInterval: 5, // seconds
TenantSizeRefreshInterval: 60, // seconds
AllTenantsRefreshInternal: 300, // seconds
},
Observability: ObservabilityConfig{
Enabled: false,
},
Management: ManagementConfig{
Enabled: true,
},
}
// FoundationDBConfig keeps FoundationDB configuration parameters
type FoundationDBConfig struct {
ClusterFile string `mapstructure:"cluster_file" json:"cluster_file" yaml:"cluster_file"`
}
type SearchConfig struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
Port int16 `mapstructure:"port" json:"port" yaml:"port"`
AuthKey string `mapstructure:"auth_key" json:"auth_key" yaml:"auth_key"`
ReadEnabled bool `mapstructure:"read_enabled" yaml:"read_enabled" json:"read_enabled"`
WriteEnabled bool `mapstructure:"write_enabled" yaml:"write_enabled" json:"write_enabled"`
}
type QuotaConfig struct {
Enabled bool
RateLimit int `mapstructure:"rate_limit" yaml:"rate_limit" json:"rate_limit"`
WriteThroughputLimit int `mapstructure:"write_throughput_limit" yaml:"write_throughput_limit" json:"write_throughput_limit"`
ReadThroughputLimit int `mapstructure:"read_throughput_limit" yaml:"read_throughput_limit" json:"read_throughput_limit"`
DataSizeLimit int64 `mapstructure:"data_size_limit" yaml:"data_size_limit" json:"data_size_limit"`
LimitUpdateInterval int64 `mapstructure:"limit_update_interval" yaml:"limit_update_interval" json:"limit_update_interval"`
TenantSizeRefreshInterval int64 `mapstructure:"tenant_size_refresh_interval" yaml:"tenant_size_refresh_interval" json:"tenant_size_refresh_interval"`
AllTenantsRefreshInternal int64 `mapstructure:"all_tenants_refresh_interval" yaml:"all_tenants_refresh_interval" json:"all_tenants_refresh_interval"`
}
func IsIndexingStoreReadEnabled() bool {
return DefaultConfig.Search.WriteEnabled && DefaultConfig.Search.ReadEnabled
}