Skip to content
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,35 @@ type Config struct {
// This allows using existing OpenTracing instrumentation with OpenTelemetry
OTLPUseOpenTracingBridge bool `envconfig:"OTLP_USE_OPENTRACING_BRIDGE" default:"true"`
}

// Validate checks the configuration for common misconfigurations and returns
// a list of warning messages. It does not return an error to avoid breaking
// existing services — warnings are meant to be logged at startup.
func (c Config) Validate() []string {
var warnings []string

if c.GRPCPort < 1 || c.GRPCPort > 65535 {
warnings = append(warnings, "GRPCPort is out of valid range (1-65535)")
}
if c.HTTPPort < 1 || c.HTTPPort > 65535 {
warnings = append(warnings, "HTTPPort is out of valid range (1-65535)")
}
if c.GRPCPort == c.HTTPPort && c.GRPCPort != 0 {
warnings = append(warnings, "GRPCPort and HTTPPort are the same, this will cause a port conflict")
}
Comment thread
ankurs marked this conversation as resolved.
Outdated
if c.NewRelicOpentelemetrySample < 0 || c.NewRelicOpentelemetrySample > 1.0 {
warnings = append(warnings, "NewRelicOpentelemetrySample should be between 0.0 and 1.0")
}
if c.OTLPSamplingRatio < 0 || c.OTLPSamplingRatio > 1.0 {
warnings = append(warnings, "OTLPSamplingRatio should be between 0.0 and 1.0")
}
Comment thread
ankurs marked this conversation as resolved.
if (c.GRPCTLSCertFile == "") != (c.GRPCTLSKeyFile == "") {
warnings = append(warnings, "GRPCTLSCertFile and GRPCTLSKeyFile must both be set or both be empty")
}
if c.ShutdownDurationInSeconds > 0 && c.HealthcheckWaitDurationInSeconds > 0 &&
c.HealthcheckWaitDurationInSeconds >= c.ShutdownDurationInSeconds {
warnings = append(warnings, "HealthcheckWaitDurationInSeconds should be less than ShutdownDurationInSeconds")
}

return warnings
}
Comment thread
ankurs marked this conversation as resolved.
21 changes: 15 additions & 6 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ func (c *cb) Run() error {
errChan <- c.runHTTP(ctx, c.httpServer)
}()
err = <-errChan
// One server failed — stop the other to ensure clean shutdown
if c.grpcServer != nil {
c.grpcServer.Stop()
}
if c.httpServer != nil {
c.httpServer.Close()
}
Comment thread
ankurs marked this conversation as resolved.
Outdated
Comment thread
ankurs marked this conversation as resolved.
c.gracefulWait.Wait() // if graceful shutdown is in progress wait for it to finish
c.close()
Comment thread
ankurs marked this conversation as resolved.
return err
Expand Down Expand Up @@ -482,12 +489,9 @@ func (c *cb) Stop(dur time.Duration) error {
}
log.Info(context.Background(), "msg", "Server shut down started, bye bye")
if c.httpServer != nil {
go func(ctx context.Context, c *cb) {
err := c.httpServer.Shutdown(ctx)
if err != nil {
log.Error(context.Background(), "msg", "http server shutdown error", "err", err)
}
}(ctx, c) // shutdown http server gracefully
if err := c.httpServer.Shutdown(ctx); err != nil {
log.Error(context.Background(), "msg", "http server shutdown error", "err", err)
}
}
if c.grpcServer != nil {
timedCall(ctx, c.grpcServer.GracefulStop)
Expand Down Expand Up @@ -524,6 +528,11 @@ func timedCall(ctx context.Context, f func()) {
// The services are added using the AddService method
// The services are started and stopped in the order they are added
func New(c config.Config) CB {
if warnings := c.Validate(); len(warnings) > 0 {
Comment thread
ankurs marked this conversation as resolved.
Outdated
for _, w := range warnings {
log.Warn(context.Background(), "msg", "config validation warning", "warning", w)
}
}
Comment thread
ankurs marked this conversation as resolved.
Outdated
impl := &cb{
config: c,
svc: make([]CBService, 0),
Expand Down
1 change: 1 addition & 0 deletions initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func SetupReleaseName(rel string) {
// Use SetupOpenTelemetry or SetupNROpenTelemetry instead, which support
// OTLP-compatible backends including Jaeger's OTLP receiver.
func setupJaeger(serviceName string) io.Closer {
log.Warn(context.Background(), "msg", "Jaeger client is deprecated and EOL. Please migrate to SetupOpenTelemetry or SetupNROpenTelemetry with OTLP-compatible backends.")
Comment thread
ankurs marked this conversation as resolved.
Outdated
conf, err := jaegerconfig.FromEnv()
if err != nil {
log.Info(context.Background(), "msg", "could not initialize jaeger", "err", err)
Expand Down
Loading