FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

make csvjsonarray timestamps always numeric by ktsaou · Pull Request #23117 · netdata/netdata · GitHub

make csvjsonarray timestamps always numeric - #23117

Merged
ktsaou merged 1 commit into
netdata:masterfrom
ktsaou:csvjsonarray-numeric-timestamps
Jul 13, 2026
Merged

make csvjsonarray timestamps always numeric#23117
ktsaou merged 1 commit into
netdata:masterfrom
ktsaou:csvjsonarray-numeric-timestamps

Conversation

ktsaou commented Jul 13, 2026
edited by cubic-dev-ai Bot
Loading

Copy link
Copy Markdown
Member

Summary

format=csvjsonarray without seconds or ms in the options emits the timestamp as a bare, unquoted, local-time date string:

"result":[["time","a","b","c"],
[2023-11-15 00:14:20,1,2,5],

— making the entire response invalid JSON, on all API versions (verified live on v1, v2 and v3). There is no code-level default adding seconds anywhere; the dashboards always passed it explicitly, which is why this never surfaced. Nothing can depend on the current no-timestamp-option output: it was never parseable — not as JSON, and not as JavaScript either (2023-11-15 00:14:20 is a syntax error as a JS expression), so not even eval-based consumers could ever have read it.

Fix

JSON has no date type, so csvjsonarray now defaults to numeric seconds timestamps; ms is honored when requested. Applied once in the csvjsonarray branch of rrd2json.c, covering both call sites (with and without jsonwrap).

The Google Visualization formats (datatable/datasource with google_json), whose Date(y,m,d,...) cells are deliberately not strict JSON per that API's contract, are untouched.

Validation

Red/green with a deterministic fixture (one chart, three dimensions, fixed 2023 epoch):

  • RED (master): v3+jsonwrap and v1 plain csvjsonarray without seconds/ms are invalid JSON (bare date strings).
  • GREEN (this branch): both parse as valid JSON with numeric epoch timestamps and correct values; ms produces millisecond timestamps; explicit seconds unchanged; the fix csvjsonarray emitting invalid JSON when label-quotes is passed #23115 label-quotes behavior is regression-pinned in the same harness (10/10 checks).

Summary by cubic

Ensure format=csvjsonarray always outputs numeric timestamps so responses are valid JSON. Defaults to seconds when no option is provided; ms still works.

  • Bug Fixes
    • Fixed invalid JSON caused by bare date strings when seconds/ms wasn’t set.
    • Enforced numeric timestamps by default (seconds) for both plain and jsonwrap responses; ms is honored when requested.

Written for commit a1f2724. Summary will update on new commits.

Without seconds or ms in the request options, the csv renderer emits the
timestamp as a bare local-time date string - [2023-11-15 00:14:20,1,2,5] -
making the whole csvjsonarray response invalid JSON, on all API versions.
Nothing can depend on that output: it was never parseable, neither as JSON
nor as JavaScript.

JSON has no date type, so this format now defaults to numeric seconds
timestamps; ms is honored when requested. The google visualization formats
(datatable/datasource with google_json), whose Date(y,m,d,...) cells are
deliberately not strict JSON per that API's contract, are untouched.

Copy link
Copy Markdown

cubic-dev-ai Bot left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All reported issues were addressed across 1 file

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.
Architecture diagram
sequenceDiagram
    participant Client as HTTP Client
    participant API as API Handler
    participant RRDR as RRDR Engine
    participant CSV as csv Formatter
    participant Buffer as JSON Buffer

    Note over Client,Buffer: csvjsonarray Timestamp Defaulting Flow

    Client->>API: GET /api/v1/data?format=csvjsonarray
    API->>RRDR: data_query_execute()
    RRDR->>RRDR: Check DATASOURCE_CSV_JSON_ARRAY case
    
    Note over RRDR: Compute csv_options<br/>Start with LABEL_QUOTES
    RRDR->>RRDR: Check options & RRDR_OPTION_MILLISECONDS
    alt MS option NOT set
        RRDR->>RRDR: Default to RRDR_OPTION_SECONDS<br/>(numeric epoch timestamp)
    else MS option IS set
        RRDR->>RRDR: Keep RRDR_OPTION_MILLISECONDS<br/>(millisecond precision)
    end

    alt JSON_WRAP option set
        RRDR->>Buffer: wrapper_begin() / json_array
        RRDR->>CSV: rrdr2csv() with csv_options
        CSV->>Buffer: Emit numeric timestamps
        RRDR->>Buffer: wrapper_end()
    else No JSON_WRAP
        RRDR->>Buffer: buffer_strcat("[")
        RRDR->>CSV: rrdr2csv() with csv_options
        CSV->>Buffer: Emit numeric timestamps
        RRDR->>Buffer: buffer_strcat("]")
    end

    Buffer-->>API: Valid JSON with numeric timestamps
    API-->>Client: 200 + application/json<br/>"result" array with epoch timestamps
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

ktsaou merged commit 436a1a2 into netdata:master Jul 13, 2026
124 of 140 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL