Skip to content

Commit

Permalink
FIX: query with incomplete span
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Brien committed Dec 8, 2024
1 parent 27a098b commit e2ed655
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
9 changes: 7 additions & 2 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ class CustomMetrics {
spans: [{ points: [{ count: 0, sum: 0 }] }],
});
let current = elt.spans[0].points.at(-1);
current.count += point.count;
current.sum += point.sum;
if (current) {
current.count += point.count;
current.sum += point.sum;
}
elt.count += point.count;
elt.sum += point.sum;
if (buffer.force ||
Expand Down Expand Up @@ -334,6 +336,9 @@ class CustomMetrics {
let interval = span.period / span.samples;
let count = Math.ceil(period / interval);
let index = span.points.length - (span.end - start) / interval;
if (index < 0) {
index = 0;
}
span.points = span.points.slice(index, index + count);
if (options.accumulate) {
result = this.accumulateMetric(metric, span, statistic, owner, timestamp);
Expand Down
9 changes: 7 additions & 2 deletions dist/mjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ export class CustomMetrics {
spans: [{ points: [{ count: 0, sum: 0 }] }],
});
let current = elt.spans[0].points.at(-1);
current.count += point.count;
current.sum += point.sum;
if (current) {
current.count += point.count;
current.sum += point.sum;
}
elt.count += point.count;
elt.sum += point.sum;
if (buffer.force ||
Expand Down Expand Up @@ -342,6 +344,9 @@ export class CustomMetrics {
let interval = span.period / span.samples;
let count = Math.ceil(period / interval);
let index = span.points.length - (span.end - start) / interval;
if (index < 0) {
index = 0;
}
span.points = span.points.slice(index, index + count);
if (options.accumulate) {
result = this.accumulateMetric(metric, span, statistic, owner, timestamp);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-metrics",
"version": "1.0.4",
"version": "1.0.5",
"description": "Custom metrics for AWS",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ export class CustomMetrics {
Add point value to the lowest span and to the elt (to manage when to persist)
*/
let current = elt.spans[0].points.at(-1)
current.count += point.count
current.sum += point.sum
if (current) {
current.count += point.count
current.sum += point.sum
}
elt.count += point.count
elt.sum += point.sum

Expand Down Expand Up @@ -645,6 +647,9 @@ export class CustomMetrics {
let interval = span.period / span.samples
let count = Math.ceil(period / interval)
let index = span.points.length - (span.end - start) / interval
if (index < 0) {
index = 0
}
span.points = span.points.slice(index, index + count)

if (options.accumulate) {
Expand Down

0 comments on commit e2ed655

Please sign in to comment.