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

[remote-storage] Use OTEL helper instead of tlscfg #6351

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup
Signed-off-by: Yuri Shkuro <[email protected]>
yurishkuro committed Dec 13, 2024
commit f64b3ae6e9107ddd9eccb44b4d2f6c7acd8fb3a1
8 changes: 1 addition & 7 deletions cmd/remote-storage/app/flags.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (

"github.com/spf13/viper"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/config/confignet"

"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
"github.com/jaegertracing/jaeger/pkg/tenancy"
@@ -40,12 +39,7 @@ func AddFlags(flagSet *flag.FlagSet) {

// InitFromViper initializes Options with properties from CLI flags.
func (o *Options) InitFromViper(v *viper.Viper) (*Options, error) {
grpcEndpoint := v.GetString(flagGRPCHostPort)
o.ServerConfig = configgrpc.ServerConfig{
NetAddr: confignet.AddrConfig{
Endpoint: grpcEndpoint,
},
}
o.NetAddr.Endpoint = v.GetString(flagGRPCHostPort)
tlsGrpc, err := tlsGRPCFlagsConfig.InitFromViper(v)
if err != nil {
return o, fmt.Errorf("failed to process gRPC TLS options: %w", err)
25 changes: 11 additions & 14 deletions cmd/remote-storage/app/server.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ package app

import (
"context"
"fmt"
"net"
"sync"

@@ -31,7 +32,7 @@ type Server struct {
opts *Options
grpcConn net.Listener
grpcServer *grpc.Server
wg sync.WaitGroup
stopped sync.WaitGroup
telset telemetry.Settings
}

@@ -87,8 +88,6 @@ func createGRPCHandler(f storage.BaseFactory, logger *zap.Logger) (*shared.GRPCH
}

func createGRPCServer(opts *Options, tm *tenancy.Manager, handler *shared.GRPCHandler, telset telemetry.Settings) (*grpc.Server, error) {
var grpcOpts []configgrpc.ToServerOption

unaryInterceptors := []grpc.UnaryServerInterceptor{
bearertoken.NewUnaryServerInterceptor(),
}
@@ -100,17 +99,15 @@ func createGRPCServer(opts *Options, tm *tenancy.Manager, handler *shared.GRPCHa
streamInterceptors = append(streamInterceptors, tenancy.NewGuardingStreamInterceptor(tm))
}

grpcOpts = append(grpcOpts,
configgrpc.WithGrpcServerOption(grpc.ChainUnaryInterceptor(unaryInterceptors...)),
configgrpc.WithGrpcServerOption(grpc.ChainStreamInterceptor(streamInterceptors...)),
)
opts.NetAddr.Transport = confignet.TransportTypeTCP
server, err := opts.ToServer(context.Background(),
nil,
telset.Host,
telset.ToOtelComponent(),
grpcOpts...)
configgrpc.WithGrpcServerOption(grpc.ChainUnaryInterceptor(unaryInterceptors...)),
configgrpc.WithGrpcServerOption(grpc.ChainStreamInterceptor(streamInterceptors...)),
)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create gRPC server: %w", err)
}
healthServer := health.NewServer()
reflection.Register(server)
@@ -124,12 +121,12 @@ func (s *Server) Start() error {
var err error
s.grpcConn, err = s.opts.NetAddr.Listen(context.Background())
if err != nil {
return err
return fmt.Errorf("failed to listen on gRPC port: %w", err)
}
s.telset.Logger.Info("Starting GRPC server", zap.Stringer("addr", s.grpcConn.Addr()))
s.wg.Add(1)
s.stopped.Add(1)
go func() {
defer s.wg.Done()
defer s.stopped.Done()
if err := s.grpcServer.Serve(s.grpcConn); err != nil {
s.telset.Logger.Error("GRPC server exited", zap.Error(err))
s.telset.ReportStatus(componentstatus.NewFatalErrorEvent(err))
@@ -142,7 +139,7 @@ func (s *Server) Start() error {
// Close stops http, GRPC servers and closes the port listener.
func (s *Server) Close() error {
s.grpcServer.Stop()
s.wg.Wait()
s.stopped.Wait()
s.telset.ReportStatus(componentstatus.NewEvent(componentstatus.StatusStopped))
return nil
}
5 changes: 2 additions & 3 deletions cmd/remote-storage/app/server_test.go
Original file line number Diff line number Diff line change
@@ -69,10 +69,9 @@ func TestNewServer_CreateStorageErrors(t *testing.T) {

s, err := f()
require.NoError(t, err)
err = s.Start()
require.NoError(t, err)
require.NoError(t, s.Start())
validateGRPCServer(t, s.grpcConn.Addr().String())
s.grpcConn.Close()
require.NoError(t, s.grpcConn.Close())
}

func TestServerStart_BadPortErrors(t *testing.T) {