Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 25ecb99

Browse files
author
Bogdan Drutu
authored
Remove unused failure from the return values. (#434)
1 parent c54ee82 commit 25ecb99

13 files changed

Lines changed: 42 additions & 99 deletions

cmd/occollector/app/sender/jaeger_thrift_http_sender.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,35 @@ func NewJaegerThriftHTTPSender(
8080
}
8181

8282
// ProcessSpans sends the received data to the configured Jaeger Thrift end-point.
83-
func (s *JaegerThriftHTTPSender) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
83+
func (s *JaegerThriftHTTPSender) ProcessSpans(td data.TraceData, spanFormat string) error {
8484
// TODO: (@pjanotti) In case of failure the translation to Jaeger Thrift is going to be remade, cache it somehow.
8585
tBatch, err := jaegertranslator.OCProtoToJaegerThrift(td)
8686
if err != nil {
87-
return uint64(len(td.Spans)), err
87+
return err
8888
}
8989

90-
mSpans := tBatch.Spans
9190
body, err := serializeThrift(tBatch)
9291
if err != nil {
93-
return uint64(len(mSpans)), err
92+
return err
9493
}
9594
req, err := http.NewRequest("POST", s.url, body)
9695
if err != nil {
97-
return uint64(len(mSpans)), err
96+
return err
9897
}
9998
req.Header.Set("Content-Type", "application/x-thrift")
10099
for k, v := range s.headers {
101100
req.Header.Set(k, v)
102101
}
103102
resp, err := s.client.Do(req)
104103
if err != nil {
105-
return uint64(len(mSpans)), err
104+
return err
106105
}
107106
io.Copy(ioutil.Discard, resp.Body)
108107
resp.Body.Close()
109108
if resp.StatusCode >= http.StatusBadRequest {
110-
return uint64(len(mSpans)), fmt.Errorf("Jaeger Thirft HTTP sender error: %d", resp.StatusCode)
109+
return fmt.Errorf("Jaeger Thirft HTTP sender error: %d", resp.StatusCode)
111110
}
112-
return 0, nil
111+
return nil
113112
}
114113

115114
func serializeThrift(obj thrift.TStruct) (*bytes.Buffer, error) {

cmd/occollector/app/sender/jaeger_thrift_tchannel_sender.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ func NewJaegerThriftTChannelSender(
4545
}
4646

4747
// ProcessSpans sends the received data to the configured Jaeger Thrift end-point.
48-
func (s *JaegerThriftTChannelSender) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
48+
func (s *JaegerThriftTChannelSender) ProcessSpans(td data.TraceData, spanFormat string) error {
4949
// TODO: (@pjanotti) In case of failure the translation to Jaeger Thrift is going to be remade, cache it somehow.
5050
tBatch, err := jaegertranslator.OCProtoToJaegerThrift(td)
5151
if err != nil {
52-
return uint64(len(tBatch.Spans)), err
52+
return err
5353
}
5454

5555
if err := s.reporter.EmitBatch(tBatch); err != nil {
5656
s.logger.Error("Reporter failed to report span batch", zap.Error(err))
57-
return uint64(len(tBatch.Spans)), err
57+
return err
5858
}
59-
return 0, nil
59+
return nil
6060
}

internal/collector/processor/exporter_processor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ func NewTraceExporterProcessor(traceExporters ...processor.TraceDataProcessor) S
3232
return &exporterSpanProcessor{tdp: processor.NewMultiTraceDataProcessor(traceExporters)}
3333
}
3434

35-
func (sp *exporterSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
35+
func (sp *exporterSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) error {
3636
err := sp.tdp.ProcessTraceData(context.Background(), td)
3737
if err != nil {
38-
// TODO: determine if the number of dropped spans is needed because it was wrong anyway.
39-
return 0, err
38+
return err
4039
}
41-
return 0, nil
40+
return nil
4241
}

internal/collector/processor/multi_processor.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,16 @@ func WithAddAttributes(attributes map[string]interface{}, overwrite bool) MultiP
107107
}
108108

109109
// ProcessSpans implements the SpanProcessor interface
110-
func (msp *multiSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
110+
func (msp *multiSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) error {
111111
for _, preProcessFn := range msp.preProcessFns {
112112
preProcessFn(td, spanFormat)
113113
}
114-
var maxFailures uint64
115114
var errors []error
116115
for _, sp := range msp.processors {
117-
failures, err := sp.ProcessSpans(td, spanFormat)
116+
err := sp.ProcessSpans(td, spanFormat)
118117
if err != nil {
119118
errors = append(errors, err)
120119
}
121-
122-
if failures > maxFailures {
123-
maxFailures = failures
124-
}
125120
}
126-
return maxFailures, internal.CombineErrors(errors)
121+
return internal.CombineErrors(errors)
127122
}

internal/collector/processor/multi_processor_test.go

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,6 @@ func TestMultiSpanProcessorMultiplexing(t *testing.T) {
4949
}
5050
}
5151

52-
func TestMultiSpanProcessorSomeNotOk(t *testing.T) {
53-
processors := make([]SpanProcessor, 3)
54-
for i := range processors {
55-
processors[i] = &mockSpanProcessor{}
56-
}
57-
58-
// Make one processor return false for some spans
59-
m := processors[1].(*mockSpanProcessor)
60-
wantFailures := uint64(2)
61-
m.Failures = wantFailures
62-
63-
tt := NewMultiSpanProcessor(processors)
64-
spans := make([]*tracepb.Span, wantFailures+3)
65-
for i := range spans {
66-
spans[i] = &tracepb.Span{}
67-
}
68-
td := data.TraceData{
69-
Spans: spans,
70-
}
71-
72-
var wantSpansCount = 0
73-
for i := 0; i < 2; i++ {
74-
failures, _ := tt.ProcessSpans(td, "test")
75-
batchSize := len(td.Spans)
76-
wantSpansCount += batchSize
77-
if wantFailures != failures {
78-
t.Errorf("Wanted %d failures but got %d", wantFailures, failures)
79-
}
80-
}
81-
82-
for _, p := range processors {
83-
m := p.(*mockSpanProcessor)
84-
if m.TotalSpans != wantSpansCount {
85-
t.Errorf("Wanted %d for every processor but got %d", wantSpansCount, m.TotalSpans)
86-
return
87-
}
88-
}
89-
}
90-
9152
func TestMultiSpanProcessorWhenOneErrors(t *testing.T) {
9253
processors := make([]SpanProcessor, 3)
9354
for i := range processors {
@@ -105,16 +66,13 @@ func TestMultiSpanProcessorWhenOneErrors(t *testing.T) {
10566

10667
var wantSpansCount = 0
10768
for i := 0; i < 2; i++ {
108-
failures, err := tt.ProcessSpans(td, "test")
69+
err := tt.ProcessSpans(td, "test")
10970
if err == nil {
11071
t.Errorf("Wanted error got nil")
11172
return
11273
}
11374
batchSize := len(td.Spans)
11475
wantSpansCount += batchSize
115-
if failures != uint64(batchSize) {
116-
t.Errorf("Wanted all spans to fail, got a different value.")
117-
}
11876
}
11977

12078
for _, p := range processors {
@@ -233,19 +191,18 @@ func multiSpanProcessorWithAddAttributesTestHelper(t *testing.T, overwrite bool)
233191
}
234192

235193
type mockSpanProcessor struct {
236-
Failures uint64
237194
TotalSpans int
238195
MustFail bool
239196
}
240197

241198
var _ SpanProcessor = &mockSpanProcessor{}
242199

243-
func (p *mockSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
200+
func (p *mockSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) error {
244201
batchSize := len(td.Spans)
245202
p.TotalSpans += batchSize
246203
if p.MustFail {
247-
return uint64(batchSize), fmt.Errorf("this processor must fail")
204+
return fmt.Errorf("this processor must fail")
248205
}
249206

250-
return p.Failures, nil
207+
return nil
251208
}

internal/collector/processor/nodebatcher/node_batcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ func NewBatcher(name string, logger *zap.Logger, sender processor.SpanProcessor,
107107

108108
// ProcessSpans implements batcher as a SpanProcessor and takes the provided spans and adds them to
109109
// batches
110-
func (b *batcher) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
110+
func (b *batcher) ProcessSpans(td data.TraceData, spanFormat string) error {
111111
bucketID := b.genBucketID(td.Node, td.Resource, spanFormat)
112112
bucket := b.getOrAddBucket(bucketID, td.Node, td.Resource, spanFormat)
113113
bucket.add(td.Spans)
114-
return 0, nil
114+
return nil
115115
}
116116

117117
func (b *batcher) genBucketID(node *commonpb.Node, resource *resourcepb.Resource, spanFormat string) string {
@@ -275,7 +275,7 @@ func (nb *nodeBatcher) sendBatch(batch *batch) {
275275
Resource: nb.resource,
276276
Spans: spans,
277277
}
278-
_, err := nb.parent.sender.ProcessSpans(td, nb.spanFormat)
278+
err := nb.parent.sender.ProcessSpans(td, nb.spanFormat)
279279
// Assumed that the next processor always handles a batch, and doesn't error
280280
if err != nil {
281281
nb.logger.Error(

internal/collector/processor/nodebatcher/node_batcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ func newTestSender() *testSender {
294294
}
295295
}
296296

297-
func (ts *testSender) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
297+
func (ts *testSender) ProcessSpans(td data.TraceData, spanFormat string) error {
298298
ts.reqChan <- td
299-
return 0, nil
299+
return nil
300300
}
301301

302302
func (ts *testSender) waitFor(spans int, timeout time.Duration) error {

internal/collector/processor/processor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// SpanProcessor handles batches of spans converted to OpenCensus proto format.
3131
type SpanProcessor interface {
3232
// ProcessSpans processes spans and return with the number of spans that failed and an error.
33-
ProcessSpans(td data.TraceData, spanFormat string) (uint64, error)
33+
ProcessSpans(td data.TraceData, spanFormat string) error
3434
// TODO: (@pjanotti) For shutdown improvement, the interface needs a method to attempt that.
3535
}
3636

@@ -39,7 +39,7 @@ type debugSpanProcessor struct{ logger *zap.Logger }
3939

4040
var _ SpanProcessor = (*debugSpanProcessor)(nil)
4141

42-
func (sp *debugSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) (uint64, error) {
42+
func (sp *debugSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) error {
4343
if td.Node == nil {
4444
sp.logger.Warn("Received batch with nil Node", zap.String("format", spanFormat))
4545
}
@@ -49,7 +49,7 @@ func (sp *debugSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string)
4949
stats.RecordWithTags(context.Background(), statsTags, StatReceivedSpanCount.M(int64(numSpans)))
5050

5151
sp.logger.Debug("debugSpanProcessor", zap.String("originalFormat", spanFormat), zap.Int("#spans", numSpans))
52-
return 0, nil
52+
return nil
5353
}
5454

5555
// NewNoopSpanProcessor creates an OC SpanProcessor that just drops the received data.

internal/collector/processor/processor_to_sink.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,5 @@ func WrapWithSpanSink(format string, p SpanProcessor) processor.TraceDataProcess
3737
}
3838

3939
func (ps *protoProcessorSink) ProcessTraceData(ctx context.Context, td data.TraceData) error {
40-
_, err := ps.protoProcessor.ProcessSpans(td, ps.sourceFormat)
41-
42-
return err
40+
return ps.protoProcessor.ProcessSpans(td, ps.sourceFormat)
4341
}

internal/collector/processor/queued/queued_processor.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,11 @@ func (sp *queuedSpanProcessor) Stop() {
111111
}
112112

113113
// ProcessSpans implements the SpanProcessor interface
114-
func (sp *queuedSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) (failures uint64, err error) {
115-
allAdded := sp.enqueueSpanBatch(td, spanFormat)
116-
if !allAdded {
117-
failures = uint64(len(td.Spans))
118-
}
119-
return
114+
func (sp *queuedSpanProcessor) ProcessSpans(td data.TraceData, spanFormat string) error {
115+
return sp.enqueueSpanBatch(td, spanFormat)
120116
}
121117

122-
func (sp *queuedSpanProcessor) enqueueSpanBatch(td data.TraceData, spanFormat string) bool {
118+
func (sp *queuedSpanProcessor) enqueueSpanBatch(td data.TraceData, spanFormat string) error {
123119
item := &queueItem{
124120
queuedTime: time.Now(),
125121
td: td,
@@ -134,12 +130,12 @@ func (sp *queuedSpanProcessor) enqueueSpanBatch(td data.TraceData, spanFormat st
134130
if !addedToQueue {
135131
sp.onItemDropped(item, statsTags)
136132
}
137-
return addedToQueue
133+
return nil
138134
}
139135

140136
func (sp *queuedSpanProcessor) processItemFromQueue(item *queueItem) {
141137
startTime := time.Now()
142-
_, err := sp.sender.ProcessSpans(item.td, item.spanFormat)
138+
err := sp.sender.ProcessSpans(item.td, item.spanFormat)
143139
if err == nil {
144140
// Record latency metrics and return
145141
sendLatencyMs := int64(time.Since(startTime) / time.Millisecond)

0 commit comments

Comments
 (0)