This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new d7352af60 fix(metrics): preserve raw samples when CSV dates are
unrepresentable (#6883)
d7352af60 is described below
commit d7352af60bc86f36cf51ae035b18b6a295548766
Author: pilichoumao <[email protected]>
AuthorDate: Fri Nov 27 12:01:24 2026 +0800
fix(metrics): preserve raw samples when CSV dates are unrepresentable
(#6883)
---
README.md | 5 ++
.../components/__tests__/MetricsExplorer.test.tsx | 30 ++++++++++
web/src/utils/metricsExplorerDiagnostics.test.ts | 70 ++++++++++++++++++++++
web/src/utils/metricsExplorerDiagnostics.ts | 8 ++-
4 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 284cd1f7a..b7666e909 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,11 @@ remaining CSV; blank rows and newlines inside quoted cells
do not count as
additional records. This record limit does not impose a file-byte or cell-size
limit: the browser still reads the selected file before parsing it.
+Metrics Explorer CSV exports retain the raw epoch and value of each accepted
scalar
+or histogram sample. If a finite timestamp is outside JavaScript Date's
representable
+range, its `Timestamp ISO` cell is empty; the raw sample and other rows remain
in the
+export.
+
## AI Assistant
Studio **hosts** a general-purpose agent CLI — Claude Code or Qoder, plus a
plain OpenAI-compatible
diff --git a/web/src/components/__tests__/MetricsExplorer.test.tsx
b/web/src/components/__tests__/MetricsExplorer.test.tsx
index d1a90b79c..00846ec21 100644
--- a/web/src/components/__tests__/MetricsExplorer.test.tsx
+++ b/web/src/components/__tests__/MetricsExplorer.test.tsx
@@ -1285,6 +1285,36 @@ describe('MetricsExplorer', () => {
expect(csv).not.toContain('"Message In TPS"');
});
+ it.each([false, true])(
+ 'exports raw out-of-range epochs without losing samples (mixed=%s)',
+ async (mixed) => {
+ const timestamp = 1e20;
+ vi.mocked(queryMetrics).mockResolvedValue({
+ ...metricData,
+ series: [
+ {
+ ...metricData.series[0],
+ values: [
+ ...(mixed ? [{ timestamp: 1_800_000_000, value: '42' }] : []),
+ { timestamp, value: '99' },
+ ],
+ histograms: [{ timestamp, histogram: { sum: '250', count: '10',
buckets: [] } }],
+ },
+ ],
+ });
+ const user = userEvent.setup();
+ renderWithProviders(<MetricsExplorer />);
+ await screen.findByRole('img', { name: 'Message In TPS time series' });
+ await user.click(screen.getByRole('button', { name: 'Message In TPS 导出
CSV' }));
+ expect(downloadCsv).toHaveBeenCalledTimes(1);
+ const csv = vi.mocked(downloadCsv).mock.calls[0][1];
+ expect(csv.split('\n')).toHaveLength(mixed ? 4 : 3);
+ expect(csv).toContain('"100000000000000000000","","99"');
+ expect(csv).toContain('"100000000000000000000","","250"');
+ if (mixed) expect(csv).toContain('"2027-01-15T08:00:00.000Z","42"');
+ },
+ );
+
it('opens series details from the clicked metric panel', async () => {
const user = userEvent.setup();
renderWithProviders(<MetricsExplorer />);
diff --git a/web/src/utils/metricsExplorerDiagnostics.test.ts
b/web/src/utils/metricsExplorerDiagnostics.test.ts
index b5b74d424..67e22707f 100644
--- a/web/src/utils/metricsExplorerDiagnostics.test.ts
+++ b/web/src/utils/metricsExplorerDiagnostics.test.ts
@@ -344,6 +344,76 @@ describe('metrics explorer diagnostics', () => {
}
});
+ it.each([
+ 1e20,
+ -1e20,
+ 8_640_000_000_001,
+ -8_640_000_000_001,
+ Number.MAX_VALUE,
+ -Number.MAX_VALUE,
+ ])('preserves scalar and histogram rows with an unrepresentable timestamp
%s', (timestamp) => {
+ const data: MetricData = {
+ resultType: 'matrix',
+ warnings: [],
+ series: [
+ {
+ labels: { cluster: 'prod' },
+ values: [
+ { timestamp: 0, value: '42' },
+ { timestamp, value: '99' },
+ ],
+ histograms: [{ timestamp, histogram: { sum: '250', count: '10',
buckets: [] } }],
+ },
+ ],
+ };
+ const rows = buildMetricCsvRows(data, metric, { profileName: 'p',
sourceName: 's' });
+ expect(rows).toHaveLength(3);
+ expect(rows.find((row) => row.timestamp ===
0)?.timestampIso).toBe('1970-01-01T00:00:00.000Z');
+ expect(
+ rows.find((row) => row.timestamp === timestamp && row.sampleType ===
'scalar'),
+ ).toMatchObject({
+ timestampIso: '',
+ value: 99,
+ labels: '{"cluster":"prod"}',
+ });
+ expect(
+ rows.find((row) => row.timestamp === timestamp && row.sampleType ===
'histogram'),
+ ).toMatchObject({
+ timestampIso: '',
+ value: 250,
+ histogramCount: 10,
+ histogramSum: 250,
+ });
+ const csv = buildMetricCsv(data, metric, { profileName: 'p', sourceName:
's' });
+ expect(csv.split('\n')).toHaveLength(4);
+ expect(csv).toContain(String(timestamp));
+ expect(csv).toContain('"99"');
+ expect(csv).toContain('"250"');
+ expect(csv).not.toContain('Invalid Date');
+ });
+
+ it.each([0, -1, 1_800_000_000.123, 8_640_000_000_000, -8_640_000_000_000])(
+ 'retains the ISO timestamp for representable scalar and histogram epochs
%s',
+ (timestamp) => {
+ const data: MetricData = {
+ resultType: 'matrix',
+ warnings: [],
+ series: [
+ {
+ labels: {},
+ values: [{ timestamp, value: '42' }],
+ histograms: [{ timestamp, histogram: { sum: '250', count: '10',
buckets: [] } }],
+ },
+ ],
+ };
+ const rows = buildMetricCsvRows(data, metric, { profileName: 'p',
sourceName: 's' });
+ expect(rows).toHaveLength(2);
+ expect(
+ rows.every((row) => row.timestampIso === new Date(timestamp *
1000).toISOString()),
+ ).toBe(true);
+ },
+ );
+
it('creates deterministic CSV filenames from metric identity', () => {
expect(buildMetricCsvFilename(metric, 1_800_000_000_000)).toBe(
'rocketmq-studio-metrics-message-in-tps-2027-01-15T08-00-00-000Z.csv',
diff --git a/web/src/utils/metricsExplorerDiagnostics.ts
b/web/src/utils/metricsExplorerDiagnostics.ts
index 529ac165d..1dea1fe72 100644
--- a/web/src/utils/metricsExplorerDiagnostics.ts
+++ b/web/src/utils/metricsExplorerDiagnostics.ts
@@ -286,6 +286,12 @@ export const summarizeMetricData = (data: MetricData):
MetricResultSummary => {
};
};
+const metricTimestampIso = (timestamp: number): string => {
+ const date = new Date(timestamp * 1000);
+ // Keep the raw sample when a finite epoch exceeds Date's representable
range.
+ return Number.isNaN(date.getTime()) ? '' : date.toISOString();
+};
+
export const buildMetricCsvRows = (
data: MetricData,
metric: MetricMapping,
@@ -313,7 +319,7 @@ export const buildMetricCsvRows = (
labels,
sampleType: sample.kind,
timestamp: sample.timestamp,
- timestampIso: new Date(sample.timestamp * 1000).toISOString(),
+ timestampIso: metricTimestampIso(sample.timestamp),
value: sample.value,
histogramCount: sample.histogramCount,
histogramSum: sample.histogramSum,