Skip to content

Commit

Permalink
exp(jaeger-v2): Simplify all-in-one configuration (#4875)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Part of #4843 
- Improvement on #4842, where all-in-one configuration was created via
createDefaultConfig methods of extensions called by OTel automatically.
This resulted in the memstore always being present in the config and
always instantiated, which is not the desired behavior.

## Description of the changes
- The cmd.RunE interceptor is changed to provide an internal value to
the `--config` flag if no flag was present on cmd line
- This avoids creating the collector manually, once we set the flag we
always delegate back to official OTel code
- The value for the config is embedded in the binary and passed using
`yaml:...`, which is one of the official config providers in OTel

## How was this change tested?
- Ran all-in-one manually

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Oct 21, 2023
1 parent 244b4be commit e1e1564
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
38 changes: 38 additions & 0 deletions cmd/jaeger-v2/internal/all-in-one.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
service:
extensions: [jaeger_storage, jaeger_query]
pipelines:
traces:
receivers: [otlp, jaeger, zipkin]
processors: [batch]
exporters: [jaeger_storage_exporter]

extensions:
jaeger_query:
trace_storage: memstore

jaeger_storage:
memory:
memstore:
max_traces: 100000

receivers:
otlp:
protocols:
grpc:
http:

jaeger:
protocols:
grpc:
thrift_binary:
thrift_compact:
thrift_http:

zipkin:

processors:
batch:

exporters:
jaeger_storage_exporter:
trace_storage: memstore
33 changes: 16 additions & 17 deletions cmd/jaeger-v2/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
package internal

import (
"embed"
"fmt"
"log"

"github.com/spf13/cobra"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/otelcol"

allinone "github.com/jaegertracing/jaeger/cmd/jaeger-v2/internal/all-in-one"
"github.com/jaegertracing/jaeger/pkg/version"
)

//go:embed all-in-one.yaml
var yamlAllInOne embed.FS

const description = "Jaeger backend v2"

func Command() *cobra.Command {
Expand All @@ -38,25 +42,20 @@ func Command() *cobra.Command {
// We want to support running the binary in all-in-one mode without a config file.
// Since there are no explicit hooks in OTel Collector for that today (as of v0.87),
// we intercept the official RunE implementation and check if any `--config` flags
// are present in the args. If not, we pass a custom ConfigProvider, and create the
// collector manually. Unfortunately, `set`(tings) is passed to NewCommand above
// by value, otherwise we could've overwritten it in the interceptor and then delegated
// back to the official RunE.
// are present in the args. If not, we create one with all-in-one configuration.
otelRunE := cmd.RunE
cmd.RunE = func(cmd *cobra.Command, args []string) error {
// a bit of a hack to check if '--config' flag was present
configFlag := cmd.Flag("config").Value.String()
if configFlag != "" && configFlag != "[]" {
return otelRunE(cmd, args)
}
log.Print("No '--config' flags detected, using default All-in-One configuration with memory storage.")
log.Print("To customize All-in-One behavior, pass a proper configuration.")
settings.ConfigProvider = allinone.NewConfigProvider()
col, err := otelcol.NewCollector(settings)
if err != nil {
return err
configFlag := cmd.Flag("config")
if !configFlag.Changed {
log.Print("No '--config' flags detected, using default All-in-One configuration with memory storage.")
log.Print("To customize All-in-One behavior, pass a proper configuration.")
data, err := yamlAllInOne.ReadFile("all-in-one.yaml")
if err != nil {
return fmt.Errorf("cannot read embedded all-in-one configuration: %w", err)
}
configFlag.Value.Set("yaml:" + string(data))
}
return col.Run(cmd.Context())
return otelRunE(cmd, args)
}

cmd.Short = description
Expand Down
6 changes: 1 addition & 5 deletions cmd/jaeger-v2/internal/exporters/storageexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"

"github.com/jaegertracing/jaeger/cmd/jaeger-v2/internal/extension/jaegerstorage"
)

// componentType is the name of this extension in configuration.
Expand All @@ -30,9 +28,7 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
return &Config{
TraceStorage: jaegerstorage.DefaultMemoryStore,
}
return &Config{}
}

func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Traces, error) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/jaeger-v2/internal/extension/jaegerquery/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/extension"

"github.com/jaegertracing/jaeger/cmd/jaeger-v2/internal/extension/jaegerstorage"
"github.com/jaegertracing/jaeger/ports"
)

Expand All @@ -26,7 +25,6 @@ func NewFactory() extension.Factory {

func createDefaultConfig() component.Config {
return &Config{
TraceStoragePrimary: jaegerstorage.DefaultMemoryStore,
HTTPServerSettings: confighttp.HTTPServerSettings{
Endpoint: ports.PortToHostPort(ports.QueryHTTP),
},
Expand Down
19 changes: 3 additions & 16 deletions cmd/jaeger-v2/internal/extension/jaegerstorage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"

memoryCfg "github.com/jaegertracing/jaeger/pkg/memory/config"
)

const (
// componentType is the name of this extension in configuration.
componentType = component.Type("jaeger_storage")

// DefaultMemoryStore is the name of the memory storage included in the default configuration.
DefaultMemoryStore = "memstore"
)
// componentType is the name of this extension in configuration.
const componentType = component.Type("jaeger_storage")

// ID is the identifier of this extension.
var ID = component.NewID(componentType)
Expand All @@ -33,13 +26,7 @@ func NewFactory() extension.Factory {
}

func createDefaultConfig() component.Config {
return &Config{
Memory: map[string]memoryCfg.Configuration{
DefaultMemoryStore: {
MaxTraces: 100_000,
},
},
}
return &Config{}
}

// createExtension creates the extension based on this config.
Expand Down

0 comments on commit e1e1564

Please sign in to comment.