CoollZzz opened a new pull request, #123:
URL: https://github.com/apache/iotdb-extras/pull/123
## Description
This PR improves Grafana table-model queries by supporting custom legend
formats and returning Grafana's native `No data` state when a time-series
result contains no plottable values.
### Support Grafana `legendFormat`
- Adds `legendFormat` to the frontend query model, table-model query editor,
and backend query parameters.
- Supports static legends and templates such as `{{instance}}` and
`{{nodeType}} - {{nodeId}}`.
- Resolves legend templates after converting long-form query results to wide
time-series frames, when the per-series labels are available.
- Maps common Prometheus label names to their IoTDB column aliases, such as
`nodeType` to `node_type` and `name` to `label_name`.
- Leaves the legend unchanged when `legendFormat` is empty or set to
Grafana's `__auto` sentinel.
- Applies the resolved value through `DisplayNameFromDS` without overwriting
other field configuration.
Resolving legends in the backend keeps imported Prometheus dashboards
compatible and avoids requiring panel-specific field overrides.
### Show `No data` for empty time-series results
Some IoTDB `HOP` and `rate` queries return timestamped rows whose numeric
values are all `NULL`, instead of returning zero rows. Grafana previously
received a non-empty frame for these results and rendered empty axes rather
than its `No data` state.
This PR treats a time-series result as having no plottable data when:
- the result contains zero rows; or
- every numeric value column contains only `NULL` values.
In these cases, the backend returns no frame, allowing Grafana to display
`No data`.
The behavior is limited to the `Time series` format. The `Table` format
still returns a frame so that column headers and `NULL` rows remain available
to table panels. This logic is implemented in the plugin instead of adding
query-specific SQL filters, so it also applies to future sparse aggregation
queries.
### Testability and coverage
The table query execution path is separated from response construction
through `executeTableQuery`. Tests can replace the query runner with an
in-memory result, allowing response semantics to be tested without a live IoTDB
RPC service.
Added coverage includes:
- static and templated legend formats;
- multiple placeholders and whitespace handling;
- Prometheus-to-IoTDB label aliases;
- missing and empty labels;
- the empty and `__auto` no-op formats;
- preservation of existing field configuration;
- legend application after long-to-wide conversion;
- zero-row time-series and table results;
- all-`NULL` numeric time-series results;
- partially populated numeric results; and
- `legendFormat` query deserialization and backward compatibility.
### Testing
- `go test -count=1 ./...`
- `go vet ./...`
- `npm run typecheck`
- `npm run test:ci`
- `npm run build`
- `git diff upstream/master --check`
<hr>
This PR has:
- [x] been self-reviewed.
- [x] added comments explaining the intent of non-obvious behavior.
- [x] added unit tests covering the new code paths.
- [ ] been tested in a test IoTDB cluster.
<hr>
##### Key changed/added classes (or packages if there are too many classes)
in this PR
- `connectors/grafana-plugin/pkg/plugin/table_query.go`
- `connectors/grafana-plugin/pkg/plugin/table_query_test.go`
- `connectors/grafana-plugin/pkg/plugin/plugin.go`
- `connectors/grafana-plugin/src/QueryEditor.tsx`
- `connectors/grafana-plugin/src/types.ts`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]