Skip to content

Commit ad620f7

Browse files
committed
polish review
Signed-off-by: Jared Tan <[email protected]>
1 parent 37d81d2 commit ad620f7

File tree

7 files changed

+125
-60
lines changed

7 files changed

+125
-60
lines changed

cmd/es-rollover/app/init/flags.go

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ package init
1616

1717
import (
1818
"flag"
19+
"log"
1920

2021
"github.com/spf13/viper"
2122

2223
"github.com/jaegertracing/jaeger/cmd/es-rollover/app"
2324
cfg "github.com/jaegertracing/jaeger/pkg/es/config"
2425
)
2526

27+
const (
28+
shards = "shards"
29+
replicas = "replicas"
30+
prioritySpanTemplate = "priority-span-template"
31+
priorityServiceTemplate = "priority-service-template"
32+
)
33+
2634
// Config holds configuration for index cleaner binary.
2735
type Config struct {
2836
app.Config
@@ -31,6 +39,11 @@ type Config struct {
3139

3240
// AddFlags adds flags for TLS to the FlagSet.
3341
func (*Config) AddFlags(flags *flag.FlagSet) {
42+
flags.Int(shards, 5, "(deprecated, will be replaced with num-shards-span,num-shards-service,num-shards-sampling,num-shards-dependencies, if .num-shards set, it will be used as global settings for span,service,sampling,dependencies index) Number of shards")
43+
flags.Int(replicas, 1, "(deprecated, will be replaced with num-replicas-span,num-replicas-service,num-replicas-sampling,num-replicas-dependencies, if .num-replicas set, it will be used as global settings for span,service,sampling,dependencies index) Number of replicas")
44+
flags.Int(prioritySpanTemplate, 0, "(deprecated, will be replaced with priority-spans-template) Priority of jaeger-span index template (ESv8 only)")
45+
flags.Int(priorityServiceTemplate, 0, "(deprecated, will be replaced with priority-services-template) Priority of jaeger-service index template (ESv8 only)")
46+
3447
flags.Int64(cfg.NumShardSpanFlag(), 5, "Number of span index shards")
3548
flags.Int64(cfg.NumShardServiceFlag(), 5, "Number of service index shards")
3649
flags.Int64(cfg.NumShardDependenciesFlag(), 5, "Number of dependencies index shards")
@@ -49,16 +62,37 @@ func (*Config) AddFlags(flags *flag.FlagSet) {
4962

5063
// InitFromViper initializes config from viper.Viper.
5164
func (c *Config) InitFromViper(v *viper.Viper) {
52-
c.Indices.Spans.TemplateNumShards = v.GetInt64(cfg.NumShardSpanFlag())
53-
c.Indices.Spans.TemplateNumReplicas = v.GetInt64(cfg.NumReplicaSpanFlag())
54-
c.Indices.Services.TemplateNumShards = v.GetInt64(cfg.NumShardServiceFlag())
55-
c.Indices.Services.TemplateNumReplicas = v.GetInt64(cfg.NumReplicaServiceFlag())
56-
c.Indices.Dependencies.TemplateNumShards = v.GetInt64(cfg.NumShardDependenciesFlag())
57-
c.Indices.Dependencies.TemplateNumReplicas = v.GetInt64(cfg.NumReplicaDependenciesFlag())
58-
c.Indices.Sampling.TemplateNumShards = v.GetInt64(cfg.NumShardSamplingFlag())
59-
c.Indices.Sampling.TemplateNumReplicas = v.GetInt64(cfg.NumShardSamplingFlag())
60-
c.Indices.Spans.TemplatePriority = v.GetInt64(cfg.PrioritySpanTemplateFlag())
61-
c.Indices.Services.TemplatePriority = v.GetInt64(cfg.PriorityServiceTemplateFlag())
65+
66+
deprecatedNumShards := v.GetInt(shards)
67+
deprecatedReplicaShards := v.GetInt(replicas)
68+
69+
if deprecatedReplicaShards > 0 || deprecatedNumShards > 0 {
70+
log.Printf("using deprecated %s or %s", shards, replicas)
71+
}
72+
73+
c.Indices.Spans.TemplateNumShards = cfg.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.NumShardSpanFlag()))
74+
c.Indices.Services.TemplateNumShards = cfg.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.NumShardServiceFlag()))
75+
c.Indices.Dependencies.TemplateNumShards = cfg.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.NumShardDependenciesFlag()))
76+
c.Indices.Sampling.TemplateNumShards = cfg.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.NumShardSamplingFlag()))
77+
78+
c.Indices.Spans.TemplateNumReplicas = cfg.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.NumReplicaSpanFlag()))
79+
c.Indices.Services.TemplateNumReplicas = cfg.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.NumReplicaServiceFlag()))
80+
c.Indices.Dependencies.TemplateNumReplicas = cfg.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.NumReplicaDependenciesFlag()))
81+
c.Indices.Sampling.TemplateNumReplicas = cfg.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.NumShardSamplingFlag()))
82+
83+
if v.GetInt(prioritySpanTemplate) > 0 || v.GetInt(priorityServiceTemplate) > 0 {
84+
log.Printf("using deprecated %s or %s", shards, replicas)
85+
}
86+
87+
deprecatedPrioritySpanTemplate := v.GetInt(prioritySpanTemplate)
88+
deprecatedPriorityServiceTemplate := v.GetInt(priorityServiceTemplate)
89+
90+
if deprecatedPriorityServiceTemplate > 0 || deprecatedPrioritySpanTemplate > 0 {
91+
log.Printf("using deprecated %s or %s", prioritySpanTemplate, priorityServiceTemplate)
92+
}
93+
94+
c.Indices.Spans.TemplatePriority = cfg.LegacyFlagValue(deprecatedPrioritySpanTemplate, v.GetInt(cfg.PrioritySpanTemplateFlag()))
95+
c.Indices.Services.TemplatePriority = cfg.LegacyFlagValue(deprecatedPriorityServiceTemplate, v.GetInt(cfg.PriorityServiceTemplateFlag()))
6296
c.Indices.Dependencies.TemplatePriority = v.GetInt64(cfg.PriorityDependenciesTemplateFlag())
6397
c.Indices.Sampling.TemplatePriority = v.GetInt64(cfg.PrioritySamplingTemplateFlag())
6498
}

cmd/es-rollover/app/init/flags_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func TestBindFlags(t *testing.T) {
3434
v.BindPFlags(command.PersistentFlags())
3535

3636
err := command.ParseFlags([]string{
37-
"--num-shards-spans=8",
38-
"--num-replicas-spans=16",
39-
"--priority-spans-template=300",
40-
"--priority-services-template=301",
37+
"--shards=8",
38+
"--replicas=16",
39+
"--priority-span-template=300",
40+
"--priority-service-template=301",
4141
"--priority-dependencies-template=302",
4242
"--priority-sampling-template=303",
4343
})

cmd/esmapping-generator/app/flags.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
package app
1616

1717
import (
18-
"github.com/spf13/cobra"
19-
2018
"github.com/jaegertracing/jaeger/pkg/es/config"
19+
"github.com/spf13/cobra"
20+
"log"
2121
)
2222

2323
// Options represent configurable parameters for jaeger-esmapping-generator
@@ -33,13 +33,16 @@ type Options struct {
3333
const (
3434
mappingFlag = "mapping"
3535
esVersionFlag = "es-version"
36+
shardsFlag = "shards"
37+
replicasFlag = "replicas"
3638
indexPrefixFlag = "index-prefix"
3739
useILMFlag = "use-ilm"
3840
ilmPolicyNameFlag = "ilm-policy-name"
3941
)
4042

4143
// AddFlags adds flags for esmapping-generator main program
4244
func (o *Options) AddFlags(command *cobra.Command) {
45+
var deprecatedNumShards, deprecatedReplicaShards int64
4346
command.Flags().StringVar(
4447
&o.Mapping,
4548
mappingFlag,
@@ -50,42 +53,53 @@ func (o *Options) AddFlags(command *cobra.Command) {
5053
esVersionFlag,
5154
7,
5255
"The major Elasticsearch version")
53-
command.Flags().IntVar(
56+
command.Flags().Int64Var(
57+
&deprecatedNumShards,
58+
shardsFlag,
59+
5,
60+
"(deprecated, will be replaced with num-shards-span,num-shards-service,num-shards-sampling,num-shards-dependencies, if .num-shards set, it will be used as global settings for span,service,sampling,dependencies index) The number of shards per index in Elasticsearch")
61+
command.Flags().Int64Var(
62+
&deprecatedReplicaShards,
63+
replicasFlag,
64+
1,
65+
"(deprecated, will be replaced with num-replicas-span,num-replicas-service,num-replicas-sampling,num-replicas-dependencies, if .num-replicas set, it will be used as global settings for span,service,sampling,dependencies index) The number of replicas per index in Elasticsearch")
66+
67+
command.Flags().Int64Var(
5468
&o.Indices.Spans.TemplateNumShards,
55-
config.GetNumShardSpanFlag(),
69+
config.NumShardSpanFlag(),
5670
5,
5771
"The number of shards per span index in Elasticsearch")
58-
command.Flags().IntVar(
72+
command.Flags().Int64Var(
5973
&o.Indices.Spans.TemplateNumReplicas,
6074
config.NumReplicaSpanFlag(),
6175
1,
6276
"The number of replicas per index in Elasticsearch")
63-
command.Flags().IntVar(
77+
command.Flags().Int64Var(
6478
&o.Indices.Services.TemplateNumShards,
65-
config.GetNumShardServiceFlag(),
79+
config.NumShardServiceFlag(),
6680
5,
6781
"The number of shards per service index in Elasticsearch")
68-
command.Flags().IntVar(
82+
command.Flags().Int64Var(
6983
&o.Indices.Services.TemplateNumReplicas,
7084
config.NumReplicaServiceFlag(),
7185
1,
7286
"The number of replicas per service index in Elasticsearch")
73-
command.Flags().IntVar(
87+
command.Flags().Int64Var(
7488
&o.Indices.Dependencies.TemplateNumShards,
7589
config.NumShardDependenciesFlag(),
7690
5,
7791
"The number of shards per dependencies index in Elasticsearch")
78-
command.Flags().IntVar(
92+
command.Flags().Int64Var(
7993
&o.Indices.Dependencies.TemplateNumReplicas,
8094
config.NumReplicaDependenciesFlag(),
8195
1,
8296
"The number of replicas per dependencies index in Elasticsearch")
83-
command.Flags().IntVar(
97+
command.Flags().Int64Var(
8498
&o.Indices.Sampling.TemplateNumShards,
8599
config.NumShardSamplingFlag(),
86100
5,
87101
"The number of shards per sampling index in Elasticsearch")
88-
command.Flags().IntVar(
102+
command.Flags().Int64Var(
89103
&o.Indices.Sampling.TemplateNumReplicas,
90104
config.NumReplicaSamplingFlag(),
91105
1,
@@ -106,6 +120,22 @@ func (o *Options) AddFlags(command *cobra.Command) {
106120
"jaeger-ilm-policy",
107121
"The name of the ILM policy to use if ILM is active")
108122

123+
if deprecatedNumShards > 0 {
124+
log.Printf("using deprecated %s", shardsFlag)
125+
o.Indices.Spans.TemplateNumShards = deprecatedNumShards
126+
o.Indices.Services.TemplateNumShards = deprecatedNumShards
127+
o.Indices.Dependencies.TemplateNumShards = deprecatedNumShards
128+
o.Indices.Sampling.TemplateNumShards = deprecatedNumShards
129+
}
130+
131+
if deprecatedReplicaShards > 0 {
132+
log.Printf("using deprecated %s", replicasFlag)
133+
o.Indices.Spans.TemplateNumReplicas = deprecatedReplicaShards
134+
o.Indices.Services.TemplateNumReplicas = deprecatedReplicaShards
135+
o.Indices.Dependencies.TemplateNumReplicas = deprecatedReplicaShards
136+
o.Indices.Sampling.TemplateNumReplicas = deprecatedReplicaShards
137+
}
138+
109139
// mark mapping flag as mandatory
110140
command.MarkFlagRequired(mappingFlag)
111141
}

cmd/esmapping-generator/app/flags_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func TestOptionsWithDefaultFlags(t *testing.T) {
3131

3232
assert.Equal(t, "", o.Mapping)
3333
assert.Equal(t, uint(7), o.EsVersion)
34-
assert.Equal(t, 5, o.Indices.Spans.TemplateOptions.NumShards)
35-
assert.Equal(t, 5, o.Indices.Services.TemplateOptions.NumShards)
36-
assert.Equal(t, 5, o.Indices.Dependencies.TemplateOptions.NumShards)
37-
assert.Equal(t, 5, o.Indices.Sampling.TemplateOptions.NumShards)
34+
assert.Equal(t, int64(5), o.Indices.Spans.TemplateNumShards)
35+
assert.Equal(t, int64(5), o.Indices.Services.TemplateNumShards)
36+
assert.Equal(t, int64(5), o.Indices.Dependencies.TemplateNumShards)
37+
assert.Equal(t, int64(5), o.Indices.Sampling.TemplateNumShards)
3838

39-
assert.Equal(t, 1, o.Indices.Spans.TemplateOptions.NumReplicas)
40-
assert.Equal(t, 1, o.Indices.Services.TemplateOptions.NumReplicas)
41-
assert.Equal(t, 1, o.Indices.Dependencies.TemplateOptions.NumReplicas)
42-
assert.Equal(t, 1, o.Indices.Sampling.TemplateOptions.NumReplicas)
39+
assert.Equal(t, int64(1), o.Indices.Spans.TemplateNumReplicas)
40+
assert.Equal(t, int64(1), o.Indices.Services.TemplateNumReplicas)
41+
assert.Equal(t, int64(1), o.Indices.Dependencies.TemplateNumReplicas)
42+
assert.Equal(t, int64(1), o.Indices.Sampling.TemplateNumReplicas)
4343
assert.Equal(t, "", o.IndexPrefix)
4444
assert.Equal(t, "false", o.UseILM)
4545
assert.Equal(t, "jaeger-ilm-policy", o.ILMPolicyName)
@@ -62,15 +62,15 @@ func TestOptionsWithFlags(t *testing.T) {
6262
require.NoError(t, err)
6363
assert.Equal(t, "jaeger-span", o.Mapping)
6464
assert.Equal(t, uint(7), o.EsVersion)
65-
assert.Equal(t, 5, o.Indices.Spans.TemplateOptions.NumShards)
66-
assert.Equal(t, 5, o.Indices.Services.TemplateOptions.NumShards)
67-
assert.Equal(t, 5, o.Indices.Dependencies.TemplateOptions.NumShards)
68-
assert.Equal(t, 5, o.Indices.Sampling.TemplateOptions.NumShards)
65+
assert.Equal(t, int64(5), o.Indices.Spans.TemplateNumShards)
66+
assert.Equal(t, int64(5), o.Indices.Services.TemplateNumShards)
67+
assert.Equal(t, int64(5), o.Indices.Dependencies.TemplateNumShards)
68+
assert.Equal(t, int64(5), o.Indices.Sampling.TemplateNumShards)
6969

70-
assert.Equal(t, 1, o.Indices.Spans.TemplateOptions.NumReplicas)
71-
assert.Equal(t, 1, o.Indices.Services.TemplateOptions.NumReplicas)
72-
assert.Equal(t, 1, o.Indices.Dependencies.TemplateOptions.NumReplicas)
73-
assert.Equal(t, 1, o.Indices.Sampling.TemplateOptions.NumReplicas)
70+
assert.Equal(t, int64(1), o.Indices.Spans.TemplateNumReplicas)
71+
assert.Equal(t, int64(1), o.Indices.Services.TemplateNumReplicas)
72+
assert.Equal(t, int64(1), o.Indices.Dependencies.TemplateNumReplicas)
73+
assert.Equal(t, int64(1), o.Indices.Sampling.TemplateNumReplicas)
7474
assert.Equal(t, "test", o.IndexPrefix)
7575
assert.Equal(t, "true", o.UseILM)
7676
assert.Equal(t, "jaeger-test-policy", o.ILMPolicyName)

cmd/esmapping-generator/app/renderer/render_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestIsValidOption(t *testing.T) {
4747
}
4848

4949
func Test_getMappingAsString(t *testing.T) {
50-
indicesOption := config.Indices{Spans: config.IndexOptions{TemplateOptions: config.TemplateOptions{NumShards: 5, NumReplicas: 1}}}
50+
indicesOption := config.Indices{Spans: config.IndexOptions{TemplateNumShards: 5, TemplateNumReplicas: 1}}
5151
tests := []struct {
5252
name string
5353
args app.Options

pkg/es/config/flagutils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ func IndexRolloverFrequencySamplingFlag() string {
110110
func IndexRolloverFrequencyDependenciesFlag() string {
111111
return rolloverFrequency(DEPENDENCIES)
112112
}
113+
114+
func LegacyFlagValue(deprecatedFlagValue, newValue int) int64 {
115+
if deprecatedFlagValue > 0 {
116+
return int64(deprecatedFlagValue)
117+
} else {
118+
return int64(newValue)
119+
}
120+
}

plugin/storage/es/options.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,6 @@ func (opt *Options) InitFromViper(v *viper.Viper) {
352352
}
353353

354354
func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
355-
overrideIndexShardsNums := func(deprecatedNum, newNum int) int64 {
356-
if deprecatedNum > 0 {
357-
return int64(deprecatedNum)
358-
} else {
359-
return int64(newNum)
360-
}
361-
}
362-
363355
cfg.Username = v.GetString(cfg.namespace + suffixUsername)
364356
cfg.Password = v.GetString(cfg.namespace + suffixPassword)
365357
cfg.TokenFilePath = v.GetString(cfg.namespace + suffixTokenPath)
@@ -376,15 +368,16 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
376368
if deprecatedReplicaShards > 0 || deprecatedNumShards > 0 {
377369
log.Printf("using deprecated %s or %s", suffixNumShards, suffixNumReplicas)
378370
}
379-
cfg.Indices.Spans.TemplateNumShards = overrideIndexShardsNums(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardSpanFlag()))
380-
cfg.Indices.Services.TemplateNumShards = overrideIndexShardsNums(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardServiceFlag()))
381-
cfg.Indices.Sampling.TemplateNumShards = overrideIndexShardsNums(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardSamplingFlag()))
382-
cfg.Indices.Dependencies.TemplateNumShards = overrideIndexShardsNums(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardDependenciesFlag()))
383-
384-
cfg.Indices.Spans.TemplateNumReplicas = overrideIndexShardsNums(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaSpanFlag()))
385-
cfg.Indices.Services.TemplateNumReplicas = overrideIndexShardsNums(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaServiceFlag()))
386-
cfg.Indices.Sampling.TemplateNumReplicas = overrideIndexShardsNums(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaSamplingFlag()))
387-
cfg.Indices.Dependencies.TemplateNumReplicas = overrideIndexShardsNums(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaDependenciesFlag()))
371+
372+
cfg.Indices.Spans.TemplateNumShards = config.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardSpanFlag()))
373+
cfg.Indices.Services.TemplateNumShards = config.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardServiceFlag()))
374+
cfg.Indices.Sampling.TemplateNumShards = config.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardSamplingFlag()))
375+
cfg.Indices.Dependencies.TemplateNumShards = config.LegacyFlagValue(deprecatedNumShards, v.GetInt(cfg.namespace+suffix+config.NumShardDependenciesFlag()))
376+
377+
cfg.Indices.Spans.TemplateNumReplicas = config.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaSpanFlag()))
378+
cfg.Indices.Services.TemplateNumReplicas = config.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaServiceFlag()))
379+
cfg.Indices.Sampling.TemplateNumReplicas = config.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaSamplingFlag()))
380+
cfg.Indices.Dependencies.TemplateNumReplicas = config.LegacyFlagValue(deprecatedReplicaShards, v.GetInt(cfg.namespace+suffix+config.NumReplicaDependenciesFlag()))
388381

389382
cfg.Indices.Spans.TemplatePriority = v.GetInt64(cfg.namespace + suffix + config.PrioritySpanTemplateFlag())
390383
cfg.Indices.Services.TemplatePriority = v.GetInt64(cfg.namespace + suffix + config.PriorityServiceTemplateFlag())

0 commit comments

Comments
 (0)