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

Fix timestamps when metrics are submitted synchronously with date #68

Merged
merged 3 commits into from
Apr 3, 2020

Conversation

sfirrin
Copy link
Contributor

@sfirrin sfirrin commented Apr 3, 2020

What does this PR do?

Fixes a bug where the timestamp set with synchronous metrics was submitted to Datadog with the timestamp in milliseconds rather than the seconds that the API requires.

Metrics submitted with a timestamp in the future (i.e. a millisecond timestamp that's interpreted as a second timestamp) are given the current time, and this is handled in the async metric path, so this bug was only affecting sync metrics submitted with a date in the past, functionality added in #63.

Motivation

#67

Testing Guidelines

Tested this and it's working as intended.

Old log (millisecond timestamps):

{
    "status": "debug",
    "message": "datadog:sending payload with body {\"series\":[{\"metric\":\"lambda.test.dist_past\",\"points\":[[1585856360814,[123]]],\"tags\":[\"dd_lambda_layer:datadog-nodev12.16.1\"],\"type\":\"distribution\"},{\"metric\":\"lambda.test.dist_now\",\"points\":[[1585856364414,[123]]],\"tags\":[\"dd_lambda_layer:datadog-nodev12.16.1\"],\"type\":\"distribution\"}]}"
}

New log (second timestamps):

{
    "status": "debug",
    "message": "datadog:sending payload with body {\"series\":[{\"metric\":\"lambda.test.dist_past\",\"points\":[[1585939463,[123]]],\"tags\":[\"dd_lambda_layer:datadog-nodev12.16.1\"],\"type\":\"distribution\"},{\"metric\":\"lambda.test.dist_now\",\"points\":[[1585939467,[123]]],\"tags\":[\"dd_lambda_layer:datadog-nodev12.16.1\"],\"type\":\"distribution\"}]}"
}

@sfirrin sfirrin requested a review from a team as a code owner April 3, 2020 18:51
@@ -4,7 +4,7 @@ import { Distribution } from "./model";
describe("Batcher", () => {
it("joins metrics with different tag orders", () => {
const batcher = new Batcher();
const timestamp = new Date(1559928315);
const timestamp = new Date(1559928315000);
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 converted these second timestamps to milliseconds since Date's constructor takes milliseconds. The timestamps in the payloads being tested remain in seconds.

@sfirrin sfirrin merged commit 3168187 into master Apr 3, 2020
@sfirrin sfirrin deleted the stephenf/fix-sync-api-timestamp branch April 3, 2020 19:26
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