@@ -39,25 +39,15 @@ const (
39
39
40
40
// IndexOptions describes the index format and rollover frequency
41
41
type IndexOptions struct {
42
- // Priority contains the priority of index template (ESv8 only).
43
- Priority int64 `mapstructure:"priority"`
44
- DateLayout string `mapstructure:"date_layout"`
45
- // Shards is the number of shards per index in Elasticsearch.
46
- Shards int64 `mapstructure:"shards"`
47
- // Replicas is the number of replicas per index in Elasticsearch.
48
- Replicas int64 `mapstructure:"replicas"`
49
- // RolloverFrequency contains the rollover frequency setting used to fetch
50
- // indices from elasticsearch.
51
- // Valid configuration options are: [hour, day].
52
- // This setting does not affect the index rotation and is simply used for
53
- // fetching indices.
54
- RolloverFrequency string `mapstructure:"rollover_frequency"`
42
+ Priority int64 `mapstructure:"priority"`
43
+ DateLayout string `mapstructure:"date_layout"`
44
+ Shards int64 `mapstructure:"shards"`
45
+ Replicas int64 `mapstructure:"replicas"`
46
+ RolloverFrequency string `mapstructure:"rollover_frequency"` // "hour" or "day"
55
47
}
56
48
57
49
// Indices describes different configuration options for each index type
58
50
type Indices struct {
59
- // IndexPrefix is an optional prefix to prepend to Jaeger indices.
60
- // For example, setting this field to "production" creates "production-jaeger-*".
61
51
IndexPrefix IndexPrefix `mapstructure:"index_prefix"`
62
52
Spans IndexOptions `mapstructure:"spans"`
63
53
Services IndexOptions `mapstructure:"services"`
@@ -80,58 +70,34 @@ func (p IndexPrefix) Apply(indexName string) string {
80
70
81
71
// Configuration describes the configuration properties needed to connect to an ElasticSearch cluster
82
72
type Configuration struct {
83
- // ---- connection related configs ----
84
- // Servers is a list of Elasticsearch servers. The strings must must contain full URLs
85
- // (i.e. http://localhost:9200).
86
- Servers []string `mapstructure:"server_urls" valid:"required,url"`
87
- // RemoteReadClusters is a list of Elasticsearch remote cluster names for cross-cluster
88
- // querying.
89
- RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
90
- Authentication Authentication `mapstructure:"auth"`
91
- // TLS contains the TLS configuration for the connection to the ElasticSearch clusters.
92
- TLS configtls.ClientConfig `mapstructure:"tls"`
93
- Sniffing Sniffing `mapstructure:"sniffing"`
94
- // SendGetBodyAs is the HTTP verb to use for requests that contain a body.
95
- SendGetBodyAs string `mapstructure:"send_get_body_as"`
96
- // QueryTimeout contains the timeout used for queries. A timeout of zero means no timeout.
97
- QueryTimeout time.Duration `mapstructure:"query_timeout"`
98
-
99
- // ---- elasticsearch client related configs ----
100
- BulkProcessing BulkProcessing `mapstructure:"bulk_processing"`
101
- // Version contains the major Elasticsearch version. If this field is not specified,
102
- // the value will be auto-detected from Elasticsearch.
103
- Version uint `mapstructure:"version"`
104
- // LogLevel contains the Elasticsearch client log-level. Valid values for this field
105
- // are: [debug, info, error]
106
- LogLevel string `mapstructure:"log_level"`
107
-
108
- // ---- index related configs ----
109
- Indices Indices `mapstructure:"indices"`
110
- // UseReadWriteAliases, if set to true, will use read and write aliases for indices.
111
- // Use this option with Elasticsearch rollover API. It requires an external component
112
- // to create aliases before startup and then performing its management.
113
- UseReadWriteAliases bool `mapstructure:"use_aliases"`
114
- // CreateIndexTemplates, if set to true, creates index templates at application startup.
115
- // This configuration should be set to false when templates are installed manually.
116
- CreateIndexTemplates bool `mapstructure:"create_mappings"`
117
- // Option to enable Index Lifecycle Management (ILM) for Jaeger span and service indices.
118
- // Read more about ILM at
119
- // https://www.jaegertracing.io/docs/deployment/#enabling-ilm-support
120
- UseILM bool `mapstructure:"use_ilm"`
121
-
122
- // ---- jaeger-specific configs ----
123
- // MaxDocCount Defines maximum number of results to fetch from storage per query.
124
- MaxDocCount int `mapstructure:"max_doc_count"`
125
- // MaxSpanAge configures the maximum lookback on span reads.
126
- MaxSpanAge time.Duration `mapstructure:"max_span_age"`
127
- // ServiceCacheTTL contains the TTL for the cache of known service names.
128
- ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
129
- // AdaptiveSamplingLookback contains the duration to look back for the
130
- // latest adaptive sampling probabilities.
131
- AdaptiveSamplingLookback time.Duration `mapstructure:"adaptive_sampling_lookback"`
132
- Tags TagsAsFields `mapstructure:"tags_as_fields"`
133
- // Enabled, if set to true, enables the namespace for storage pointed to by this configuration.
134
- Enabled bool `mapstructure:"-"`
73
+ Servers []string `mapstructure:"server_urls" valid:"required,url"`
74
+ RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
75
+ Username string `mapstructure:"username"`
76
+ Password string `mapstructure:"password" json:"-"`
77
+ TokenFilePath string `mapstructure:"token_file"`
78
+ PasswordFilePath string `mapstructure:"password_file"`
79
+ AllowTokenFromContext bool `mapstructure:"-"`
80
+ Sniffer bool `mapstructure:"sniffer"` // https://github.com/olivere/elastic/wiki/Sniffing
81
+ SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
82
+ MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
83
+ MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
84
+ Timeout time.Duration `mapstructure:"-"`
85
+ BulkSize int `mapstructure:"-"`
86
+ BulkWorkers int `mapstructure:"-"`
87
+ BulkActions int `mapstructure:"-"`
88
+ BulkFlushInterval time.Duration `mapstructure:"-"`
89
+ Indices Indices `mapstructure:"indices"`
90
+ ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
91
+ AdaptiveSamplingLookback time.Duration `mapstructure:"-"`
92
+ Tags TagsAsFields `mapstructure:"tags_as_fields"`
93
+ Enabled bool `mapstructure:"-"`
94
+ TLS configtls.ClientConfig `mapstructure:"tls"`
95
+ UseReadWriteAliases bool `mapstructure:"use_aliases"`
96
+ CreateIndexTemplates bool `mapstructure:"create_mappings"`
97
+ UseILM bool `mapstructure:"use_ilm"`
98
+ Version uint `mapstructure:"version"`
99
+ LogLevel string `mapstructure:"log_level"`
100
+ SendGetBodyAs string `mapstructure:"send_get_body_as"`
135
101
}
136
102
137
103
// TagsAsFields holds configuration for tag schema.
@@ -148,53 +114,6 @@ type TagsAsFields struct {
148
114
Include string `mapstructure:"include"`
149
115
}
150
116
151
- // Sniffing sets the sniffing configuration for the ElasticSearch client, which is the process
152
- // of finding all the nodes of your cluster. Read more about sniffing at
153
- // https://github.com/olivere/elastic/wiki/Sniffing.
154
- type Sniffing struct {
155
- // Enabled, if set to true, enables sniffing for the ElasticSearch client.
156
- Enabled bool `mapstructure:"enabled"`
157
- // UseHTTPS, if set to true, sets the HTTP scheme to HTTPS when performing sniffing.
158
- UseHTTPS bool `mapstructure:"use_https"`
159
- }
160
-
161
- type BulkProcessing struct {
162
- // MaxBytes, contains the number of bytes which specifies when to flush.
163
- MaxBytes int `mapstructure:"max_bytes"`
164
- // MaxActions contain the number of added actions which specifies when to flush.
165
- MaxActions int `mapstructure:"max_actions"`
166
- // FlushInterval is the interval at the end of which a flush occurs.
167
- FlushInterval time.Duration `mapstructure:"flush_interval"`
168
- // Workers contains the number of concurrent workers allowed to be executed.
169
- Workers int `mapstructure:"workers"`
170
- }
171
-
172
- type Authentication struct {
173
- BasicAuthentication BasicAuthentication `mapstructure:"basic"`
174
- BearerTokenAuthentication BearerTokenAuthentication `mapstructure:"bearer_token"`
175
- }
176
-
177
- type BasicAuthentication struct {
178
- // Username contains the username required to connect to Elasticsearch.
179
- Username string `mapstructure:"username"`
180
- // Password contains The password required by Elasticsearch
181
- Password string `mapstructure:"password" json:"-"`
182
- // PasswordFilePath contains the path to a file containing password.
183
- // This file is watched for changes.
184
- PasswordFilePath string `mapstructure:"password_file"`
185
- }
186
-
187
- // BearerTokenAuthentication contains the configuration for attaching bearer tokens
188
- // when making HTTP requests. Note that TokenFilePath and AllowTokenFromContext
189
- // should not both be enabled. If both TokenFilePath and AllowTokenFromContext are set,
190
- // the TokenFilePath will be ignored.
191
- type BearerTokenAuthentication struct {
192
- // FilePath contains the path to a file containing a bearer token.
193
- FilePath string `mapstructure:"file_path"`
194
- // AllowTokenFromContext, if set to true, enables reading bearer token from the context.
195
- AllowFromContext bool `mapstructure:"from_context"`
196
- }
197
-
198
117
// NewClient creates a new ElasticSearch client
199
118
func NewClient (c * Configuration , logger * zap.Logger , metricsFactory metrics.Factory ) (es.Client , error ) {
200
119
if len (c .Servers ) < 1 {
@@ -252,10 +171,10 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
252
171
zap .Any ("response" , response ))
253
172
}
254
173
}).
255
- BulkSize (c .BulkProcessing . MaxBytes ).
256
- Workers (c .BulkProcessing . Workers ).
257
- BulkActions (c .BulkProcessing . MaxActions ).
258
- FlushInterval (c .BulkProcessing . FlushInterval ).
174
+ BulkSize (c .BulkSize ).
175
+ Workers (c .BulkWorkers ).
176
+ BulkActions (c .BulkActions ).
177
+ FlushInterval (c .BulkFlushInterval ).
259
178
Do (context .Background ())
260
179
if err != nil {
261
180
return nil , err
@@ -301,9 +220,9 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
301
220
func newElasticsearchV8 (c * Configuration , logger * zap.Logger ) (* esV8.Client , error ) {
302
221
var options esV8.Config
303
222
options .Addresses = c .Servers
304
- options .Username = c .Authentication . BasicAuthentication . Username
305
- options .Password = c .Authentication . BasicAuthentication . Password
306
- options .DiscoverNodesOnStart = c .Sniffing . Enabled
223
+ options .Username = c .Username
224
+ options .Password = c .Password
225
+ options .DiscoverNodesOnStart = c .Sniffer
307
226
transport , err := GetHTTPRoundTripper (c , logger )
308
227
if err != nil {
309
228
return nil , err
@@ -339,14 +258,14 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
339
258
if len (c .RemoteReadClusters ) == 0 {
340
259
c .RemoteReadClusters = source .RemoteReadClusters
341
260
}
342
- if c .Authentication . BasicAuthentication . Username == "" {
343
- c .Authentication . BasicAuthentication . Username = source . Authentication . BasicAuthentication .Username
261
+ if c .Username == "" {
262
+ c .Username = source .Username
344
263
}
345
- if c .Authentication . BasicAuthentication . Password == "" {
346
- c .Authentication . BasicAuthentication . Password = source . Authentication . BasicAuthentication .Password
264
+ if c .Password == "" {
265
+ c .Password = source .Password
347
266
}
348
- if ! c .Sniffing . Enabled {
349
- c .Sniffing . Enabled = source .Sniffing . Enabled
267
+ if ! c .Sniffer {
268
+ c .Sniffer = source .Sniffer
350
269
}
351
270
if c .MaxSpanAge == 0 {
352
271
c .MaxSpanAge = source .MaxSpanAge
@@ -362,20 +281,20 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
362
281
setDefaultIndexOptions (& c .Indices .Services , & source .Indices .Services )
363
282
setDefaultIndexOptions (& c .Indices .Dependencies , & source .Indices .Dependencies )
364
283
365
- if c .BulkProcessing . MaxBytes == 0 {
366
- c .BulkProcessing . MaxBytes = source .BulkProcessing . MaxBytes
284
+ if c .BulkSize == 0 {
285
+ c .BulkSize = source .BulkSize
367
286
}
368
- if c .BulkProcessing . Workers == 0 {
369
- c .BulkProcessing . Workers = source .BulkProcessing . Workers
287
+ if c .BulkWorkers == 0 {
288
+ c .BulkWorkers = source .BulkWorkers
370
289
}
371
- if c .BulkProcessing . MaxActions == 0 {
372
- c .BulkProcessing . MaxActions = source .BulkProcessing . MaxActions
290
+ if c .BulkActions == 0 {
291
+ c .BulkActions = source .BulkActions
373
292
}
374
- if c .BulkProcessing . FlushInterval == 0 {
375
- c .BulkProcessing . FlushInterval = source .BulkProcessing . FlushInterval
293
+ if c .BulkFlushInterval == 0 {
294
+ c .BulkFlushInterval = source .BulkFlushInterval
376
295
}
377
- if ! c .Sniffing . UseHTTPS {
378
- c .Sniffing . UseHTTPS = source .Sniffing . UseHTTPS
296
+ if ! c .SnifferTLSEnabled {
297
+ c .SnifferTLSEnabled = source .SnifferTLSEnabled
379
298
}
380
299
if ! c .Tags .AllAsFields {
381
300
c .Tags .AllAsFields = source .Tags .AllAsFields
@@ -442,31 +361,31 @@ func (c *Configuration) TagKeysAsFields() ([]string, error) {
442
361
// getConfigOptions wraps the configs to feed to the ElasticSearch client init
443
362
func (c * Configuration ) getConfigOptions (logger * zap.Logger ) ([]elastic.ClientOptionFunc , error ) {
444
363
options := []elastic.ClientOptionFunc {
445
- elastic .SetURL (c .Servers ... ), elastic .SetSniff (c .Sniffing . Enabled ),
364
+ elastic .SetURL (c .Servers ... ), elastic .SetSniff (c .Sniffer ),
446
365
// Disable health check when token from context is allowed, this is because at this time
447
- // we don'r have a valid token to do the check ad if we don't disable the check the service that
366
+ // we don' have a valid token to do the check ad if we don't disable the check the service that
448
367
// uses this won't start.
449
- elastic .SetHealthcheck (! c .Authentication . BearerTokenAuthentication . AllowFromContext ),
368
+ elastic .SetHealthcheck (! c .AllowTokenFromContext ),
450
369
}
451
- if c .Sniffing . UseHTTPS {
370
+ if c .SnifferTLSEnabled {
452
371
options = append (options , elastic .SetScheme ("https" ))
453
372
}
454
373
httpClient := & http.Client {
455
- Timeout : c .QueryTimeout ,
374
+ Timeout : c .Timeout ,
456
375
}
457
376
options = append (options , elastic .SetHttpClient (httpClient ))
458
377
459
- if c .Authentication . BasicAuthentication . Password != "" && c . Authentication . BasicAuthentication .PasswordFilePath != "" {
378
+ if c .Password != "" && c .PasswordFilePath != "" {
460
379
return nil , fmt .Errorf ("both Password and PasswordFilePath are set" )
461
380
}
462
- if c .Authentication . BasicAuthentication . PasswordFilePath != "" {
463
- passwordFromFile , err := loadTokenFromFile (c .Authentication . BasicAuthentication . PasswordFilePath )
381
+ if c .PasswordFilePath != "" {
382
+ passwordFromFile , err := loadTokenFromFile (c .PasswordFilePath )
464
383
if err != nil {
465
384
return nil , fmt .Errorf ("failed to load password from file: %w" , err )
466
385
}
467
- c .Authentication . BasicAuthentication . Password = passwordFromFile
386
+ c .Password = passwordFromFile
468
387
}
469
- options = append (options , elastic .SetBasicAuth (c .Authentication . BasicAuthentication . Username , c . Authentication . BasicAuthentication .Password ))
388
+ options = append (options , elastic .SetBasicAuth (c .Username , c .Password ))
470
389
471
390
if c .SendGetBodyAs != "" {
472
391
options = append (options , elastic .SetSendGetBodyAs (c .SendGetBodyAs ))
@@ -546,20 +465,20 @@ func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTrippe
546
465
}
547
466
548
467
token := ""
549
- if c .Authentication . BearerTokenAuthentication . FilePath != "" {
550
- if c .Authentication . BearerTokenAuthentication . AllowFromContext {
468
+ if c .TokenFilePath != "" {
469
+ if c .AllowTokenFromContext {
551
470
logger .Warn ("Token file and token propagation are both enabled, token from file won't be used" )
552
471
}
553
- tokenFromFile , err := loadTokenFromFile (c .Authentication . BearerTokenAuthentication . FilePath )
472
+ tokenFromFile , err := loadTokenFromFile (c .TokenFilePath )
554
473
if err != nil {
555
474
return nil , err
556
475
}
557
476
token = tokenFromFile
558
477
}
559
- if token != "" || c .Authentication . BearerTokenAuthentication . AllowFromContext {
478
+ if token != "" || c .AllowTokenFromContext {
560
479
transport = bearertoken.RoundTripper {
561
480
Transport : httpTransport ,
562
- OverrideFromCtx : c .Authentication . BearerTokenAuthentication . AllowFromContext ,
481
+ OverrideFromCtx : c .AllowTokenFromContext ,
563
482
StaticToken : token ,
564
483
}
565
484
}
0 commit comments