@mantiq/heartbeat 0.5.21 → 0.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -138,9 +138,12 @@ export class MetricsCollector {
|
|
|
138
138
|
const now = Date.now()
|
|
139
139
|
const bucket = Math.floor(now / 60_000) // 1-minute buckets
|
|
140
140
|
|
|
141
|
+
// Snapshot current counters so new increments during the write are not lost
|
|
142
|
+
const counterSnapshot = new Map(this.counters)
|
|
143
|
+
|
|
141
144
|
try {
|
|
142
145
|
// Flush counters
|
|
143
|
-
for (const [key, value] of
|
|
146
|
+
for (const [key, value] of counterSnapshot) {
|
|
144
147
|
const { name, tags } = this.parseMetricKey(key)
|
|
145
148
|
await this.store.insertMetric(name, 'counter', value, tags, 60, bucket)
|
|
146
149
|
}
|
|
@@ -159,10 +162,11 @@ export class MetricsCollector {
|
|
|
159
162
|
await this.store.insertMetric(name, 'histogram', avg, tags, 60, bucket)
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
// Reset counters after
|
|
165
|
+
// Reset counters only after successful write — if the write failed,
|
|
166
|
+
// data is preserved for the next flush attempt.
|
|
163
167
|
this.counters.clear()
|
|
164
168
|
} catch {
|
|
165
|
-
//
|
|
169
|
+
// Write failed — counters are preserved for the next flush attempt
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
|