Skip to content

Commit

Permalink
jaegertracing#2047 - Add ILM support for managing jaeger indices in e…
Browse files Browse the repository at this point in the history
…lasticsearch

Signed-off-by: santosh <bsantosh@thoughtworks.com>
  • Loading branch information
bhiravabhatla committed Jan 25, 2021
1 parent 2ff0a3d commit cab597a
Show file tree
Hide file tree
Showing 35 changed files with 1,269 additions and 154 deletions.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,19 @@ test-compile-es-scripts:

.PHONY: index-cleaner-integration-test
index-cleaner-integration-test: docker-images-elastic
# Expire tests results for storage integration tests since the environment might change
# Expire test results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_cleaner $(STORAGE_PKGS) | $(COLORIZE)"

.PHONY: index-rollover-integration-test
index-rollover-integration-test: docker-images-elastic
# Expire test results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_rollover $(STORAGE_PKGS) | $(COLORIZE)"


.PHONY: token-propagation-integration-test
token-propagation-integration-test:
go clean -testcache
Expand Down Expand Up @@ -217,6 +225,14 @@ build-tracegen:
build-anonymizer:
$(GOBUILD) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) ./cmd/anonymizer/main.go

.PHONY: build-templatizer
build-templatizer:
$(GOBUILD) -o ./plugin/storage/es/templatizer-$(GOOS)-$(GOARCH) ./cmd/templatizer/main.go

.PHONY: build-templatizer-linux
build-templatizer-linux:
GOOS=linux GOARCH=amd64 $(GOBUILD) -o ./plugin/storage/es/templatizer ./cmd/templatizer/main.go

.PHONY: docker-hotrod
docker-hotrod:
GOOS=linux $(MAKE) build-examples
Expand Down Expand Up @@ -336,7 +352,7 @@ docker-images-cassandra:
@echo "Finished building jaeger-cassandra-schema =============="

.PHONY: docker-images-elastic
docker-images-elastic:
docker-images-elastic: build-templatizer-linux
docker build -t $(DOCKER_NAMESPACE)/jaeger-es-index-cleaner:${DOCKER_TAG} plugin/storage/es
docker build -t $(DOCKER_NAMESPACE)/jaeger-es-rollover:${DOCKER_TAG} plugin/storage/es -f plugin/storage/es/Dockerfile.rollover
@echo "Finished building jaeger-es-indices-clean =============="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"

esTemplate "github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/plugin/storage/es"
)

Expand All @@ -31,7 +32,10 @@ func newExporter(ctx context.Context, config *Config, params component.ExporterC
return nil, err
}
if config.Primary.IsCreateIndexTemplates() {
spanMapping, serviceMapping := es.GetSpanServiceMappings(esCfg.GetNumShards(), esCfg.GetNumReplicas(), uint(w.esClientVersion()))
spanMapping, serviceMapping, err := es.GetSpanServiceMappings(esTemplate.TextTemplateBuilder{}, esCfg.GetNumShards(), esCfg.GetNumReplicas(), uint(w.esClientVersion()), esCfg.GetIndexPrefix(), esCfg.GetUseILM())
if err != nil {
return nil, err
}
if err = w.CreateTemplates(ctx, spanMapping, serviceMapping); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/esclient"
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/reader/es/esdependencyreader"
"github.com/jaegertracing/jaeger/cmd/opentelemetry/app/internal/reader/es/esspanreader"
esTemplate "github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/es"
Expand Down Expand Up @@ -104,7 +105,10 @@ func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
return err
}
esVersion := uint(w.esClientVersion())
spanMapping, serviceMapping := es.GetSpanServiceMappings(numShards, numReplicas, esVersion)
spanMapping, serviceMapping, err := es.GetSpanServiceMappings(esTemplate.TextTemplateBuilder{}, numShards, numReplicas, esVersion, "", false)
if err != nil {
return err
}
err = w.CreateTemplates(context.Background(), spanMapping, serviceMapping)
if err != nil {
return err
Expand All @@ -127,7 +131,10 @@ func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
})
s.SpanReader = reader

depMapping := es.GetDependenciesMappings(numShards, numReplicas, esVersion)
depMapping, err := es.GetDependenciesMappings(esTemplate.TextTemplateBuilder{}, numShards, numReplicas, esVersion)
if err != nil {
return err
}
depStore := esdependencyreader.NewDependencyStore(elasticsearchClient, s.logger, indexPrefix, indexDateLayout, defaultMaxDocCount)
if err := depStore.CreateTemplates(depMapping); err != nil {
return nil
Expand Down
2 changes: 2 additions & 0 deletions cmd/opentelemetry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,10 @@ github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv
github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5/go.mod h1:ppEjwdhyy7Y31EnHRDm1JkChoC7LXIJ7Ex0VYLWtZtQ=
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad/go.mod h1:Hy8o65+MXnS6EwGElrSRjUzQDLXreJlzYLlWiHtt8hM=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
Expand Down
81 changes: 81 additions & 0 deletions cmd/templatizer/app/flags.go
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)
}
57 changes: 57 additions & 0 deletions cmd/templatizer/app/flags_test.go
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)
}
61 changes: 61 additions & 0 deletions cmd/templatizer/app/renderer/render.go
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
}
Loading

0 comments on commit cab597a

Please sign in to comment.