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

Add Datadog::Registry #200

Merged
merged 2 commits into from
Oct 19, 2017
Merged

Add Datadog::Registry #200

merged 2 commits into from
Oct 19, 2017

Conversation

p-lambert
Copy link
Member

@p-lambert p-lambert commented Sep 26, 2017

This PR provides the Registry abstraction that will help us to refactor the configuration API. The idea is to provide a clear interface for adding/retrieving different integrations and to decouple the Datadog::Monkey from it.

The PR also includes a Registerable module that provides a #register_as convenience method to let different integrations to "self-register" themselves.

@p-lambert p-lambert force-pushed the pedro/create-module-registry branch from 2cce8ca to fc6e980 Compare September 26, 2017 19:18
@palazzem palazzem added this to the 0.9.0 milestone Sep 27, 2017
@palazzem palazzem mentioned this pull request Sep 27, 2017
@palazzem palazzem self-requested a review September 27, 2017 03:40
@palazzem palazzem added core Involves Datadog core libraries do-not-merge/WIP Not ready for merge labels Sep 27, 2017
@palazzem
Copy link
Contributor

Just as a note, a draft of the overall API is available here: https://gist.github.com/p-lambert/fd817fb19b8236e26d40eaca421cc40f

The idea is to provide this core API and to migrate one of our integrations so that it can be used as a template.

@p-lambert p-lambert force-pushed the pedro/create-module-registry branch 6 times, most recently from 8534170 to e179839 Compare September 29, 2017 20:23
@p-lambert p-lambert removed the do-not-merge/WIP Not ready for merge label Sep 29, 2017
@palazzem palazzem modified the milestones: 0.9.0, 0.10.0 Oct 6, 2017
@nerdrew
Copy link

nerdrew commented Oct 11, 2017

I like this I believe we should also remove anything related to rails from our lib/ddtrace.rb file. from the linked doc.

@p-lambert p-lambert force-pushed the pedro/create-module-registry branch from e179839 to f0b6e2e Compare October 16, 2017 18:51
@p-lambert p-lambert force-pushed the pedro/create-module-registry branch from f0b6e2e to 79941df Compare October 16, 2017 19:17
lib/ddtrace.rb Outdated
end

require 'ddtrace/monkey'
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a reason why it has been moved here and not at the top of the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. the problem is, Monkey is loading all integrations, and during their load time they're registering themselves in the Datadog.registry. So by the time monkey is required, we need Datadog.registry defined. Hence the move.

Once we have time I'd like to improve our startup process, so we rely less on ordering etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes after reading the rest of the PR I got that. Can you add a comment saying ^^? just in case someone else will work in the startup process in a few months.

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!

@@ -0,0 +1,42 @@
require_relative 'registry/registerable'
Copy link
Contributor

Choose a reason for hiding this comment

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

should be a require_relative?

Copy link
Member Author

@p-lambert p-lambert Oct 19, 2017

Choose a reason for hiding this comment

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

I usually prefer relative paths, but that is more a matter of style, I guess. I think require_relative tend to be more common in gems, specially when you're loading components that are associated.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

# Patchers should expose 2 methods:
# - patch, which applies our patch if needed. Should be idempotent,
# can be call twice but should just do nothing the second time.
# - patched?, which returns true if the module has been succesfully
# patched (patching might have failed if requirements were not here)
@patchers = { elasticsearch: Datadog::Contrib::Elasticsearch::Patcher,
Copy link
Contributor

Choose a reason for hiding this comment

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

finally we get rid of that 🎉

@mutex = Mutex.new
@registry = Datadog.registry
Copy link
Contributor

Choose a reason for hiding this comment

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

should we really keep Datadog.registry as a reference + attr_accessor? what is the use case to not use directly Datadog.registry?

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically by injecting the dependency we can test everything in isolation. Right now testing the Monkey class is a nightmare, because every time we create a new integration we have to update 10 lines of test in the Monkey. In my opinion Monkey tests should be agnostic of the existing contributions. Monkey should be responsible for calling #patch in contribution modules, that's it. By having that, we can write such tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

Good to go!

@mutex = Mutex.new
@registry = Datadog.registry
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -0,0 +1,42 @@
require_relative 'registry/registerable'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@palazzem palazzem merged commit df52c6d into master Oct 19, 2017
@palazzem palazzem deleted the pedro/create-module-registry branch October 19, 2017 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants