-
Notifications
You must be signed in to change notification settings - Fork 375
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::Worker and extensions #973
Conversation
a0b11e2
to
5432b63
Compare
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.
Great stuff, very well flushed out implementation. 👍 🎉
end | ||
|
||
def buffer | ||
@buffer ||= [] |
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.
Is it ok to use a simple array here, as it is not thread-safe?
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 suppose it depends on your worker implementation, and how (also if) it uses threads. The buffer itself should be made thread safe if you require it; we do this by overriding the buffer for the TraceWriter
. This is just a default implementation.
# Stub conditional wait so tests run faster | ||
before { allow(worker.send(:shutdown)).to receive(:wait) } |
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.
Awesome quality of life improvement with this. 💯
5432b63
to
0abe5d9
Compare
0abe5d9
to
9f7c7be
Compare
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.
Looking forward to seeing these changes in the wild! ⛵️🌊
Extracted from #879
This pull request adds the
Datadog::Worker
base class and its extension modules. It is intended to act as the foundation for background processes that run within the tracing library. Examples of these would be "writing traces to the agent" and "flushing runtime metrics to Statsd".At its core, there is the
Datadog::Worker
class which itself defines a simple task, and aperform
function.Each background process would extend this base class, and define its work behavior within. e.g.
Because each worker might need to behave differently (e.g. polling, queuing, threading etc) these behaviors are provided through modules
Polling
,Async::Thread
,IntervalLoop
,Queue
which can then be composed into the worker. Each of these layers wrap theperform
function with additional behavior, and provide new functions to the worker. e.g.As described in #879, some of the benefits of implementing this include:
SyncWriter
by having one common definition for trace flushing behavior, then havingAsyncTraceWriter
decorated upon that.AsyncTraceWriter
can optionally automatically switch to synchronous writing when forked (addresses the need for SyncWriter in integrations like Resque.)The
Datadog::Worker
and its other components will be used in another set of PRs which will introduce theTraceWriter
andRuntimeMetrics
workers.