Skip to content

Commit

Permalink
add deprecation warning to each Jaeger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rubvs committed Aug 12, 2024
1 parent f589fe2 commit 3b97b50
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
28 changes: 22 additions & 6 deletions internal/beater/jaeger/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"strconv"
"sync/atomic"

jaegermodel "github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
Expand Down Expand Up @@ -76,15 +77,21 @@ func RegisterGRPCServices(
Semaphore: semaphore,
})

logger.Warn(deprecationNotice)
logger.Info(deprecationNotice)

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

var warningSampling atomic.Int32
api_v2.RegisterSamplingManagerServer(srv, &grpcSampler{&warningSampling, logger, fetcher})
}

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

// AuthenticateUnaryCall authenticates CollectorService calls.
Expand Down Expand Up @@ -125,6 +132,9 @@ 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.logger.Warn(deprecationNotice)
}
if err := c.postSpans(ctx, r.Batch); err != nil {
return nil, err
}
Expand All @@ -151,8 +161,10 @@ var (
)

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

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

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

samplingRate, err := s.fetchSamplingRate(ctx, params.ServiceName)
if err != nil {
// do not return full error details since this is part of an unprotected endpoint response
Expand Down
28 changes: 25 additions & 3 deletions internal/beater/jaeger/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestPostSpans(t *testing.T) {
var processor modelpb.ProcessBatchFunc = func(ctx context.Context, batch *modelpb.Batch) error {
return processorErr
}
conn, _ := newServer(t, processor, nil)
conn, logs := newServer(t, processor, nil)

client := api_v2.NewCollectorServiceClient(conn)
result, err := client.PostSpans(context.Background(), &api_v2.PostSpansRequest{})
Expand Down Expand Up @@ -80,6 +80,17 @@ func TestPostSpans(t *testing.T) {
t.Run(name, func(t *testing.T) {
processorErr = tc.processorErr
resp, err := client.PostSpans(context.Background(), tc.request)

// Deprecation log shown on server startup.
log := logs.All()[0]
assert.Equal(t, log.Level, zap.InfoLevel)
assert.Contains(t, log.Message, deprecationNotice)

// Deprecation log shown on first endpoint hit.
log = logs.All()[1]
assert.Equal(t, log.Level, zap.WarnLevel)
assert.Contains(t, log.Message, deprecationNotice)

if tc.expectedErr != nil {
assert.Nil(t, resp)
assert.Error(t, err)
Expand Down Expand Up @@ -167,14 +178,25 @@ func TestGRPCSampler_GetSamplingStrategy(t *testing.T) {
client := api_v2.NewSamplingManagerClient(conn)
resp, err := client.GetSamplingStrategy(context.Background(), tc.params)

// Deprecation log shown on server startup.
log := logs.All()[0]
assert.Equal(t, log.Level, zap.InfoLevel)
assert.Contains(t, log.Message, deprecationNotice)

// Deprecation log shown on first endpoint hit.
log = logs.All()[1]
assert.Equal(t, log.Level, zap.WarnLevel)
assert.Contains(t, log.Message, deprecationNotice)

// assert sampling response
if tc.expectedErrMsg != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.expectedErrMsg)
assert.Nil(t, resp)

require.Equal(t, 2, logs.Len())
log := logs.All()[1]
require.Equal(t, 3, logs.Len())

log = logs.All()[2]
assert.Contains(t, log.Message, tc.expectedLogMsg)

if tc.expectedLogError != "" {
Expand Down

0 comments on commit 3b97b50

Please sign in to comment.