Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Elasticsearch ILM Polices #2454

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bfb2e87
#2048 - Adds support for Elasticsearch ILM Polices
bhiravabhatla Sep 3, 2020
6acf5da
#2048 - Fixes index templates to work well with Index prefixes
bhiravabhatla Sep 4, 2020
17a8e1c
#2048 - Modify existing index templates to use ILM - avoid creating n…
bhiravabhatla Sep 26, 2020
06896ec
Merge branch 'master' into master
bhiravabhatla Sep 26, 2020
5f0dac7
#2048 - Fix perform_action method call by passing missing argument
bhiravabhatla Sep 26, 2020
f24f9fa
Merge branch 'master' into master
bhiravabhatla Oct 22, 2020
09ba770
Merge branch 'master' into master
bhiravabhatla Nov 27, 2020
fe5938f
#2048[WIP] - Add support for enabling ILM using command line param
bhiravabhatla Dec 4, 2020
f02553e
#2048[WIP] - Rebasing with upstream master
bhiravabhatla Dec 4, 2020
1af12df
#2048[WIP] - Fix lint issues
bhiravabhatla Dec 5, 2020
0f5bb18
#2048[WIP] - Fix integration tests and remobe ES_USE_ILM parameter fr…
bhiravabhatla Dec 5, 2020
8d3c483
#2048[WIP] - Fix failing es-otel-exporter-integration-test
bhiravabhatla Dec 5, 2020
e5fda11
#2048[WIP] - Implement suggested feedback and add integration test fo…
bhiravabhatla Dec 12, 2020
016f626
Merge branch 'master' of https://github.com/jaegertracing/jaeger
bhiravabhatla Dec 12, 2020
f524da3
#2048[WIP] - Fix lint issues
bhiravabhatla Dec 12, 2020
0076eaf
#2048[WIP] - Add write_index setting only if use_ilm is enabled & fix…
bhiravabhatla Dec 13, 2020
653b861
#2048[WIP] - Fix failing exporter integration tests
bhiravabhatla Dec 13, 2020
526f214
Update plugin/storage/es/options.go
bhiravabhatla Dec 14, 2020
8a51584
2048[WIP] - Implement @albertteoh feedback on error variable names an…
bhiravabhatla Dec 19, 2020
fcbf676
Fix fmt issue
bhiravabhatla Dec 19, 2020
a3e8f0e
Fix misleading use-alias help doc (#2692)
albertteoh Dec 15, 2020
8e0b750
#2048[WIP] - Fix failing build and implement feedback on escaping quotes
bhiravabhatla Dec 19, 2020
e2a0fee
#2048[WIP] - Add integration test to check index template names with …
bhiravabhatla Dec 19, 2020
3f31372
#2048[WIP] - Add check to fail if delete ILM policy fails
bhiravabhatla Dec 19, 2020
aacf4c9
#2048[WIP] - Move Index rollover tests to another file
bhiravabhatla Dec 19, 2020
77a8a17
#2048[WIP] - Skip TestIndexRollover_FailIfILMNotPresent test for es v…
bhiravabhatla Dec 19, 2020
4755013
#2048[WIP] - Clean ES before running rollover test for ES version < 7
bhiravabhatla Dec 19, 2020
667a511
Update plugin/storage/es/options.go
bhiravabhatla Dec 14, 2020
3696256
#2048[WIP] - Replace external dependency for rendering templates with…
bhiravabhatla Jan 16, 2021
4b044bc
Fix potential cross-site scripting issues (#2697)
yurishkuro Dec 20, 2020
877175c
Remove 'Report Security Issue' link since GitHub already adds it prom…
yurishkuro Dec 21, 2020
f57c970
Add gh action for hotrod ci jobs (#2702)
Ashmita152 Dec 24, 2020
c514c91
Clean-up "tcollector" references (#2704)
sniperking1234 Dec 25, 2020
183af3c
Fix flaky TestHotReloadUIConfigTempFile (#2713)
albertteoh Jan 7, 2021
d1e9dc4
[pkg/queue] Add `StartConsumersWithFactory` function (#2714)
mx-psi Jan 7, 2021
4c8ad45
[mem store] Return clones of spans to prevent in-place changes by adj…
bobrik Jan 9, 2021
602b943
Show plaintext as supported Kafka auth option in CLI help (#2721)
pdepaepe Jan 11, 2021
00b7daa
[agent] Add metrics to show connections status between agent and coll…
WalkerWang731 Jan 13, 2021
b980e87
[refactor] Minor clean-up of #2657 (#2728)
yurishkuro Jan 13, 2021
5b80343
[tests] Increase timeout for TestGRPCResolverRoundRobin (#2729)
yurishkuro Jan 14, 2021
dc1b855
Add ability to use JS file for UI configuration (jaeger-ui/#123) (#2707)
th3M1ke Jan 14, 2021
76256d6
Add support for Kafka SASL/PLAIN authentication via SCRAM-SHA-256 or …
WalkerWang731 Jan 14, 2021
1a888aa
#2048[WIP] - Fix fmt issues
bhiravabhatla Jan 16, 2021
9bec1a4
#2048[WIP] - Implement feedback on CLI - use cobra & unit tests
bhiravabhatla Jan 22, 2021
01654f9
Increase HotROD CI test timeout to 30sec
yurishkuro Jan 18, 2021
ea4e71c
Update jaeger-ui to use memoization for getConfig (#2732)
th3M1ke Jan 18, 2021
23f53dd
Fix broken CNCF logo link
yurishkuro Jan 18, 2021
ef16c6a
TLS support for HTTP API of Query server (#2337)
rjs211 Jan 19, 2021
0f0cc90
Add ability to remove inactive maintainers; introduce Emeritus status…
yurishkuro Jan 19, 2021
d4895d7
Transition black-adder and tiffon to Emeritus Maintainers (#2735)
yurishkuro Jan 20, 2021
6864653
Enable stale bot for PRs and questions (#2731)
yurishkuro Jan 20, 2021
6f8bfb1
Expose cache ttl for es span writer index+service (#2737)
necrolyte2 Jan 21, 2021
d85d954
#2048[WIP] - Fix failing integration tests and lint
bhiravabhatla Jan 22, 2021
c0f3e93
#2048[WIP] - Fix fmt issues
bhiravabhatla Jan 22, 2021
09e4e9d
#2048[WIP] - add tests to increase coverage
bhiravabhatla Jan 22, 2021
a3b465b
Fix merge conflicts
bhiravabhatla Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +25 to +28
Copy link
Contributor

@albertteoh albertteoh Jan 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these stem from needing to mock out the function's behaviour. You've already done the hard work of creating interfaces and mocks for these, why not use them?

Consider removing these and please refer to the code suggestions below.


// GetMappingAsString returns rendered index templates as string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest simplifying this to what's below. What's changed:

  • Use map of allowed values that acts as a set for faster and simpler "contains" check.
  • Pass in the TemplateBuilder interface to allow mocking. Then just pass esTemplate.TextTemplateBuilder{} into this function from main().
  • Simplify the logic in this function.
var allowedValues = map[string] struct{} {
	"jaeger-span": {},
	"jaeger-service": {},
}

// GetMappingAsString returns rendered index templates as string
func GetMappingAsString(builder esTemplate.TemplateBuilder, opt *app.Options) (string, error) {
	if opt.EsVersion == 7 {
		enableILM, err := strconv.ParseBool(opt.UseILM)
		if err != nil {
			return "", err
		}
		return es.FixMapping(builder, es.LoadMapping("/"+opt.Mapping+"-7.json"), opt.Shards, opt.Replicas, opt.EsPrefix, enableILM)
	}
	return es.FixMapping(builder, es.LoadMapping("/"+opt.Mapping+".json"), opt.Shards, opt.Replicas, "", false)
}

// IsValidOption checks if passed option is a valid index template.
func IsValidOption(val string) bool {
	_, ok := allowedValues[val]
	return ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in new PR

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