Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Jul 12, 2024
1 parent 09c2638 commit 396a17d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
12 changes: 8 additions & 4 deletions cmd/jaeger/internal/extension/jaegerquery/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package jaegerquery
import (
"github.com/asaskevich/govalidator"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"

queryApp "github.com/jaegertracing/jaeger/cmd/query/app"
Expand All @@ -18,10 +19,13 @@ var _ component.ConfigValidator = (*Config)(nil)
type Config struct {
queryApp.QueryOptionsBase `mapstructure:",squash"`

TraceStoragePrimary string `valid:"required" mapstructure:"trace_storage"`
TraceStorageArchive string `valid:"optional" mapstructure:"trace_storage_archive"`
confighttp.ServerConfig `mapstructure:",squash"`
Tenancy tenancy.Options `mapstructure:"multi_tenancy"`
TraceStoragePrimary string `valid:"required" mapstructure:"trace_storage"`
TraceStorageArchive string `valid:"optional" mapstructure:"trace_storage_archive"`

HTTP confighttp.ServerConfig `mapstructure:",squash"`
GRPC configgrpc.ServerConfig `mapstructure:",squash"`

Tenancy tenancy.Options `mapstructure:"multi_tenancy"`
}

func (cfg *Config) Validate() error {
Expand Down
10 changes: 9 additions & 1 deletion cmd/jaeger/internal/extension/jaegerquery/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/extension"

"github.com/jaegertracing/jaeger/ports"
Expand All @@ -25,9 +27,15 @@ func NewFactory() extension.Factory {

func createDefaultConfig() component.Config {
return &Config{
ServerConfig: confighttp.ServerConfig{
HTTP: confighttp.ServerConfig{
Endpoint: ports.PortToHostPort(ports.QueryHTTP),
},
GRPC: configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: ports.PortToHostPort(ports.QueryGRPC),
Transport: confignet.TransportTypeTCP,
},
},
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/jaeger/internal/extension/jaegerquery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/jaegertracing/jaeger/pkg/telemetery"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/plugin/metrics/disabled"
"github.com/jaegertracing/jaeger/ports"
)

var (
Expand Down Expand Up @@ -127,9 +126,10 @@ func (s *server) makeQueryOptions() *queryApp.QueryOptions {
return &queryApp.QueryOptions{
QueryOptionsBase: s.config.QueryOptionsBase,

// TODO expose via config
HTTPHostPort: ports.PortToHostPort(ports.QueryHTTP),
GRPCHostPort: ports.PortToHostPort(ports.QueryGRPC),
// TODO utilize OTEL helpers for creating HTTP/GRPC servers
HTTPHostPort: s.config.HTTP.Endpoint,
GRPCHostPort: s.config.GRPC.NetAddr.Endpoint,
// TODO handle TLS
}
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func TestServerStart(t *testing.T) {
Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())),
ReportStatus: func(*component.StatusEvent) {},
}
tt.config.HTTP.Endpoint = ":0"
tt.config.GRPC.NetAddr.Endpoint = ":0"
server := newServer(tt.config, telemetrySettings)
err := server.Start(context.Background(), host)
if tt.expectedErr == "" {
Expand All @@ -176,7 +178,7 @@ func TestServerStart(t *testing.T) {
// which could cause flaky code coverage by going through error cases.
require.Eventually(t,
func() bool {
resp, err := http.Get("http://localhost:16686/")
resp, err := http.Get(fmt.Sprintf("http://%s/", server.server.HTTPAddr()))
if err != nil {
return false
}
Expand All @@ -187,7 +189,7 @@ func TestServerStart(t *testing.T) {
100*time.Millisecond,
"server not started")
grpctest.ReflectionServiceValidator{
HostPort: ":16685",
HostPort: server.server.GRPCAddr(),
ExpectedServices: []string{
"jaeger.api_v2.QueryService",
"jaeger.api_v3.QueryService",
Expand Down
17 changes: 13 additions & 4 deletions cmd/query/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func NewServer(querySvc *querysvc.QueryService,
if err != nil {
return nil, fmt.Errorf("invalid gRPC server host:port: %w", err)
}
separatePorts := grpcPort != httpPort || grpcPort == "0" || httpPort == "0"

if (options.TLSHTTP.Enabled || options.TLSGRPC.Enabled) && (grpcPort == httpPort) {
if (options.TLSHTTP.Enabled || options.TLSGRPC.Enabled) && !separatePorts {
return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead")
}

Expand All @@ -98,7 +99,7 @@ func NewServer(querySvc *querysvc.QueryService,
queryOptions: options,
grpcServer: grpcServer,
httpServer: httpServer,
separatePorts: grpcPort != httpPort,
separatePorts: separatePorts,
Setting: telset,
}, nil
}
Expand Down Expand Up @@ -232,8 +233,8 @@ func (s *Server) initListener() (cmux.CMux, error) {
}
s.Logger.Info(
"Query server started",
zap.String("http_addr", s.httpConn.Addr().String()),
zap.String("grpc_addr", s.grpcConn.Addr().String()),
zap.String("http_addr", s.HTTPAddr()),
zap.String("grpc_addr", s.GRPCAddr()),
)
return nil, nil
}
Expand Down Expand Up @@ -346,6 +347,14 @@ func (s *Server) Start() error {
return nil
}

func (s *Server) HTTPAddr() string {
return s.httpConn.Addr().String()
}

func (s *Server) GRPCAddr() string {
return s.grpcConn.Addr().String()
}

// Close stops HTTP, GRPC servers and closes the port listener.
func (s *Server) Close() error {
errs := []error{
Expand Down
1 change: 0 additions & 1 deletion internal/grpctest/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
// ReflectionServiceValidator verifies that a gRPC service at a given address
// supports reflection service. Called must invoke Execute func.
type ReflectionServiceValidator struct {
Server *grpc.Server
HostPort string
ExpectedServices []string
}
Expand Down

0 comments on commit 396a17d

Please sign in to comment.