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

[SVLS-4422] Support metrics with timestamps when the Extension is running #522

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

DylanLovesCoffee
Copy link
Contributor

@DylanLovesCoffee DylanLovesCoffee commented Mar 20, 2024

What does this PR do?

Allows sendDistributionMetricWithDate to submit a metric with a timestamp when the Extension is running. Neither hot-shots nor Dogstatsd supports historical distribution metrics (more on the latter here and here).

The ability to send metrics with timestamps already existed but did not work when using the Extension.

Motivation

Testing Guidelines

Unit test + manual tests. Example of one invocation using the following:

const MS_PER_MINUTE = 60000;
const timestamp = new Date(Date.now() - MS_PER_MINUTE);
sendDistributionMetricWithDate("dylan.test.past", 1, timestamp);
sendDistributionMetric("dylan.test.present", 1); // tracer.dogstatsd.distribution("dylan.test.present", 1) also works

Screenshot 2024-03-20 at 12 34 36 PM

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@DylanLovesCoffee DylanLovesCoffee requested a review from a team as a code owner March 20, 2024 16:45
@duncanista
Copy link
Contributor

Do not merge before #519

@DylanLovesCoffee
Copy link
Contributor Author

Do not merge before #519

should I just change the base to jordan.gonzalez/lazy-load-fallback-processor?

@@ -167,7 +174,9 @@ export class MetricsListener {
}

public sendDistributionMetric(name: string, value: number, forceAsync: boolean, ...tags: string[]) {
this.sendDistributionMetricWithDate(name, value, new Date(Date.now()), forceAsync, ...tags);
// The Extension doesn't support distribution metrics with timestamps. Use sendDistributionMetricWithDate instead.
const metricTime = this.isExtensionRunning ? new Date(0) : new Date(Date.now());
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of setting a metric time if the extension is still gonna ignore it? (as understood by the purpose of the PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't too sure if changing the type for this function's parameter would introduce a breaking change to users or not, so I figured I'd rather just not change the type of the metricTime param from Date -> Date | undefined. But if it's not going to change much then I can just update the type to Date | undefined and pass undefined here

Copy link
Contributor

@duncanista duncanista Mar 21, 2024

Choose a reason for hiding this comment

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

I think the workaround makes sense. Changing the API would definitely make a breaking change, so that's a no in the mean time. Can you leave a note in the form of // TODO: Next breaking change, change API for metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yessir 👍

// Only create the processor to submit metrics to the API when a user provides a valid timestamp as
// Dogstatsd does not support timestamps for distributions.
this.currentProcessor = this.createProcessor(this.config, this.apiKey);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try to avoid having if-else blocks. Also, wouldn't this need a return? This seems like it would process the metric if the extension is running but if this.config.logForwarding is set to true, it will both process it and then write it to stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The if here just creates the processor since it's typically never needed when using the extension, except for this special case, otherwise always send to statsd. Later on the metric is added to the processor at the end of the function (unchanged). So if logForwarding is true and the extension is running, then it will return on L153 and not process

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, thanks for explaining!

Copy link
Contributor

@duncanista duncanista 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 fixing this!

@DylanLovesCoffee DylanLovesCoffee merged commit b20c40e into main Mar 27, 2024
25 checks passed
@DylanLovesCoffee DylanLovesCoffee deleted the dylan/dist-metric-time branch March 27, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants