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

feat: Add esmapping-generator into jaeger binary #6327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
collectorFlags "github.com/jaegertracing/jaeger/cmd/collector/app/flags"
"github.com/jaegertracing/jaeger/cmd/internal/docs"
"github.com/jaegertracing/jaeger/cmd/internal/env"
"github.com/jaegertracing/jaeger/cmd/internal/esmapping"
"github.com/jaegertracing/jaeger/cmd/internal/flags"
"github.com/jaegertracing/jaeger/cmd/internal/printconfig"
"github.com/jaegertracing/jaeger/cmd/internal/status"
Expand Down Expand Up @@ -79,7 +80,7 @@ func main() {
Short: "Jaeger all-in-one distribution with collector and query in one process.",
Long: `Jaeger all-in-one distribution with collector and query. Use with caution: this version
by default uses only in-memory database.`,
RunE: func(_ *cobra.Command, _ /* args */ []string) error {
RunE: func(cobra *cobra.Command, _ /* args */ []string) error {
if err := svc.Start(v); err != nil {
return err
}
Expand Down Expand Up @@ -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))
Copy link
Member

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


config.AddFlags(
v,
Expand Down
24 changes: 24 additions & 0 deletions cmd/esmapping-generator/app/generator/esmapping_generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package generator

import (
"fmt"

"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/plugin/storage/es/mappings"
)

func GenerateMappings() string {
options := app.Options{}
if _, err := mappings.MappingTypeFromString(options.Mapping); err != nil {
return fmt.Sprintf("please pass either 'jaeger-service' or 'jaeger-span' as argument: %v", err)
}

parsedMapping, err := renderer.GetMappingAsString(es.TextTemplateBuilder{}, &options)
if err != nil {
return fmt.Sprintf("failed to get mapping as string: %v", err)
}

return parsedMapping
}
5 changes: 2 additions & 3 deletions cmd/esmapping-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
"go.uber.org/zap"

"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"
Copy link
Member

Choose a reason for hiding this comment

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

run make fmt

)

func main() {
Expand Down
28 changes: 28 additions & 0 deletions cmd/internal/esmapping/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package esmapping

import (
"fmt"

"github.com/spf13/cobra"

"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app"
"github.com/jaegertracing/jaeger/cmd/esmapping-generator/app/generator"
"go.uber.org/zap"
)

func Command(logger *zap.Logger) *cobra.Command {
options := app.Options{}

command := &cobra.Command{
Use: "es-mappings",
Short: "Generate Elasticsearch mappings",
Long: "Generate Elasticsearch mappings using jaeger-esmapping-generator functionality",
Run: func(_ *cobra.Command, _ []string) {
result := generator.GenerateMappings()
fmt.Println(result)
},
}

command.Flags().StringVar(&options.Mapping, "mapping", "jaeger-span", "Mapping type to use, e.g. 'jaeger-service' or 'jaeger-span'")
return command
}
5 changes: 5 additions & 0 deletions cmd/jaeger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import (
"log"

"github.com/spf13/viper"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/internal/docs"
"github.com/jaegertracing/jaeger/cmd/internal/esmapping"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/version"
)

func main() {
logger, _ := zap.NewDevelopment()
v := viper.New()
command := internal.Command()
command.AddCommand(version.Command())
command.AddCommand(docs.Command(v))
command.AddCommand(esmapping.Command(logger))
config.AddFlags(
v,
command,
Expand All @@ -27,4 +31,5 @@ func main() {
if err := command.Execute(); err != nil {
log.Fatal(err)
}

}
Loading