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

2649 - Change receiver obsreport helpers pattern to match the Processor/Exporter #3227

Merged
merged 13 commits into from
May 20, 2021

Conversation

humivo
Copy link
Member

@humivo humivo commented May 18, 2021

Description: Change obsreport helpers for receiver to use the same pattern with structs and helpers as Processor/Exporter.

Link to tracking Issue: Issue #2649

@humivo humivo requested a review from a team May 18, 2021 21:27
receiver/scraperhelper/scrapercontroller.go Outdated Show resolved Hide resolved
receiver/zipkinreceiver/trace_receiver.go Outdated Show resolved Hide resolved
receiver/prometheusreceiver/internal/transaction.go Outdated Show resolved Hide resolved
receiver/otlpreceiver/logs/otlp.go Outdated Show resolved Hide resolved
@@ -254,7 +254,8 @@ func (c *tracesConsumerGroupHandler) ConsumeClaim(session sarama.ConsumerGroupSe
session.MarkMessage(message, "")

ctx := obsreport.ReceiverContext(session.Context(), c.id, transport)
ctx = obsreport.StartTraceDataReceiveOp(ctx, c.id, transport)
rec := obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: c.id, Transport: transport})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, you can cache to object. Please apply the caching to all the non-test code where you can.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I applied to caching to all non-test code in my latest commit

receiver/jaegerreceiver/trace_receiver.go Outdated Show resolved Hide resolved
@@ -217,7 +219,8 @@ func (zr *ZipkinReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {

transportTag := transportType(r, asZipkinv1)
ctx = obsreport.ReceiverContext(ctx, zr.id, transportTag)
ctx = obsreport.StartTraceDataReceiveOp(ctx, zr.id, transportTag)
zr.receiver = obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: zr.id, Transport: transportTag})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you cannot "cache" since you don't know the transport (actually it will cause a race condition). you cannot do things blindly :) Please check everywhere if that is the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh ok I thought so. I just fixed this in the latest commit. I think that was the only place where we do not know the transport.

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments apply everywhere

@@ -239,10 +242,11 @@ func (h *agentHandler) EmitZipkinBatch(context.Context, []*zipkincore.Span) (err
// Jaeger spans received by the Jaeger agent processor.
func (h *agentHandler) EmitBatch(ctx context.Context, batch *jaeger.Batch) error {
ctx = obsreport.ReceiverContext(ctx, h.id, h.transport)
ctx = obsreport.StartTraceDataReceiveOp(ctx, h.id, h.transport)
h.obsrecv = obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: h.id, Transport: h.transport})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about here? Does seem that you initialize the obsrecv every request so you will have a race. Probably initialize in the ctor if transport is known.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now initialized in the ctor in latest commit

@@ -267,12 +271,13 @@ func (jr *jReceiver) PostSpans(ctx context.Context, r *api_v2.PostSpansRequest)
}

ctx = obsreport.ReceiverContext(ctx, jr.id, grpcTransport)
ctx = obsreport.StartTraceDataReceiveOp(ctx, jr.id, grpcTransport)
jr.obsrecv = obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: jr.id, Transport: grpcTransport})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Or have different instances per transport is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialized in ctor with different instances per transport

@@ -415,12 +420,13 @@ func (jr *jReceiver) HandleThriftHTTPBatch(w http.ResponseWriter, r *http.Reques
}

ctx = obsreport.ReceiverContext(ctx, jr.id, collectorHTTPTransport)
ctx = obsreport.StartTraceDataReceiveOp(ctx, jr.id, collectorHTTPTransport)
jr.obsrecv = obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: jr.id, Transport: collectorHTTPTransport})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here you modify the same variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now initialized in the ctor in latest commit

@@ -254,7 +258,8 @@ func (c *tracesConsumerGroupHandler) ConsumeClaim(session sarama.ConsumerGroupSe
session.MarkMessage(message, "")

ctx := obsreport.ReceiverContext(session.Context(), c.id, transport)
ctx = obsreport.StartTraceDataReceiveOp(ctx, c.id, transport)
c.obsrecv = obsreport.NewReceiver(obsreport.ReceiverSettings{ReceiverID: c.id, Transport: transport})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You re-initialize the variable every request, this is not caching, you need to initialize it in the ctor of the tracesConsumerGroupHandler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now initialized in the ctor in latest commit

@bogdandrutu
Copy link
Member

@humivo are you ready to also upgrade contrib right away? Otherwise better to keep as deprecated the old funcs and implement them as NewReceiver + calls into the new funcs, then we can upgrade contrib and change receivers one by one.

@humivo
Copy link
Member Author

humivo commented May 19, 2021

@humivo are you ready to also upgrade contrib right away? Otherwise better to keep as deprecated the old funcs and implement them as NewReceiver + calls into the new funcs, then we can upgrade contrib and change receivers one by one.

Yes I will be ready to upgrade the contrib right away. But I am open to whichever option is preferred.

@bogdandrutu
Copy link
Member

Let's do the deprecation one, so I can ensure myself that I will not be the one doing it :)))

@humivo
Copy link
Member Author

humivo commented May 19, 2021

Let's do the deprecation one, so I can ensure myself that I will not be the one doing it :)))

Ok I'll update the PR right now with the deprecated old funcs

@bogdandrutu
Copy link
Member

@humivo waiting for that :)

@humivo
Copy link
Member Author

humivo commented May 20, 2021

@humivo waiting for that :)

Yup sorry for the delay! Just made the fix.

@bogdandrutu bogdandrutu merged commit f7674b2 into open-telemetry:main May 20, 2021
dashpole pushed a commit to dashpole/opentelemetry-collector that referenced this pull request Jun 14, 2021
…or/Exporter (open-telemetry#3227)

* Change Receiver to match pattern with structs and helpers

* Added support for ReceiverSettings

* Add receiver to end functions

* Add comments for new receiver

* Add entry to changelog

* Cache the recevier in structs

* Cache the receiver in other files

* Fix name for var and fix caching

* Fix caching so there is no race

* Fix unit tests

* Add deprecated old funcs back

* Fix comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants