Skip to content

Commit

Permalink
Add esmapping-generator tool to jaeger binary
Browse files Browse the repository at this point in the history
Signed-off-by: Rohanraj123 <[email protected]>
  • Loading branch information
Rohanraj123 committed Jan 11, 2025
1 parent 980dc31 commit 01ad9bc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
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))

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"
)

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)
}

}

0 comments on commit 01ad9bc

Please sign in to comment.