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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datadog-lambda-js",
"version": "2.20.0",
"version": "2.21.0",
"description": "Lambda client library that supports hybrid tracing in node js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/batcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

const distribution1 = new Distribution(
"my-dist",
[{ timestamp, value: 1 }, { timestamp, value: 2 }],
Expand All @@ -29,7 +29,7 @@ describe("Batcher", () => {

it("doesn't join metrics with different tags", () => {
const batcher = new Batcher();
const timestamp = new Date(1559928315);
const timestamp = new Date(1559928315000);
const distribution1 = new Distribution(
"my-dist",
[{ timestamp, value: 1 }, { timestamp, value: 2 }],
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Distribution } from "./model";

describe("Distribution", () => {
it("converts to a APIMetric", () => {
const timestamp = new Date(1559928315);
const timestamp = new Date(1559928315000);

const distribution = new Distribution(
"my-dist",
Expand Down
4 changes: 3 additions & 1 deletion src/metrics/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class Distribution implements Metric {

public toAPIMetrics(): APIMetric[] {
const points: APIPoint[] = this.points.map((point) => {
return [point.timestamp.getTime(), [point.value]];
// Convert the milliseconds we get from getTime to seconds for the Datadog API
const unixSeconds = Math.floor(point.timestamp.getTime() / 1000);
return [unixSeconds, [point.value]];
});
return [
{
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MockAPIClient implements Client {
}

function makeMetric(name: string = "my-metric", value: number = 1): Metric {
const timestamp = new Date(1559941498);
const timestamp = new Date(1559941498000);
return new Distribution(name, [{ timestamp, value }], "tag:a", "tag:b");
}

Expand Down