Skip to content

Commit

Permalink
jaegertracing#2048 - Implement @yurishkuro's feedback on PR
Browse files Browse the repository at this point in the history
Signed-off-by: santosh <bsantosh@thoughtworks.com>
  • Loading branch information
bhiravabhatla committed Feb 13, 2021
1 parent 4c53450 commit 61049f9
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 52 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ 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-esmapping-generator
build-esmapping-generator:
$(GOBUILD) -o ./plugin/storage/es/esmapping-generator-$(GOOS)-$(GOARCH) ./cmd/esmapping-generator/main.go

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

.PHONY: docker-hotrod
docker-hotrod:
Expand Down Expand Up @@ -352,7 +352,7 @@ docker-images-cassandra:
@echo "Finished building jaeger-cassandra-schema =============="

.PHONY: docker-images-elastic
docker-images-elastic: build-templatizer-linux
docker-images-elastic: build-esmapping-generator-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 @@ -18,7 +18,7 @@ import (
"github.com/spf13/cobra"
)

// Options represent configurable parameters for jaeger-templatizer
// Options represent configurable parameters for jaeger-esmapping-generator
type Options struct {
Mapping string
EsVersion int64
Expand All @@ -30,49 +30,43 @@ type Options struct {

const (
mappingFlag = "mapping"
esVersionFlag = "esVersion"
esVersionFlag = "es-version"
shardsFlag = "shards"
replicasFlag = "replicas"
esPrefixFlag = "esPrefix"
useILMFlag = "useILM"
esPrefixFlag = "es-prefix"
useILMFlag = "use-ilm"
)

// AddFlags adds flags for templatizer main program
// AddFlags adds flags for esmapping-generator main program
func (o *Options) AddFlags(command *cobra.Command) {
command.Flags().StringVarP(
command.Flags().StringVar(
&o.Mapping,
mappingFlag,
"m",
"",
"The index mapping the template will be applied to. Pass either jaeger-span or jaeger-service")
command.Flags().Int64VarP(
command.Flags().Int64Var(
&o.EsVersion,
esVersionFlag,
"v",
7,
"The major Elasticsearch version")
command.Flags().Int64VarP(
command.Flags().Int64Var(
&o.Shards,
shardsFlag,
"s",
5,
"The number of shards per index in Elasticsearch")
command.Flags().Int64VarP(
command.Flags().Int64Var(
&o.Replicas,
replicasFlag,
"r",
1,
"The number of replicas per index in Elasticsearch")
command.Flags().StringVarP(
command.Flags().StringVar(
&o.EsPrefix,
esPrefixFlag,
"p",
"",
"Specifies index prefix")
command.Flags().StringVarP(
command.Flags().StringVar(
&o.UseILM,
useILMFlag,
"i",
"false",
"Set to true to use ILM for managing lifecycle of jaeger indices")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package app

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/spf13/cobra"
Expand All @@ -39,15 +40,15 @@ func TestOptionsWithFlags(t *testing.T) {
c := cobra.Command{}

o.AddFlags(&c)
c.ParseFlags([]string{
err := c.ParseFlags([]string{
"--mapping=jaeger-span",
"--esVersion=6",
"--es-version=6",
"--shards=5",
"--replicas=1",
"--esPrefix=test",
"--useILM=true",
"--es-prefix=test",
"--use-ilm=true",
})

require.NoError(t, err)
assert.Equal(t, "jaeger-span", o.Mapping)
assert.Equal(t, int64(6), o.EsVersion)
assert.Equal(t, int64(5), o.Shards)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package renderer
import (
"strconv"

"github.com/jaegertracing/jaeger/cmd/templatizer/app"
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app"
esTemplate "github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/plugin/storage/es"
)

var allowedValues = map[string]struct{}{
var supportedMappings = map[string]struct{}{
"jaeger-span": {},
"jaeger-service": {},
}
Expand All @@ -41,6 +41,6 @@ func GetMappingAsString(builder esTemplate.TemplateBuilder, opt *app.Options) (s

// IsValidOption checks if passed option is a valid index template.
func IsValidOption(val string) bool {
_, ok := allowedValues[val]
_, ok := supportedMappings[val]
return ok
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/jaegertracing/jaeger/cmd/templatizer/app"
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app"
"github.com/jaegertracing/jaeger/pkg/es/mocks"
)

Expand Down
10 changes: 5 additions & 5 deletions cmd/templatizer/main.go → cmd/esmapping-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/templatizer/app"
"github.com/jaegertracing/jaeger/cmd/templatizer/app/renderer"
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app"
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app/renderer"
"github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/pkg/version"
)
Expand All @@ -31,9 +31,9 @@ func main() {
logger, _ := zap.NewDevelopment()
var options = app.Options{}
var command = &cobra.Command{
Use: "jaeger-templatizer",
Short: "Jaeger templatizer prints rendered mappings as string",
Long: `Jaeger templatizer renders passed templates with provided values and prints rendered output to stdout`,
Use: "jaeger-esmapping-generator",
Short: "Jaeger esmapping-generator prints rendered mappings as string",
Long: `Jaeger esmapping-generator renders passed templates with provided values and prints rendered output to stdout`,
Run: func(cmd *cobra.Command, args []string) {

if !renderer.IsValidOption(options.Mapping) {
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/services/frontend/gen_assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/gorilla/mux v1.7.4
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/grpc-ecosystem/grpc-gateway v1.14.5
github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-hclog v0.15.0
github.com/hashicorp/go-plugin v1.4.0
github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect
github.com/kr/pretty v0.2.1
Expand Down Expand Up @@ -68,7 +68,7 @@ require (
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c
go.mongodb.org/mongo-driver v1.3.2 // indirect
go.uber.org/atomic v1.6.0
go.uber.org/atomic v1.7.0
go.uber.org/automaxprocs v1.4.0
go.uber.org/zap v1.16.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.15.0 h1:qMuK0wxsoW4D0ddCCYwPSTm4KQv1X1ke3WmPWZ0Mvsk=
github.com/hashicorp/go-hclog v0.15.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
Expand Down Expand Up @@ -627,6 +629,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0=
go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Configuration struct {
TLS tlscfg.Options `mapstructure:"tls"`
UseReadWriteAliases bool `mapstructure:"use_aliases"`
CreateIndexTemplates bool `mapstructure:"create_mappings"`
UseILM bool `mapstructure:"-"`
UseILM bool `mapstructure:"use_ilm"`
Version uint `mapstructure:"version"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/es/textTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ type TemplateBuilder interface {
type TextTemplateBuilder struct{}

// Parse is a wrapper for template.Parse
func (t TextTemplateBuilder) Parse(mapping string) (TemplateApplier, error) {
return template.New("mapping").Parse(mapping)
func (t TextTemplateBuilder) Parse(tmpl string) (TemplateApplier, error) {
return template.New("mapping").Parse(tmpl)
}
2 changes: 1 addition & 1 deletion plugin/storage/es/Dockerfile.rollover
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN pip install urllib3==1.24.3
RUN pip install elasticsearch elasticsearch-curator
COPY ./mappings/* /mappings/
COPY esRollover.py /es-rollover/
COPY templatizer /usr/bin/
COPY esmapping-generator /usr/bin/

ENTRYPOINT ["python3", "/es-rollover/esRollover.py"]
4 changes: 2 additions & 2 deletions plugin/storage/es/esRollover.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def str2bool(v):


def fix_mapping(template_name, esVersion, shards, replicas, esprefix, use_ilm):
output = subprocess.Popen(['templatizer', '--mapping', template_name, '--esVersion', str(esVersion),
output = subprocess.Popen(['esmapping-generator', '--mapping', template_name, '--es-version', str(esVersion),
'--shards', str(shards), '--replicas',
str(replicas), '--esPrefix', esprefix, '--useILM', str(use_ilm)],
str(replicas), '--es-prefix', esprefix, '--use-ilm', str(use_ilm)],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
mapping, stderr = output.communicate()
Expand Down
3 changes: 2 additions & 1 deletion plugin/storage/es/spanstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package spanstore

import (
"context"
"strings"
"time"

"github.com/uber/jaeger-lib/metrics"
Expand Down Expand Up @@ -102,7 +103,7 @@ func NewSpanWriter(p SpanWriterParams) *SpanWriter {

// CreateTemplates creates index templates.
func (s *SpanWriter) CreateTemplates(spanTemplate, serviceTemplate, indexPrefix string) error {
if indexPrefix != "" {
if indexPrefix != "" && !strings.HasSuffix(indexPrefix, "-") {
indexPrefix += "-"
}
_, err := s.client.CreateTemplate(indexPrefix + "jaeger-span").Body(spanTemplate).Do(context.Background())
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/model"
esTemplate "github.com/jaegertracing/jaeger/pkg/es"
estemplate "github.com/jaegertracing/jaeger/pkg/es"
eswrapper "github.com/jaegertracing/jaeger/pkg/es/wrapper"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/es"
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *ESStorageIntegration) initSpanstore(allTagsAsFields, archive bool) erro
return err
}
client := eswrapper.WrapESClient(s.client, bp, esVersion)
spanMapping, serviceMapping, err := es.GetSpanServiceMappings(esTemplate.TextTemplateBuilder{}, 5, 1, client.GetVersion(), indexPrefix, false)
spanMapping, serviceMapping, err := es.GetSpanServiceMappings(estemplate.TextTemplateBuilder{}, 5, 1, client.GetVersion(), indexPrefix, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func (s *ESStorageIntegration) initSpanstore(allTagsAsFields, archive bool) erro
MaxDocCount: defaultMaxDocCount,
})
dependencyStore := dependencystore.NewDependencyStore(client, s.logger, indexPrefix, indexDateLayout, defaultMaxDocCount)
depMapping, err := es.GetDependenciesMappings(esTemplate.TextTemplateBuilder{}, 5, 1, client.GetVersion())
depMapping, err := es.GetDependenciesMappings(estemplate.TextTemplateBuilder{}, 5, 1, client.GetVersion())
if err != nil {
return err
}
Expand Down

0 comments on commit 61049f9

Please sign in to comment.