Skip to content

datadog: time_util portion of new tracing library#25003

Merged
yanavlasov merged 7 commits into
envoyproxy:mainfrom
DataDog:david.goffredo/dd-trace-cpp-1/9-time_util
Jan 27, 2023
Merged

datadog: time_util portion of new tracing library#25003
yanavlasov merged 7 commits into
envoyproxy:mainfrom
DataDog:david.goffredo/dd-trace-cpp-1/9-time_util

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 small component that will be used in the future when more of the new library is integrated into the Datadog tracing extension.

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 18, 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 @mattklein123

🐱

Caused by: #25003 was opened by dgoffredo.

see: more, trace.

@dgoffredo
Copy link
Copy Markdown
Contributor Author

/assign @jmarantz

@repokitteh-read-only
Copy link
Copy Markdown

dgoffredo is not allowed to assign users.

🐱

Caused by: a #25003 (comment) was created by @dgoffredo.

see: more, trace.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
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.

lgtm mostly with some minor comments. still need to read the test.

Comment thread source/extensions/tracers/datadog/time_util.h Outdated
Comment thread source/extensions/tracers/datadog/time_util.h Outdated
Comment thread source/extensions/tracers/datadog/time_util.cc Outdated
Comment thread source/extensions/tracers/datadog/time_util.cc Outdated
// specified `SystemTime`. Use the optionally specified
// `datadog::tracing::Clock` to read the current time. If a clock is not
// specified, then the default clock is used.
datadog::tracing::TimePoint estimateTime(SystemTime);
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.

is this an estimate really? or are we just converting a SystemTime to a DataDog time?

Would it be clearer at call-sites to call this convertSystemTimeToDataDog() ?

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.

Yes, it's an estimate. The background is explained here as part of the original pull request (that readme will be added again in a subsequent pull request).

Envoy has a time type that, like Go's, contains both a system time point and a steady ("monotonic") time point. However, only the system time is exposed to the tracing subsystem. Not sure why.

This is problematic for the new library (dd-trace-cpp), because it uses the steady time to calculate the duration of a span (end.tick - begin.tick). So, we need to get a steady clock time from a given system clock time. The scheme is to measure the current system/steady time, compare the system part with the given system time, and then adjust the measured steady time accordingly. This is correct if the system clock has not been adjusted since the given system time was measured. It's incorrect otherwise, hence an estimate.

What do you think about all this? Is there a better way?

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.

sgtm thanks. The above explanation might be good to throw into the code here as a comment.

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
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.

looks pretty good. It'd be good to understand if we can just use MonotonicTime if that's what we need.

datadog::tracing::TimePoint estimateTime(SystemTime wall, const datadog::tracing::Clock& clock) {
datadog::tracing::TimePoint point = clock();
if (point.wall > wall) {
point.tick -= point.wall - wall;
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.

should we also verify that the delta we are subtracting is less than point.tick?

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.

point.tick is a time point, while point.wall - wall is a duration, so no.

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.

got it, thanks!

namespace Tracers {
namespace Datadog {

datadog::tracing::TimePoint estimateTime(SystemTime wall) {
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.

why are we not plumbing the MonotonicTime (or maybe just the TimeSource into here?

Copy link
Copy Markdown
Contributor Author

@dgoffredo dgoffredo Jan 19, 2023

Choose a reason for hiding this comment

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

The goal is to implement the interfaces defined in https://github.com/envoyproxy/envoy/blob/main/envoy/tracing/trace_driver.h.

There are two time points in those interfaces: Span::spawnChild and Driver::startSpan. Both take SystemTime only, without a monotonic counterpart.

If I were redesigning the interface, I would have spawnChild and startSpan take both a SystemTime and a MonotonicTime, and additionally have finishSpan take a MonotonicTime (or both, but at least the MonotonicTime).

I thought it would be inappropriate to propose to change the interface and everything that implements it.

What do you think?

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.

I think it's fine to push forward with this but we should also try to correct the API to get the best results. It's not that hard to change these APIs; there's probably not that much fallout, particularly if you just plumb through some additional fields and don't remove the SystemTime.

jmarantz
jmarantz previously approved these changes Jan 20, 2023
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.

/assign-from @envoyproxy/senior-maintainers

@repokitteh-read-only
Copy link
Copy Markdown

@envoyproxy/senior-maintainers assignee is @yanavlasov

🐱

Caused by: a #25003 (review) was submitted by @jmarantz.

see: more, trace.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Jan 23, 2023

/assign

yanavlasov
yanavlasov previously approved these changes Jan 23, 2023
@yanavlasov yanavlasov enabled auto-merge (squash) January 23, 2023 15:34
Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
auto-merge was automatically disabled January 23, 2023 16:51

Head branch was pushed to by a user without write access

@dgoffredo dgoffredo dismissed stale reviews from yanavlasov and jmarantz via c8e308b January 23, 2023 16:51
@yanavlasov
Copy link
Copy Markdown
Contributor

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #25003 (comment) was created by @yanavlasov.

see: more, trace.

@dgoffredo
Copy link
Copy Markdown
Contributor Author

Code coverage for source/extensions/tracers is lower than limit of 95.4 (95.3)

@dgoffredo
Copy link
Copy Markdown
Contributor Author

https://storage.googleapis.com/envoy-pr/3629d09/coverage/source/extensions/tracers/datadog/time_util.cc.gcov.html

I could write a test for that overload. Will do this tomorrow.

@yanavlasov
Copy link
Copy Markdown
Contributor

/wait

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

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit didn't fail.

🐱

Caused by: a #25003 (comment) was created by @yanavlasov.

see: more, trace.

@yanavlasov yanavlasov merged commit c476539 into envoyproxy:main Jan 27, 2023
@dgoffredo
Copy link
Copy Markdown
Contributor Author

Thanks @yanavlasov @jmarantz

VishalDamgude pushed a commit to freshworks-oss/envoy that referenced this pull request Feb 2, 2023
* datadog: time_util without tests

Signed-off-by: David Goffredo <david.goffredo@datadoghq.com>
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.

5 participants