Skip to content

Commit

Permalink
replace atomic with sync.Once
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvs committed Aug 13, 2024
1 parent 3b97b50 commit 5a15008
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ https://github.com/elastic/apm-server/compare/8.15\...main[View commits]

[float]
==== Deprecations
- Support for Jaeger will be deprecated in a future release {pull}13809[13809]
- Support for Jaeger is now deprecated, and will be removed in a future release {pull}13809[13809]

[float]
==== Intake API Changes
Expand Down
31 changes: 15 additions & 16 deletions internal/beater/jaeger/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"errors"
"fmt"
"strconv"
"sync/atomic"
"sync"

jaegermodel "github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
Expand Down Expand Up @@ -79,19 +79,16 @@ func RegisterGRPCServices(

logger.Info(deprecationNotice)

var warningCollector atomic.Int32
api_v2.RegisterCollectorServiceServer(srv, &grpcCollector{&warningCollector, logger, traceConsumer})

var warningSampling atomic.Int32
api_v2.RegisterSamplingManagerServer(srv, &grpcSampler{&warningSampling, logger, fetcher})
api_v2.RegisterCollectorServiceServer(srv, &grpcCollector{sync.Once{}, logger, traceConsumer})
api_v2.RegisterSamplingManagerServer(srv, &grpcSampler{sync.Once{}, logger, fetcher})
}

// grpcCollector implements Jaeger api_v2 protocol for receiving tracing data
type grpcCollector struct {
// Use an atomic counter to ensure concurrent safety.
warningPrinted *atomic.Int32
logger *zap.Logger
consumer consumer.Traces
once sync.Once
logger *zap.Logger
consumer consumer.Traces
}

// AuthenticateUnaryCall authenticates CollectorService calls.
Expand Down Expand Up @@ -132,9 +129,11 @@ func (c *grpcCollector) RequestMetrics(fullMethodName string) map[request.Result
// The implementation of the protobuf contract is based on the open-telemetry implementation at
// https://github.com/open-telemetry/opentelemetry-collector/tree/master/receiver/jaegerreceiver
func (c *grpcCollector) PostSpans(ctx context.Context, r *api_v2.PostSpansRequest) (*api_v2.PostSpansResponse, error) {
if c.warningPrinted.CompareAndSwap(0, 1) {

c.once.Do(func() {
c.logger.Warn(deprecationNotice)
}
})

if err := c.postSpans(ctx, r.Batch); err != nil {
return nil, err
}
Expand Down Expand Up @@ -162,9 +161,9 @@ var (

type grpcSampler struct {
// Use an atomic counter to ensure concurrent safety.
warningPrinted *atomic.Int32
logger *zap.Logger
fetcher agentcfg.Fetcher
once sync.Once
logger *zap.Logger
fetcher agentcfg.Fetcher
}

// GetSamplingStrategy implements the api_v2/sampling.proto.
Expand All @@ -174,9 +173,9 @@ func (s *grpcSampler) GetSamplingStrategy(
ctx context.Context,
params *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) {

if s.warningPrinted.CompareAndSwap(0, 1) {
s.once.Do(func() {
s.logger.Warn(deprecationNotice)
}
})

samplingRate, err := s.fetchSamplingRate(ctx, params.ServiceName)
if err != nil {
Expand Down

0 comments on commit 5a15008

Please sign in to comment.