-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from 4 commits
9bcd342
9afe1a1
9146a1c
8383b3b
da5feeb
fb8f7f6
ddd738e
439f27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,17 +140,24 @@ export class MetricsListener { | |
forceAsync: boolean, | ||
...tags: string[] | ||
) { | ||
const dist = new Distribution(name, [{ timestamp: metricTime, value }], ...tags); | ||
|
||
if (this.isExtensionRunning) { | ||
this.statsDClient?.distribution(name, value, undefined, tags); | ||
return; | ||
const isMetricTimeValid = Date.parse(metricTime.toString()) > 0; | ||
if (isMetricTimeValid) { | ||
// 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 { | ||
this.statsDClient?.distribution(name, value, undefined, tags); | ||
return; | ||
} | ||
} | ||
if (this.config.logForwarding || forceAsync) { | ||
writeMetricToStdout(name, value, metricTime, tags); | ||
return; | ||
} | ||
|
||
const dist = new Distribution(name, [{ timestamp: metricTime, value }], ...tags); | ||
|
||
if (!this.apiKey) { | ||
const errorMessage = "api key not configured, see https://dtdg.co/sls-node-metrics"; | ||
logError(errorMessage); | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yessir 👍 |
||
this.sendDistributionMetricWithDate(name, value, metricTime, forceAsync, ...tags); | ||
} | ||
|
||
private async createProcessor(config: MetricsConfig, apiKey: Promise<string>) { | ||
|
There was a problem hiding this comment.
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 ifthis.config.logForwarding
is set totrue
, it will both process it and then write it tostdout
.There was a problem hiding this comment.
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 iflogForwarding
is true and the extension is running, then it will return on L153 and not processThere was a problem hiding this comment.
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!