Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Dec 27, 2023
1 parent 397f898 commit ab23eb8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions services/rotor/src/lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export function createMetrics(producer?: Producer): Metrics {
await Promise.all([
resOld
.then(async r => {
if (r.ok) {
log.atInfo().log(`Flushed metrics events(old): ${((await r.json()) as any).state.successfulRows}`);
} else {
if (!r.ok) {
log.atError().log(`Failed to flush metrics events(old): ${r.status} ${r.statusText}`);
}
})
Expand All @@ -110,9 +108,7 @@ export function createMetrics(producer?: Producer): Metrics {
}),
res
.then(async r => {
if (r.ok) {
log.atInfo().log(`Flushed metrics events: ${((await r.json()) as any).state.successfulRows}`);
} else {
if (!r.ok) {
log.atError().log(`Failed to flush metrics events: ${r.status} ${r.statusText}`);
}
})
Expand All @@ -128,9 +124,10 @@ export function createMetrics(producer?: Producer): Metrics {
if (length > 0) {
const sw = stopwatch();
try {
await flush([...buffer]);
const copy = [...buffer];
await flush(copy);
buffer.length = 0;
log.atInfo().log(`Periodic flushing ${length} metrics events took ${sw.elapsedPretty()}`);
log.atInfo().log(`Periodic flushing ${copy.length} metrics events took ${sw.elapsedPretty()}`);
} catch (e) {
log.atError().withCause(e).log(`Failed to flush metrics`);
}
Expand Down Expand Up @@ -182,9 +179,15 @@ export function createMetrics(producer?: Producer): Metrics {
});
}
if (buffer.length >= max_batch_size) {
log.atInfo().log(`Flushing ${buffer.length} metrics events`);
const sw = stopwatch();
const copy = [...buffer];
setImmediate(() => flush(copy));
setImmediate(async () =>
flush(copy)
.then(() => log.atInfo().log(`Flushed ${copy.length} metrics events. Took: ${sw.elapsedPretty()}`))
.catch(e => {
log.atError().withCause(e).log(`Failed to flush metrics`);
})
);
buffer.length = 0;
}
},
Expand Down

0 comments on commit ab23eb8

Please sign in to comment.