-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from DataDog/stephenf/fix-async-metric-timestamps
Fix timestamps for async metrics
- Loading branch information
Showing
5 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { buildMetricLog } from "./build-metric-log"; | ||
|
||
describe("buildMetricLog", () => { | ||
jest.spyOn(Date, "now").mockImplementation(() => 1487076708123); | ||
it("handles empty tag list", () => { | ||
expect(buildMetricLog("my.test.metric", 1337, [])).toStrictEqual( | ||
'{"e":1487076708.123,"m":"my.test.metric","t":[],"v":1337}\n', | ||
); | ||
}); | ||
it("writes timestamp in Unix seconds", () => { | ||
expect(buildMetricLog("my.test.metric", 1337, ["region:us", "account:dev", "team:serverless"])).toStrictEqual( | ||
'{"e":1487076708.123,"m":"my.test.metric","t":["region:us","account:dev","team:serverless"],"v":1337}\n', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Builds the string representation of the metric that will be written to logs | ||
export function buildMetricLog(name: string, value: number, tags: string[]) { | ||
return `${JSON.stringify({ | ||
// Date.now() returns Unix time in milliseconds, we convert to seconds for DD API submission | ||
e: Date.now() / 1000, | ||
m: name, | ||
t: tags, | ||
v: value, | ||
})}\n`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters