-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: Add esmapping-generator into jaeger binary #6327
base: main
Are you sure you want to change the base?
Conversation
@yurishkuro I think now this is perfectly decoupling the logic for generation in tool and then calling it from jaeger binary. Looking forward to your suggestions! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6327 +/- ##
===========================================
- Coverage 96.27% 50.30% -45.98%
===========================================
Files 372 188 -184
Lines 21283 11411 -9872
===========================================
- Hits 20491 5740 -14751
- Misses 605 5217 +4612
- Partials 187 454 +267
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
"go.uber.org/zap" | ||
) | ||
|
||
func GenerateESMappings(logger *zap.Logger, options app.Options) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this can be in the app/ package
- can be called GenerateMappings ("ES" is implied)
- as a library function it needs to return the results, not print them. The caller can decide what to do with the string.
|
||
fmt.Println(parsedMapping) | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs tests
@@ -0,0 +1,26 @@ | |||
package es |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this package is not a place for commands. Can move it to cmd/esmapping-generator/app/command.go
Short: "Generate Elasticsearch mappings", | ||
Long: "Generate Elasticsearch mappings using jaeger-esmapping-generator functionality", | ||
Run: func(_ *cobra.Command, _ []string) { | ||
if err := renderer.GenerateESMappings(logger, options); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are options
populated?
24c7af6
to
01ad9bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is a user expected to run this?
cmd/all-in-one/main.go
Outdated
@@ -199,6 +200,7 @@ by default uses only in-memory database.`, | |||
command.AddCommand(docs.Command(v)) | |||
command.AddCommand(status.Command(v, ports.CollectorAdminHTTP)) | |||
command.AddCommand(printconfig.Command(v)) | |||
command.AddCommand(esmapping.Command(svc.Logger)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add this to v1 binaries, only cmd/jaeger
cmd/esmapping-generator/main.go
Outdated
"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" | ||
"github.com/jaegertracing/jaeger/plugin/storage/es/mappings" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run make fmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`:~/jaeger$
./jaeger es-mappings --mapping jaeger-span
2025/01/12 17:15:13 application version: git-commit=, git-version=, build-date=
Generating mappings with options: {Mapping:jaeger-span EsVersion:7 Shards:5 Replicas:1 IndexPrefix:jaeger UseILM:false ILMPolicyName:}
{
"index_patterns": "*jaeger-jaeger-span-*",
"settings":{
"index.number_of_shards": 5,
"index.number_of_replicas": 1,
"index.mapping.nested_fields.limit":50,
"index.requests.cache.enable":true
},
"mappings":{
"dynamic_templates":[
{
"span_tags_map":{
"mapping":{
"type":"keyword",
"ignore_above":256
},
"path_match":"tag.*"
}
},
{
"process_tags_map":{
"mapping":{
"type":"keyword",
"ignore_above":256
},
"path_match":"process.tag.*"
}
}
],
"properties":{
"traceID":{
"type":"keyword",
"ignore_above":256
},
"parentSpanID":{
"type":"keyword",
"ignore_above":256
},
"spanID":{
"type":"keyword",
"ignore_above":256
},
"operationName":{
"type":"keyword",
"ignore_above":256
},
"startTime":{
"type":"long"
},
"startTimeMillis":{
"type":"date",
"format":"epoch_millis"
},
"duration":{
"type":"long"
},
"flags":{
"type":"integer"
},
"logs":{
"type":"nested",
"dynamic":false,
"properties":{
"timestamp":{
"type":"long"
},
"fields":{
"type":"nested",
"dynamic":false,
"properties":{
"key":{
"type":"keyword",
"ignore_above":256
},
"value":{
"type":"keyword",
"ignore_above":256
},
"type":{
"type":"keyword",
"ignore_above":256
}
}
}
}
},
"process":{
"properties":{
"serviceName":{
"type":"keyword",
"ignore_above":256
},
"tag":{
"type":"object"
},
"tags":{
"type":"nested",
"dynamic":false,
"properties":{
"key":{
"type":"keyword",
"ignore_above":256
},
"value":{
"type":"keyword",
"ignore_above":256
},
"type":{
"type":"keyword",
"ignore_above":256
}
}
}
}
},
"references":{
"type":"nested",
"dynamic":false,
"properties":{
"refType":{
"type":"keyword",
"ignore_above":256
},
"traceID":{
"type":"keyword",
"ignore_above":256
},
"spanID":{
"type":"keyword",
"ignore_above":256
}
}
},
"tag":{
"type":"object"
},
"tags":{
"type":"nested",
"dynamic":false,
"properties":{
"key":{
"type":"keyword",
"ignore_above":256
},
"value":{
"type":"keyword",
"ignore_above":256
},
"type":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
rohan@rohan-IdeaPad-3-15IIL05-Ua:~/jaeger$ `
This is how I generated esmapping after building jaeger binary. I needed to add some extra flag values.
Signed-off-by: Rohanraj123 <[email protected]>
01ad9bc
to
be85f38
Compare
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
internal/esmapping/command.go
Outdated
} | ||
|
||
options.AddFlags(command) | ||
command.AddCommand(version.Command()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
cmd/esmapping-generator/main.go
Outdated
) | ||
|
||
func main() { | ||
logger, _ := zap.NewDevelopment() | ||
options := app.Options{} | ||
command := &cobra.Command{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this cannot be the same command as the one you introduce in internal?
You can override its Use:
field to maintain the old name, everything else is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the same. I added the central command to the esmapping-generator/main.go
file
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
"github.com/jaegertracing/jaeger/plugin/storage/es/mappings" | ||
) | ||
|
||
func GenerateMappings(options app.Options) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func GenerateMappings(options app.Options) string { | |
func GenerateMappings(options app.Options) (string, error) { |
return proper errors and log them from the caller
internal/esmapping/command.go
Outdated
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/generator" | ||
) | ||
|
||
func Command() *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add tests and run make lint
(which will fail right now)
Signed-off-by: Rohanraj123 <[email protected]>
Signed-off-by: Rohanraj123 <[email protected]>
|
||
command.AddCommand(version.Command()) | ||
esmappingsCmd.Use = rootCmd.Use | ||
rootCmd.AddCommand(esmappingsCmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not equivalent. You need to use the command returned from helper AS the root command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we treat the returned command as a root command then we will not get any specific command as we were getting before. Example of what I mean :
Before :
I use this command to run the command :
go build -o jaeger-esmapping-generator .
to build
./jaeger-esmapping-generator es-mappings --mapping=jaeger-service --es-version=7 --shards=5 --replicas=1 --index-prefix=jaeger-service-index --use-ilm=true --ilm-policy-name=service-ilm-policy
to run the command
After :
go build -o jaeger-esmapping-generator .
to build
./jaeger-esmapping-generator --mapping=jaeger-service --es-version=7 --shards=5 --replicas=1 --index-prefix=jaeger-service-index --use-ilm=true --ilm-policy-name=service-ilm-policy
to run the command.
I didnt find any way of overriding that previous command that was only possible when I add the returned command to some root command. Please let me know if there any workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing binary does not implement any subcommand to execute the functionality
$ go run ./cmd/esmapping-generator help
Jaeger esmapping-generator renders passed templates with provided values and prints rendered output to stdout
Usage:
jaeger-esmapping-generator [flags]
jaeger-esmapping-generator [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Print the version.
Neither should it have subcommands after this change.
|
||
capturedOutput := output.String() | ||
|
||
expectedOutput := `{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command itself is not responsible for the content of the mapping produced by the rendered (and presumably already tested for content). The tests here should only validate the sanity of the output, the comma-to-comma comparison. The same applies to the generator test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically I need to just check whether the output is valid Json or not . Also whether the flags are present in the output also in a valid format or not. And error messages should be correctly handlled . Please correct me If I am wrong. Then I will update tests like that.
Which problem is this PR solving?
Description of the changes
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:yarn lint
andyarn test