Skip to content

Commit 766c9ee

Browse files
committed
polish
Signed-off-by: Jared Tan <jian.tan@daocloud.io>
1 parent 28aa268 commit 766c9ee

File tree

4 files changed

+67
-87
lines changed

4 files changed

+67
-87
lines changed

pkg/es/config/config.go

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -60,54 +60,40 @@ type Indices struct {
6060

6161
// Configuration describes the configuration properties needed to connect to an ElasticSearch cluster
6262
type Configuration struct {
63-
Servers []string `mapstructure:"server_urls" valid:"required,url"`
64-
RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
65-
Username string `mapstructure:"username"`
66-
Password string `mapstructure:"password" json:"-"`
67-
TokenFilePath string `mapstructure:"token_file"`
68-
PasswordFilePath string `mapstructure:"password_file"`
69-
AllowTokenFromContext bool `mapstructure:"-"`
70-
Sniffer bool `mapstructure:"sniffer"` // https://github.com/olivere/elastic/wiki/Sniffing
71-
SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
72-
MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
73-
MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
74-
NumShards int64 `mapstructure:"num_shards"`
75-
NumReplicas int64 `mapstructure:"num_replicas"`
76-
PrioritySpanTemplate int64 `mapstructure:"priority_span_template"`
77-
PriorityServiceTemplate int64 `mapstructure:"priority_service_template"`
78-
PriorityDependenciesTemplate int64 `mapstructure:"priority_dependencies_template"`
79-
Timeout time.Duration `mapstructure:"-"`
80-
BulkSize int `mapstructure:"-"`
81-
BulkWorkers int `mapstructure:"-"`
82-
BulkActions int `mapstructure:"-"`
83-
BulkFlushInterval time.Duration `mapstructure:"-"`
84-
IndexPrefix string `mapstructure:"index_prefix"`
85-
// Deprecated: use Indices and IndexOptions instead.
86-
IndexDateLayoutSpans string `mapstructure:"-"`
87-
// Deprecated: use Indices and IndexOptions instead.
88-
IndexDateLayoutServices string `mapstructure:"-"`
89-
// Deprecated: use Indices and IndexOptions instead.
90-
IndexDateLayoutSampling string `mapstructure:"-"`
91-
// Deprecated: use Indices and IndexOptions instead.
92-
IndexDateLayoutDependencies string `mapstructure:"-"`
93-
// Deprecated: use Indices and IndexOptions instead.
94-
IndexRolloverFrequencySpans string `mapstructure:"-"`
95-
// Deprecated: use Indices and IndexOptions instead.
96-
IndexRolloverFrequencyServices string `mapstructure:"-"`
97-
// Deprecated: use Indices and IndexOptions instead.
98-
IndexRolloverFrequencySampling string `mapstructure:"-"`
99-
Indices Indices `mapstructure:"indices"`
100-
ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
101-
AdaptiveSamplingLookback time.Duration `mapstructure:"-"`
102-
Tags TagsAsFields `mapstructure:"tags_as_fields"`
103-
Enabled bool `mapstructure:"-"`
104-
TLS tlscfg.Options `mapstructure:"tls"`
105-
UseReadWriteAliases bool `mapstructure:"use_aliases"`
106-
CreateIndexTemplates bool `mapstructure:"create_mappings"`
107-
UseILM bool `mapstructure:"use_ilm"`
108-
Version uint `mapstructure:"version"`
109-
LogLevel string `mapstructure:"log_level"`
110-
SendGetBodyAs string `mapstructure:"send_get_body_as"`
63+
Servers []string `mapstructure:"server_urls" valid:"required,url"`
64+
RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
65+
Username string `mapstructure:"username"`
66+
Password string `mapstructure:"password" json:"-"`
67+
TokenFilePath string `mapstructure:"token_file"`
68+
PasswordFilePath string `mapstructure:"password_file"`
69+
AllowTokenFromContext bool `mapstructure:"-"`
70+
Sniffer bool `mapstructure:"sniffer"` // https://github.com/olivere/elastic/wiki/Sniffing
71+
SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
72+
MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
73+
MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
74+
NumShards int64 `mapstructure:"num_shards"`
75+
NumReplicas int64 `mapstructure:"num_replicas"`
76+
PrioritySpanTemplate int64 `mapstructure:"priority_span_template"`
77+
PriorityServiceTemplate int64 `mapstructure:"priority_service_template"`
78+
PriorityDependenciesTemplate int64 `mapstructure:"priority_dependencies_template"`
79+
Timeout time.Duration `mapstructure:"-"`
80+
BulkSize int `mapstructure:"-"`
81+
BulkWorkers int `mapstructure:"-"`
82+
BulkActions int `mapstructure:"-"`
83+
BulkFlushInterval time.Duration `mapstructure:"-"`
84+
IndexPrefix string `mapstructure:"index_prefix"`
85+
Indices Indices `mapstructure:"indices"`
86+
ServiceCacheTTL time.Duration `mapstructure:"service_cache_ttl"`
87+
AdaptiveSamplingLookback time.Duration `mapstructure:"-"`
88+
Tags TagsAsFields `mapstructure:"tags_as_fields"`
89+
Enabled bool `mapstructure:"-"`
90+
TLS tlscfg.Options `mapstructure:"tls"`
91+
UseReadWriteAliases bool `mapstructure:"use_aliases"`
92+
CreateIndexTemplates bool `mapstructure:"create_mappings"`
93+
UseILM bool `mapstructure:"use_ilm"`
94+
Version uint `mapstructure:"version"`
95+
LogLevel string `mapstructure:"log_level"`
96+
SendGetBodyAs string `mapstructure:"send_get_body_as"`
11197
}
11298

11399
// TagsAsFields holds configuration for tag schema.
@@ -315,17 +301,17 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
315301

316302
// GetIndexRolloverFrequencySpansDuration returns jaeger-span index rollover frequency duration
317303
func (c *Configuration) GetIndexRolloverFrequencySpansDuration() time.Duration {
318-
return getIndexRolloverFrequencyDuration(c.IndexRolloverFrequencySpans)
304+
return getIndexRolloverFrequencyDuration(c.Indices.Spans.RolloverFrequency)
319305
}
320306

321307
// GetIndexRolloverFrequencyServicesDuration returns jaeger-service index rollover frequency duration
322308
func (c *Configuration) GetIndexRolloverFrequencyServicesDuration() time.Duration {
323-
return getIndexRolloverFrequencyDuration(c.IndexRolloverFrequencyServices)
309+
return getIndexRolloverFrequencyDuration(c.Indices.Services.RolloverFrequency)
324310
}
325311

326312
// GetIndexRolloverFrequencySamplingDuration returns jaeger-sampling index rollover frequency duration
327313
func (c *Configuration) GetIndexRolloverFrequencySamplingDuration() time.Duration {
328-
return getIndexRolloverFrequencyDuration(c.IndexRolloverFrequencySampling)
314+
return getIndexRolloverFrequencyDuration(c.Indices.Sampling.RolloverFrequency)
329315
}
330316

331317
// GetIndexRolloverFrequencyDuration returns the index rollover frequency duration for the given frequency string

plugin/storage/es/factory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ func createSpanReader(
236236
MaxDocCount: cfg.MaxDocCount,
237237
MaxSpanAge: cfg.MaxSpanAge,
238238
IndexPrefix: cfg.IndexPrefix,
239-
SpanIndexDateLayout: cfg.IndexDateLayoutSpans,
240-
ServiceIndexDateLayout: cfg.IndexDateLayoutServices,
239+
SpanIndexDateLayout: cfg.Indices.Spans.DateLayout,
240+
ServiceIndexDateLayout: cfg.Indices.Services.DateLayout,
241241
SpanIndexRolloverFrequency: cfg.GetIndexRolloverFrequencySpansDuration(),
242242
ServiceIndexRolloverFrequency: cfg.GetIndexRolloverFrequencyServicesDuration(),
243243
TagDotReplacement: cfg.Tags.DotReplacement,
@@ -270,8 +270,8 @@ func createSpanWriter(
270270
writer := esSpanStore.NewSpanWriter(esSpanStore.SpanWriterParams{
271271
Client: clientFn,
272272
IndexPrefix: cfg.IndexPrefix,
273-
SpanIndexDateLayout: cfg.IndexDateLayoutSpans,
274-
ServiceIndexDateLayout: cfg.IndexDateLayoutServices,
273+
SpanIndexDateLayout: cfg.Indices.Spans.DateLayout,
274+
ServiceIndexDateLayout: cfg.Indices.Services.DateLayout,
275275
AllTagsAsFields: cfg.Tags.AllAsFields,
276276
TagKeysAsFields: tags,
277277
TagDotReplacement: cfg.Tags.DotReplacement,
@@ -301,7 +301,7 @@ func (f *Factory) CreateSamplingStore(int /* maxBuckets */) (samplingstore.Store
301301
Client: f.getPrimaryClient,
302302
Logger: f.logger,
303303
IndexPrefix: f.primaryConfig.IndexPrefix,
304-
IndexDateLayout: f.primaryConfig.IndexDateLayoutSampling,
304+
IndexDateLayout: f.primaryConfig.Indices.Sampling.DateLayout,
305305
IndexRolloverFrequency: f.primaryConfig.GetIndexRolloverFrequencySamplingDuration(),
306306
Lookback: f.primaryConfig.AdaptiveSamplingLookback,
307307
MaxDocCount: f.primaryConfig.MaxDocCount,
@@ -345,7 +345,7 @@ func createDependencyReader(
345345
Client: clientFn,
346346
Logger: logger,
347347
IndexPrefix: cfg.IndexPrefix,
348-
IndexDateLayout: cfg.IndexDateLayoutDependencies,
348+
IndexDateLayout: cfg.Indices.Dependencies.RolloverFrequency,
349349
MaxDocCount: cfg.MaxDocCount,
350350
UseReadWriteAliases: cfg.UseReadWriteAliases,
351351
})

plugin/storage/es/options.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,17 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
363363
cfg.RemoteReadClusters = strings.Split(remoteReadClusters, ",")
364364
}
365365

366-
cfg.IndexRolloverFrequencySpans = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySpans))
367-
cfg.IndexRolloverFrequencyServices = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencyServices))
368-
cfg.IndexRolloverFrequencySampling = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySampling))
366+
cfg.Indices.Spans.RolloverFrequency = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySpans))
367+
cfg.Indices.Services.RolloverFrequency = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencyServices))
368+
cfg.Indices.Sampling.RolloverFrequency = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySampling))
369369

370370
separator := v.GetString(cfg.namespace + suffixIndexDateSeparator)
371-
cfg.IndexDateLayoutSpans = initDateLayout(cfg.IndexRolloverFrequencySpans, separator)
372-
cfg.IndexDateLayoutServices = initDateLayout(cfg.IndexRolloverFrequencyServices, separator)
373-
cfg.IndexDateLayoutSampling = initDateLayout(cfg.IndexRolloverFrequencySampling, separator)
371+
cfg.Indices.Spans.DateLayout = initDateLayout(cfg.Indices.Spans.RolloverFrequency, separator)
372+
cfg.Indices.Services.DateLayout = initDateLayout(cfg.Indices.Services.RolloverFrequency, separator)
373+
cfg.Indices.Sampling.DateLayout = initDateLayout(cfg.Indices.Sampling.RolloverFrequency, separator)
374374

375375
// Dependencies calculation should be daily, and this index size is very small
376-
cfg.IndexDateLayoutDependencies = initDateLayout(defaultIndexRolloverFrequency, separator)
376+
cfg.Indices.Dependencies.DateLayout = initDateLayout(defaultIndexRolloverFrequency, separator)
377377
var err error
378378
cfg.TLS, err = cfg.getTLSFlagsConfig().InitFromViper(v)
379379
if err != nil {
@@ -434,22 +434,16 @@ func DefaultConfig() config.Configuration {
434434
Tags: config.TagsAsFields{
435435
DotReplacement: "@",
436436
},
437-
Enabled: true,
438-
CreateIndexTemplates: true,
439-
Version: 0,
440-
UseReadWriteAliases: false,
441-
UseILM: false,
442-
Servers: []string{defaultServerURL},
443-
RemoteReadClusters: []string{},
444-
MaxDocCount: defaultMaxDocCount,
445-
LogLevel: "error",
446-
SendGetBodyAs: defaultSendGetBodyAs,
447-
IndexDateLayoutSpans: defaultIndexOptions.DateLayout,
448-
IndexDateLayoutServices: defaultIndexOptions.DateLayout,
449-
IndexDateLayoutSampling: defaultIndexOptions.DateLayout,
450-
IndexRolloverFrequencySpans: defaultIndexOptions.RolloverFrequency,
451-
IndexRolloverFrequencyServices: defaultIndexOptions.RolloverFrequency,
452-
IndexRolloverFrequencySampling: defaultIndexOptions.RolloverFrequency,
437+
Enabled: true,
438+
CreateIndexTemplates: true,
439+
Version: 0,
440+
UseReadWriteAliases: false,
441+
UseILM: false,
442+
Servers: []string{defaultServerURL},
443+
RemoteReadClusters: []string{},
444+
MaxDocCount: defaultMaxDocCount,
445+
LogLevel: "error",
446+
SendGetBodyAs: defaultSendGetBodyAs,
453447
Indices: config.Indices{
454448
Spans: defaultIndexOptions,
455449
Services: defaultIndexOptions,

plugin/storage/es/options_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func TestOptionsWithFlags(t *testing.T) {
9898
assert.Equal(t, "!", primary.Tags.DotReplacement)
9999
assert.Equal(t, "./file.txt", primary.Tags.File)
100100
assert.Equal(t, "test,tags", primary.Tags.Include)
101-
assert.Equal(t, "20060102", primary.IndexDateLayoutServices)
102-
assert.Equal(t, "2006010215", primary.IndexDateLayoutSpans)
101+
assert.Equal(t, "20060102", primary.Indices.Services.DateLayout)
102+
assert.Equal(t, "2006010215", primary.Indices.Spans.DateLayout)
103103
aux := opts.Get("es.aux")
104104
assert.Equal(t, []string{"3.3.3.3", "4.4.4.4"}, aux.Servers)
105105
assert.Equal(t, "hello", aux.Username)
@@ -112,8 +112,8 @@ func TestOptionsWithFlags(t *testing.T) {
112112
assert.Equal(t, "@", aux.Tags.DotReplacement)
113113
assert.Equal(t, "./file.txt", aux.Tags.File)
114114
assert.Equal(t, "test,tags", aux.Tags.Include)
115-
assert.Equal(t, "2006.01.02", aux.IndexDateLayoutServices)
116-
assert.Equal(t, "2006.01.02.15", aux.IndexDateLayoutSpans)
115+
assert.Equal(t, "2006.01.02", aux.Indices.Services.DateLayout)
116+
assert.Equal(t, "2006.01.02.15", aux.Indices.Spans.DateLayout)
117117
assert.True(t, primary.UseILM)
118118
assert.Equal(t, "POST", aux.SendGetBodyAs)
119119
}
@@ -182,7 +182,7 @@ func TestIndexDateSeparator(t *testing.T) {
182182
opts.InitFromViper(v)
183183

184184
primary := opts.GetPrimary()
185-
assert.Equal(t, tc.wantDateLayout, primary.IndexDateLayoutSpans)
185+
assert.Equal(t, tc.wantDateLayout, primary.Indices.Spans.DateLayout)
186186
})
187187
}
188188
}
@@ -236,8 +236,8 @@ func TestIndexRollover(t *testing.T) {
236236
command.ParseFlags(tc.flags)
237237
opts.InitFromViper(v)
238238
primary := opts.GetPrimary()
239-
assert.Equal(t, tc.wantSpanDateLayout, primary.IndexDateLayoutSpans)
240-
assert.Equal(t, tc.wantServiceDateLayout, primary.IndexDateLayoutServices)
239+
assert.Equal(t, tc.wantSpanDateLayout, primary.Indices.Spans.DateLayout)
240+
assert.Equal(t, tc.wantServiceDateLayout, primary.Indices.Services.DateLayout)
241241
assert.Equal(t, tc.wantSpanIndexRolloverFrequency, primary.GetIndexRolloverFrequencySpansDuration())
242242
assert.Equal(t, tc.wantServiceIndexRolloverFrequency, primary.GetIndexRolloverFrequencyServicesDuration())
243243
})

0 commit comments

Comments
 (0)