-
Notifications
You must be signed in to change notification settings - Fork 190
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
feat: Introduced new APM module to handle RabbitMQ messaging #1347
Conversation
❕ Build Aborted
Expand to view the summary
Build stats
Steps errorsExpand to view the steps failures
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekrucio thanks for opening the PR!
The Extractor interface feels a bit too specific to the pattern you are using in your application. Because streadway/amqp provides a fairly general API, I think we may have to provide a toolkit of functions for creating transactions or spans for consumers, rather than always assuming a one-to-one mapping between messages and transactions (effectively this pattern, IIANM: https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-messaging.md#passive-message-reception)
Are you defining a Publisher
interface in your code, so you can use either an amqp.Channel
or an amqpstreadway.Publisher
? If that is the case, I think the Publisher
could stay - but it does not need to be an interface; it should instead be a struct type.
My idea about the Publisher interface was to be some kind of a wrapper over the ch.Publish and thus the way to get access to this "custom publisher" we should call Wrap(ch *amqp.Channel). I completely agree with the unneeded and wrong "contract" initiated by the current implementation of the Extractor. Should the change to return trace context be suffiecient to fix this? |
👍
I think starting out minimally is fine, and it can be filled in later. For Publisher, I'm mostly just bothered about exporting an interface rather than a concrete struct type. What do you think about having a Channel wrapper struct type that embeds amqp.Channel, and overwrites its Publish method? Something like: // WrappedChannel wraps amqp.Channel such that Publish calls are traced,
// and trace context is added to published messages.
//
// Trace context must be supplied using Channel.WithContext.
type WrappedChannel struct {
*amqp.Channel
ctx context.Context
}
func WrapChannel(ch amqp.Channel) WrappedChannel {
...
}
func (c WrappedChannel) WithContext(ctx context.Context) WrappedChannel {
return WrappedChannel{Channel: c.Channel, ctx: ctx}
}
// Publish publishes a message and returns an error in encountered.
func (c WrappedChannel) Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error {
...
}
👍 Changing |
That is better, I agree, will do it that way 👍 . |
@axw Just fyi I made the necessary changes (or at least I think so). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ekrucio thanks for the changes, this looks like it's in a good shape now. I've left a few more comments, otherwise it needs some tests, copyright headers, and doc comments.
Co-authored-by: Andrew Wilkins <axwalk@gmail.com>
@axw Sorry, I didn't read you whole comment and requested a review before resolving everything mentioned here ->
Will add those 👍 |
@axw Added tests but due to the conctrete implementation of this library the Publish test is less than pretty. |
@axw I've added the proposed fixes. Also your idea about the in-memory AMQP server was top! I was ashamed of the way I did the test initially and it's much better that way. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ekrucio, the main code all looks good, and the new test is nice :)
I have some concerns about the test being potentially flaky, for which I've left a suggested fix.
Other than that, there's just a few other things that need to be updated:
- please run
make scripts/Dockerfile-testing update-modules update-licenses fmt
(you can verify the results by runningmake precheck
-- this is required to pass by CI) - please add a small entry to CHANGELOG.asciidoc, and to docs/instrumenting.asciidoc. See https://github.com/elastic/apm-agent-go/pull/1301/files for an example of where a new instrumentation module was added.
Co-authored-by: Andrew Wilkins <axwalk@gmail.com>
@axw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be completely mistaken and I could just be doing something wrong. Can you assist me with those steps, or give me pointers if there's something else I'm missing.
You can use a newer version of Go than 1.15, that's just the minimum for using the agent. I can take a look at fixing these things up and push to your branch.
Would you please add the docs/instrumenting.asciidoc section?
I can't push to your branch. If you're comfortable doing so, please enable that at https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork#enabling-repository-maintainer-permissions-on-existing-pull-requests |
💚 CLA has been signed |
@axw We had to raise the root Go version to Go 1.17 because one of the packages -> "golang.org/x/sys/unix" requires 1.17, otherwise it doesn't want to compile. |
Raising the minimum version for all modules is a showstopper. We support Go 1.15+, and changing that will require a major version bump. Tests have been passing across the repo with Go 1.15. I don't see any changes to Also, while running the tests, I noticed some race conditions and other errors originating from garagemq and its dependencies. If you run |
Sorry if this is a moot point but in the issue it does mention support for streadway/amqp. However this is now a unmaintained fork and in the README states. "This repository is NOT ACTIVELY MAINTAINED. Consider using a different fork instead: rabbitmq/amqp091-go." I am not sure if this changes any implementation within this PR but would it be best to move forward with supporting rabbitmq/amqp091-go instead. I am quite busy with work at the moment but if this pull request is stale I may have a go at implementing a module for RabbitMQ over the coming months. |
I'm sorry, I've been pretty busy lately and the last I remember is I think the PR is ready to be merged with the exception of changes related to the Go modules which I didn't had to look at. |
Sure, that's fine - go ahead and close/reopen when you're ready. It may take a while before I get to it though. |
Messaging systems are one of the main components powering distributed microservices. We're tightly dependent on RabbitMQ messaging in our codebase, and especially this package streadway/amqp .
This PR is related to issue Feature #37 but does not resolve it, it is simply a POC.
If you're okay with those changes I will add tests.