Skip to content

Commit

Permalink
polish review
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredTan95 committed Aug 8, 2024
1 parent df4f3e1 commit f7efa32
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 262 deletions.
40 changes: 20 additions & 20 deletions cmd/es-rollover/app/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ type Config struct {
func (*Config) AddFlags(flags *flag.FlagSet) {
flags.Int64(cfg.GetNumShardSpanFlag(), 5, "Number of span index shards")
flags.Int64(cfg.GetNumShardServiceFlag(), 5, "Number of service index shards")
flags.Int64(cfg.GetNumShardDependenciesFlag(), 5, "Number of dependencies index shards")
flags.Int64(cfg.GetNumShardSamplingFlag(), 5, "Number of sampling index shards")
flags.Int64(cfg.NumShardDependenciesFlag(), 5, "Number of dependencies index shards")
flags.Int64(cfg.NumShardSamplingFlag(), 5, "Number of sampling index shards")

flags.Int64(cfg.GetNumReplicasSpanFlag(), 1, "Number of span index replicas")
flags.Int64(cfg.GetNumReplicasServiceFlag(), 1, "Number of services index replicas")
flags.Int64(cfg.GetNumReplicasDependenciesFlag(), 1, "Number of dependencies index replicas")
flags.Int64(cfg.GetNumReplicasSamplingFlag(), 1, "Number of sampling index replicas")
flags.Int64(cfg.NumReplicaSpanFlag(), 1, "Number of span index replicas")
flags.Int64(cfg.NumReplicaServiceFlag(), 1, "Number of services index replicas")
flags.Int64(cfg.NumReplicaDependenciesFlag(), 1, "Number of dependencies index replicas")
flags.Int64(cfg.NumReplicaSamplingFlag(), 1, "Number of sampling index replicas")

flags.Int64(cfg.GetPrioritySpanTemplate(), 0, "Priority of jaeger-span index template (ESv8 only)")
flags.Int64(cfg.GetPriorityServiceTemplate(), 0, "Priority of jaeger-service index template (ESv8 only)")
flags.Int64(cfg.GetPriorityDependenciesTemplate(), 0, "Priority of jaeger-dependencies index template (ESv8 only)")
flags.Int64(cfg.GetPrioritySamplingTemplate(), 0, "Priority of jaeger-sampling index template (ESv8 only)")
flags.Int64(cfg.PrioritySpanTemplate(), 0, "Priority of jaeger-span index template (ESv8 only)")
flags.Int64(cfg.PriorityServiceTemplate(), 0, "Priority of jaeger-service index template (ESv8 only)")
flags.Int64(cfg.PriorityDependenciesTemplate(), 0, "Priority of jaeger-dependencies index template (ESv8 only)")
flags.Int64(cfg.PrioritySamplingTemplate(), 0, "Priority of jaeger-sampling index template (ESv8 only)")
}

// InitFromViper initializes config from viper.Viper.
func (c *Config) InitFromViper(v *viper.Viper) {
c.Indices.Spans.TemplateNumShards = v.GetInt(cfg.GetNumShardSpanFlag())
c.Indices.Spans.TemplateNumReplicas = v.GetInt(cfg.GetNumReplicasSpanFlag())
c.Indices.Spans.TemplateNumReplicas = v.GetInt(cfg.NumReplicaSpanFlag())
c.Indices.Services.TemplateNumShards = v.GetInt(cfg.GetNumShardServiceFlag())
c.Indices.Services.TemplateNumReplicas = v.GetInt(cfg.GetNumReplicasServiceFlag())
c.Indices.Dependencies.TemplateNumShards = v.GetInt(cfg.GetNumShardDependenciesFlag())
c.Indices.Dependencies.TemplateNumReplicas = v.GetInt(cfg.GetNumReplicasDependenciesFlag())
c.Indices.Sampling.TemplateNumShards = v.GetInt(cfg.GetNumShardSamplingFlag())
c.Indices.Sampling.TemplateNumReplicas = v.GetInt(cfg.GetNumShardSamplingFlag())
c.Indices.Spans.TemplatePriority = v.GetInt(cfg.GetPrioritySpanTemplate())
c.Indices.Services.TemplatePriority = v.GetInt(cfg.GetPriorityServiceTemplate())
c.Indices.Dependencies.TemplatePriority = v.GetInt(cfg.GetPriorityDependenciesTemplate())
c.Indices.Sampling.TemplatePriority = v.GetInt(cfg.GetPrioritySamplingTemplate())
c.Indices.Services.TemplateNumReplicas = v.GetInt(cfg.NumReplicaServiceFlag())
c.Indices.Dependencies.TemplateNumShards = v.GetInt(cfg.NumShardDependenciesFlag())
c.Indices.Dependencies.TemplateNumReplicas = v.GetInt(cfg.NumReplicaDependenciesFlag())
c.Indices.Sampling.TemplateNumShards = v.GetInt(cfg.NumShardSamplingFlag())
c.Indices.Sampling.TemplateNumReplicas = v.GetInt(cfg.NumShardSamplingFlag())
c.Indices.Spans.TemplatePriority = v.GetInt(cfg.PrioritySpanTemplate())
c.Indices.Services.TemplatePriority = v.GetInt(cfg.PriorityServiceTemplate())
c.Indices.Dependencies.TemplatePriority = v.GetInt(cfg.PriorityDependenciesTemplate())
c.Indices.Sampling.TemplatePriority = v.GetInt(cfg.PrioritySamplingTemplate())
}
12 changes: 6 additions & 6 deletions cmd/esmapping-generator/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o *Options) AddFlags(command *cobra.Command) {
"The number of shards per span index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Spans.TemplateNumReplicas,
config.GetNumReplicasSpanFlag(),
config.NumReplicaSpanFlag(),
1,
"The number of replicas per index in Elasticsearch")
command.Flags().IntVar(
Expand All @@ -67,27 +67,27 @@ func (o *Options) AddFlags(command *cobra.Command) {
"The number of shards per service index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Services.TemplateNumReplicas,
config.GetNumReplicasServiceFlag(),
config.NumReplicaServiceFlag(),
1,
"The number of replicas per service index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Dependencies.TemplateNumShards,
config.GetNumShardDependenciesFlag(),
config.NumShardDependenciesFlag(),
5,
"The number of shards per dependencies index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Dependencies.TemplateNumReplicas,
config.GetNumReplicasDependenciesFlag(),
config.NumReplicaDependenciesFlag(),
1,
"The number of replicas per dependencies index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Sampling.TemplateNumShards,
config.GetNumShardSamplingFlag(),
config.NumShardSamplingFlag(),
5,
"The number of shards per sampling index in Elasticsearch")
command.Flags().IntVar(
&o.Indices.Sampling.TemplateNumReplicas,
config.GetNumReplicasSamplingFlag(),
config.NumReplicaSamplingFlag(),
1,
"The number of replicas per sampling index in Elasticsearch")
command.Flags().StringVar(
Expand Down
8 changes: 3 additions & 5 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type TemplateOptions struct {
type IndexOptions struct {
DateLayout string `mapstructure:"date_layout"`
RolloverFrequency string `mapstructure:"rollover_frequency"` // "hour" or "day"
TemplatePriority int `mapstructure:"template_priority"`
TemplateNumShards int `mapstructure:"template_num_shards"`
TemplateNumReplicas int `mapstructure:"template_num_replicas"`
TemplatePriority int64 `mapstructure:"template_priority"`
TemplateNumShards int64 `mapstructure:"template_num_shards"`
TemplateNumReplicas int64 `mapstructure:"template_num_replicas"`
}

// Indices describes different configuration options for each index type
Expand All @@ -80,8 +80,6 @@ type Configuration struct {
SnifferTLSEnabled bool `mapstructure:"sniffer_tls_enabled"`
MaxDocCount int `mapstructure:"-"` // Defines maximum number of results to fetch from storage per query
MaxSpanAge time.Duration `mapstructure:"-"` // configures the maximum lookback on span reads
NumShards int64 `mapstructure:"num_shards"`
NumReplicas int64 `mapstructure:"num_replicas"`
Timeout time.Duration `mapstructure:"-"`
BulkSize int `mapstructure:"-"`
BulkWorkers int `mapstructure:"-"`
Expand Down
86 changes: 54 additions & 32 deletions pkg/es/config/flagutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,94 @@ import "fmt"
type IndexType string

const (
SPAN IndexType = "span"
SERVICE IndexType = "service"
SPAN IndexType = "spans"
SERVICE IndexType = "services"
DEPENDENCIES IndexType = "dependencies"
SAMPLING IndexType = "sampling"

numShards = "num-shards-"
numReplicas = "num-replicas-"
numShards = "num-shards-%s"
numReplicas = "num-replicas-%s"
priority = "priority-%s-template"

indexRolloverFrequency = "index-rollover-frequency-%s"
)

func NumShardSpanFlag() string {
return getNumShardPrefix(SPAN)
return numShardPrefix(SPAN)
}

func GetNumShardsServiceFlag() string {
return getNumShardPrefix(SERVICE)
func NumShardServiceFlag() string {
return numShardPrefix(SERVICE)
}

func GetNumShardSamplingFlag() string {
return getNumShardPrefix(SAMPLING)
func NumShardSamplingFlag() string {
return numShardPrefix(SAMPLING)
}

func GetNumShardDependenciesFlag() string {
return getNumShardPrefix(DEPENDENCIES)
func NumShardDependenciesFlag() string {
return numShardPrefix(DEPENDENCIES)
}

func GetNumReplicasSpanFlag() string {
return getNumReplicasPrefix(SPAN)
func NumReplicaSpanFlag() string {
return numReplicaPrefix(SPAN)
}

func GetNumReplicasServiceFlag() string {
return getNumReplicasPrefix(SERVICE)
func NumReplicaServiceFlag() string {
return numReplicaPrefix(SERVICE)
}

func GetNumReplicasDependenciesFlag() string {
return getNumReplicasPrefix(DEPENDENCIES)
func NumReplicaDependenciesFlag() string {
return numReplicaPrefix(DEPENDENCIES)
}

func GetNumReplicasSamplingFlag() string {
return getNumReplicasPrefix(SAMPLING)
func NumReplicaSamplingFlag() string {
return numReplicaPrefix(SAMPLING)
}

func getNumShardPrefix(indexType IndexType) string {
return string(numShards + indexType)
func numShardPrefix(indexType IndexType) string {
return fmt.Sprintf(numShards, indexType)
}

func getNumReplicasPrefix(indexType IndexType) string {
return string(numReplicas + indexType)
func numReplicaPrefix(indexType IndexType) string {
return fmt.Sprintf(numReplicas, indexType)
}

func GetPrioritySpanTemplate() string {
return getPriorityTemplate(SPAN)
func PrioritySpanTemplateFlag() string {
return priorityTemplate(SPAN)
}

func GetPriorityServiceTemplate() string {
return getPriorityTemplate(SERVICE)
func PriorityServiceTemplateFlag() string {
return priorityTemplate(SERVICE)
}

func GetPriorityDependenciesTemplate() string {
return getPriorityTemplate(DEPENDENCIES)
func PriorityDependenciesTemplateFlag() string {
return priorityTemplate(DEPENDENCIES)
}

func GetPrioritySamplingTemplate() string {
return getPriorityTemplate(SAMPLING)
func PrioritySamplingTemplateFlag() string {
return priorityTemplate(SAMPLING)
}

func getPriorityTemplate(indexType IndexType) string {
func priorityTemplate(indexType IndexType) string {
return fmt.Sprintf(priority, indexType)
}

func rolloverFrequency(indexType IndexType) string {
return fmt.Sprintf(indexRolloverFrequency, indexType)
}

func IndexRolloverFrequencySpanFlag() string {
return rolloverFrequency(SPAN)
}

func IndexRolloverFrequencyServiceFlag() string {
return rolloverFrequency(SERVICE)
}

func IndexRolloverFrequencySamplingFlag() string {
return rolloverFrequency(SAMPLING)
}

func IndexRolloverFrequencyDependenciesFlag() string {
return rolloverFrequency(DEPENDENCIES)
}
18 changes: 9 additions & 9 deletions pkg/es/config/flagutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ func TestGetFlags(t *testing.T) {
{
name: "span-options",
indexType: SPAN,
expectedNumShardsFlag: "num-shards-span",
expectedNumReplicasFlag: "num-replicas-span",
expectedPriorityFlag: "priority-span-template",
expectedNumShardsFlag: "num-shards-spans",
expectedNumReplicasFlag: "num-replicas-spans",
expectedPriorityFlag: "priority-spans-template",
},
{
name: "service-options",
indexType: SERVICE,
expectedNumShardsFlag: "num-shards-service",
expectedNumReplicasFlag: "num-replicas-service",
expectedPriorityFlag: "priority-service-template",
expectedNumShardsFlag: "num-shards-services",
expectedNumReplicasFlag: "num-replicas-services",
expectedPriorityFlag: "priority-services-template",
},
}

for _, tt := range testCase {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expectedNumShardsFlag, getNumShardPrefix(tt.indexType))
assert.Equal(t, tt.expectedNumReplicasFlag, getNumReplicasPrefix(tt.indexType))
assert.Equal(t, tt.expectedPriorityFlag, getPriorityTemplate(tt.indexType))
assert.Equal(t, tt.expectedNumShardsFlag, numShardPrefix(tt.indexType))
assert.Equal(t, tt.expectedNumReplicasFlag, numReplicaPrefix(tt.indexType))
assert.Equal(t, tt.expectedPriorityFlag, priorityTemplate(tt.indexType))
})
}
}
Loading

0 comments on commit f7efa32

Please sign in to comment.