Skip to content

datadog: event scheduling portion of new tracing library#25170

Merged
jmarantz merged 12 commits into
envoyproxy:mainfrom
DataDog:david.goffredo/dd-trace-cpp-6/9-event_scheduler
Mar 10, 2023
Merged

datadog: event scheduling portion of new tracing library#25170
jmarantz merged 12 commits into
envoyproxy:mainfrom
DataDog:david.goffredo/dd-trace-cpp-6/9-event_scheduler

Conversation

@dgoffredo
Copy link
Copy Markdown
Contributor

This is part of the initiative described in #23958.

This revision introduces a new library dependency for Datadog tracing, and adds a component that will be used in the future when more of the new library is integrated into the Datadog tracing extension.

EventScheduler allows the new tracing library to schedule a recurring timer that fires every two seconds; this is when the tracing library will send its batched traces to the Datadog Agent.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
@repokitteh-read-only repokitteh-read-only Bot added the deps Approval required for changes to Envoy's external dependencies label Jan 25, 2023
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @moderation

🐱

Caused by: #25170 was opened by dgoffredo.

see: more, trace.

@moderation
Copy link
Copy Markdown
Contributor

@dgoffredo
Copy link
Copy Markdown
Contributor Author

Yes, it's intentional. In retrospect, it might have been better to first add only the dependency changes, wait for those changes to be merged into main, and then propose the lowest level of new code.

I wanted instead to propose the first round of pull requests ASAP, and so duplicated the shared added dependency in all of those lowest level PRs.

I could create a dedicated dependency PR and rebase the others onto it, if you like.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Feb 8, 2023

ping myself, sorry for the delay. 😞

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for you contribution and some comments are added. And please merge the main to resolve the conflict.

Comment thread source/extensions/tracers/datadog/event_scheduler.cc Outdated
Comment thread source/extensions/tracers/datadog/event_scheduler.cc Outdated
Comment thread source/extensions/tracers/datadog/event_scheduler.cc
Comment thread source/extensions/tracers/datadog/event_scheduler.h Outdated
@dgoffredo
Copy link
Copy Markdown
Contributor Author

Thanks for the review. I'll push a commit and merge from main within the next couple of days.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Feb 15, 2023

/wait ci and conflict.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
@dgoffredo
Copy link
Copy Markdown
Contributor Author

dgoffredo commented Feb 15, 2023

Code coverage for source/extensions/tracers/datadog is lower than limit of 96.6 (96.5)

Hmmm. Looks like calling config_json in a test might help: https://storage.googleapis.com/envoy-pr/0f305a0/coverage/source/extensions/tracers/datadog/event_scheduler.cc.gcov.html

Also interesting in the logger, which was recently merged, I'd except these kinds of tests: https://github.com/envoyproxy/envoy/pull/25025/files#diff-ab9f820e99ec92b52dd7334d825976ab5b5e2240dc9693e58fd4c99fab4c7dddR96-R103
to cover these kinds of branches: https://storage.googleapis.com/envoy-pr/9763eb9/coverage/source/extensions/tracers/datadog/logger.cc.gcov.html
but they don't.

I'll have to look closer.

[edit]: Ah, the logger and its sink(s) have separate levels. It's the logger level that matters most.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
wbpcode
wbpcode previously approved these changes Feb 16, 2023
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for you great contribution.

cc @jmarantz for final review or merge.

@dgoffredo
Copy link
Copy Markdown
Contributor Author

Ping @jmarantz

Copy link
Copy Markdown
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

Sorry for the delay this fell off my radar.

I found a few minor suggestions, but I'm not going to be available for the next few days. Whatever you decide is fine.

@wbpcode feel free to make the final call and merge for this.

Comment thread source/extensions/tracers/datadog/event_scheduler.cc Outdated
Comment thread source/extensions/tracers/datadog/event_scheduler.cc Outdated
Comment thread source/extensions/tracers/datadog/event_scheduler.h Outdated
Comment thread test/extensions/tracers/datadog/event_scheduler_test.cc Outdated
Comment thread test/extensions/tracers/datadog/event_scheduler_test.cc Outdated
// separate tests.
TEST(DatadogEventSchedulerTest, ScheduleRecurringEventEnablesATimer) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
auto* const timer_ = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: don't use an underscore suffix for a local. Comment on memory management: who deletes timer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This pattern is copied from here:

timer_ = new NiceMock<Event::MockTimer>(&tls_.dispatcher_);

Which was copied from here:

timer_ = new NiceMock<Event::MockTimer>(&tls_.dispatcher_);

It occurs to me now that the raw pointer is probably a substitute for "optional" in the original code.

who deletes timer?

Nobody, it's leaked, as in the copied-from code.

I'll see if it works the same with just a testing::NiceMock<Event::MockTimer> on the stack (no pointer). That'd be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's not for lack of optional. This is indeed the intended usage of MockTimer:

// Ownership of each MockTimer instance is transferred to the (caller of) dispatcher's
// createTimer_(), so to avoid destructing it twice, the MockTimer must have been dynamically
// allocated and must not be deleted by it's creator.
MockTimer(MockDispatcher* dispatcher);


TEST(DatadogEventSchedulerTest, TriggeredTimerInvokesCallbackAndReschedulesItself) {
testing::NiceMock<ThreadLocal::MockInstance> thread_local_storage_;
auto* const timer_ = new testing::NiceMock<Event::MockTimer>(&thread_local_storage_.dispatcher_);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

dito

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
@jmarantz jmarantz merged commit 89cefef into envoyproxy:main Mar 10, 2023
@dgoffredo
Copy link
Copy Markdown
Contributor Author

Thanks!

Another week has gone by and I still haven't produced the final pair of pull requests. Those are coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deps Approval required for changes to Envoy's external dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants