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#2048[WIP] - Replace external dependency for rendering t…
…emplates with text/template and golang util & Implement feedback on tests Signed-off-by: santosh <bsantosh@thoughtworks.com>
- Loading branch information
1 parent
667a511
commit 3696256
Showing
25 changed files
with
608 additions
and
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 main | ||
|
||
import ( | ||
"flag" | ||
"strconv" | ||
|
||
"go.uber.org/zap" | ||
|
||
esTemplate "github.com/jaegertracing/jaeger/pkg/es" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es" | ||
) | ||
|
||
var logger, _ = zap.NewDevelopment() | ||
var fixMappingFunc = es.FixMapping | ||
var loadMappingFunc = es.LoadMapping | ||
var mapping string | ||
var err error | ||
|
||
func main() { | ||
|
||
mappingName := flag.String("mapping", "", "Pass name of the mapping to parse - should be either jaeger-service or jaeger-span") | ||
esVersion := flag.Int64("esVersion", 7, "Version of ES") | ||
shards := flag.Int64("shards", 3, "Number of shards") | ||
replicas := flag.Int64("replicas", 3, "Number of replicas") | ||
esPrefix := flag.String("esPrefix", "", "Prefix for ES indices") | ||
useILM := flag.String("useILM", "false", "Set to true to enable ILM") | ||
flag.Parse() | ||
if !isValidOption(*mappingName) { | ||
logger.Fatal("please pass either 'jaeger-service' or 'jaeger-span' as argument") | ||
} | ||
parsedMapping, err := getMappingAsString(*mappingName, *esPrefix, *useILM, *esVersion, *shards, *replicas) | ||
if err != nil { | ||
logger.Fatal(err.Error()) | ||
} | ||
print(parsedMapping) | ||
|
||
} | ||
|
||
func getMappingAsString(mappingName, esPrefix, useILM string, esVersion, shards, replicas int64) (string, error) { | ||
|
||
if esVersion == 7 { | ||
enableILM, err := strconv.ParseBool(useILM) | ||
if err != nil { | ||
return "", err | ||
} | ||
mapping, err = fixMappingFunc(esTemplate.TextTemplateBuilder{}, loadMappingFunc("/"+mappingName+"-7.json"), shards, replicas, esPrefix, enableILM) | ||
if err != nil { | ||
return "", err | ||
} | ||
} else { | ||
mapping, err = fixMappingFunc(esTemplate.TextTemplateBuilder{}, loadMappingFunc("/"+mappingName+".json"), shards, replicas, "", false) | ||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
return mapping, nil | ||
|
||
} | ||
|
||
func isValidOption(val string) bool { | ||
allowedValues := []string{"jaeger-span", "jaeger-service"} | ||
for _, value := range allowedValues { | ||
if val == value { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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,108 @@ | ||
// 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 main | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
esTemplate "github.com/jaegertracing/jaeger/pkg/es" | ||
) | ||
|
||
func TestIsValidOption(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg string | ||
expectedValue bool | ||
}{{name: "span mapping", arg: "jaeger-span", expectedValue: true}, | ||
{name: "service mapping", arg: "jaeger-service", expectedValue: true}, | ||
{name: "Invalid mapping", arg: "dependency-service", expectedValue: false}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if got := isValidOption(test.arg); got != test.expectedValue { | ||
t.Errorf("isValidOption() = %v, want %v", got, test.expectedValue) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_getMappingAsString(t *testing.T) { | ||
type args struct { | ||
mappingName string | ||
esPrefix string | ||
useILM string | ||
esVersion int64 | ||
shards int64 | ||
replicas int64 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
fixMappingFunc func(esTemplate.TemplateBuilder, string, int64, int64, string, bool) (string, error) | ||
want string | ||
wantErr bool | ||
}{ | ||
{name: "ES version 7", args: args{"jaeger-span", "test", "true", 7, 5, 5}, | ||
fixMappingFunc: func(esTemplate.TemplateBuilder, string, int64, int64, string, bool) (string, error) { | ||
return "ES version 7", nil | ||
}, | ||
want: "ES version 7", | ||
wantErr: false, | ||
}, | ||
{name: "ES version 6", args: args{"jaeger-service", "test", "false", 6, 5, 5}, | ||
fixMappingFunc: func(esTemplate.TemplateBuilder, string, int64, int64, string, bool) (string, error) { | ||
return "ES version 6", nil | ||
}, | ||
want: "ES version 6", | ||
wantErr: false, | ||
}, | ||
{name: "Parse Error version 6", args: args{"jaeger-service", "test", "false", 6, 5, 5}, | ||
fixMappingFunc: func(esTemplate.TemplateBuilder, string, int64, int64, string, bool) (string, error) { | ||
return "", errors.New("parse error") | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, {name: "Parse Error version 7", args: args{"jaeger-service", "test", "false", 7, 5, 5}, | ||
fixMappingFunc: func(esTemplate.TemplateBuilder, string, int64, int64, string, bool) (string, error) { | ||
return "", errors.New("parse error") | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
oldFixMappingFunc := fixMappingFunc | ||
oldLoadMappingFunc := loadMappingFunc | ||
defer func() { | ||
fixMappingFunc = oldFixMappingFunc | ||
loadMappingFunc = oldLoadMappingFunc | ||
}() | ||
|
||
fixMappingFunc = tt.fixMappingFunc | ||
loadMappingFunc = func(string) string { return "test" } | ||
got, err := getMappingAsString(tt.args.mappingName, tt.args.esPrefix, tt.args.useILM, tt.args.esVersion, tt.args.shards, tt.args.replicas) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getMappingAsString() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("getMappingAsString() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.