forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jaegertracing#2047 - Add ILM support for managing jaeger indices in e…
…lasticsearch Signed-off-by: santosh <[email protected]>
- Loading branch information
1 parent
2ff0a3d
commit cab597a
Showing
35 changed files
with
1,269 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// 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 app | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Options represent configurable parameters for jaeger-templatizer | ||
type Options struct { | ||
Mapping string | ||
EsVersion int64 | ||
Shards int64 | ||
Replicas int64 | ||
EsPrefix string | ||
UseILM string // using string as util is being used in python and using bool leads to type issues. | ||
} | ||
|
||
const ( | ||
mappingFlag = "mapping" | ||
esVersionFlag = "esVersion" | ||
shardsFlag = "shards" | ||
replicasFlag = "replicas" | ||
esPrefixFlag = "esPrefix" | ||
useILMFlag = "useILM" | ||
) | ||
|
||
// AddFlags adds flags for templatizer main program | ||
func (o *Options) AddFlags(command *cobra.Command) { | ||
command.Flags().StringVarP( | ||
&o.Mapping, | ||
mappingFlag, | ||
"m", | ||
"", | ||
"Pass either jaeger-span or jaeger-service") | ||
command.Flags().Int64VarP( | ||
&o.EsVersion, | ||
esVersionFlag, | ||
"v", | ||
7, | ||
"the major Elasticsearch version") | ||
command.Flags().Int64VarP( | ||
&o.Shards, | ||
shardsFlag, | ||
"s", | ||
5, | ||
"the number of shards per index in Elasticsearch") | ||
command.Flags().Int64VarP( | ||
&o.Replicas, | ||
replicasFlag, | ||
"r", | ||
1, | ||
"the number of replicas per index in Elasticsearch") | ||
command.Flags().StringVarP( | ||
&o.EsPrefix, | ||
esPrefixFlag, | ||
"e", | ||
"", | ||
"specifies index prefix") | ||
command.Flags().StringVarP( | ||
&o.UseILM, | ||
useILMFlag, | ||
"u", | ||
"false", | ||
"set to true to use ILM for managing lifecycle of jaeger indices") | ||
|
||
// mark mapping flag as mandatory | ||
command.MarkFlagRequired(mappingFlag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2020 The Jaeger Authors. | ||
// | ||
// 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 app | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptionsWithDefaultFlags(t *testing.T) { | ||
o := Options{} | ||
c := cobra.Command{} | ||
o.AddFlags(&c) | ||
|
||
assert.Equal(t, "", o.Mapping) | ||
assert.Equal(t, int64(7), o.EsVersion) | ||
assert.Equal(t, int64(5), o.Shards) | ||
assert.Equal(t, int64(1), o.Replicas) | ||
assert.Equal(t, "", o.EsPrefix) | ||
assert.Equal(t, "false", o.UseILM) | ||
} | ||
|
||
func TestOptionsWithFlags(t *testing.T) { | ||
o := Options{} | ||
c := cobra.Command{} | ||
|
||
o.AddFlags(&c) | ||
c.ParseFlags([]string{ | ||
"--mapping=jaeger-span", | ||
"--esVersion=6", | ||
"--shards=5", | ||
"--replicas=1", | ||
"--esPrefix=test", | ||
"--useILM=true", | ||
}) | ||
|
||
assert.Equal(t, "jaeger-span", o.Mapping) | ||
assert.Equal(t, int64(6), o.EsVersion) | ||
assert.Equal(t, int64(5), o.Shards) | ||
assert.Equal(t, int64(1), o.Replicas) | ||
assert.Equal(t, "test", o.EsPrefix) | ||
assert.Equal(t, "true", o.UseILM) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// 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 renderer | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/templatizer/app" | ||
esTemplate "github.com/jaegertracing/jaeger/pkg/es" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es" | ||
) | ||
|
||
var fixMappingFunc = es.FixMapping | ||
var loadMappingFunc = es.LoadMapping | ||
var mapping string | ||
var err error | ||
|
||
// GetMappingAsString returns rendered index templates as string | ||
func GetMappingAsString(opt *app.Options) (string, error) { | ||
|
||
if opt.EsVersion == 7 { | ||
enableILM, err := strconv.ParseBool(opt.UseILM) | ||
if err != nil { | ||
return "", err | ||
} | ||
mapping, err = fixMappingFunc(esTemplate.TextTemplateBuilder{}, loadMappingFunc("/"+opt.Mapping+"-7.json"), opt.Shards, opt.Replicas, opt.EsPrefix, enableILM) | ||
if err != nil { | ||
return "", err | ||
} | ||
} else { | ||
mapping, err = fixMappingFunc(esTemplate.TextTemplateBuilder{}, loadMappingFunc("/"+opt.Mapping+".json"), opt.Shards, opt.Replicas, "", false) | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
return mapping, nil | ||
|
||
} | ||
|
||
// IsValidOption checks if passed option is a valid index template. | ||
func IsValidOption(val string) bool { | ||
allowedValues := []string{"jaeger-span", "jaeger-service"} | ||
for _, value := range allowedValues { | ||
if val == value { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.