hyperdx/packages/common-utils
Drew Davis ff422206c5
fix: Fix Services Dashboard Database tab charts (#1435)
Closes HDX-2960

# Summary

This PR makes two fixes to improve the charts on the Database tab of the Services dashboard.

1. Previously, the charts were not rendering a series per query, since ClickHouse returns type `Nullable(String)` for the statement expression (`coalesce(nullif(SpanAttributes['db.query.text'], ''), nullif(SpanAttributes['db.statement'], '')) AS "Statement"`). Our `convertCHDataTypeToJSType()` function failed to map this to a `String` type in JS, which resulted in the column not being inferred as a group column by `inferGroupColumns()` in `formatResponseForTimeChart()`.
2. Once we started rendering a series per query, the page immediately started OOM crashing on any serious volume of data because there are too many distinct groups/queries being returned. To fix this, the query now selects only the queries with the highest values in across any time bucket. The queries do the following:
    1. First, apply filters and group by query and time bucket
    2. Then, `groupArray` the values and time buckets for each query
    3. Select the top 60 queries by max value across all time buckets
    4. `arrayJoin(zip())` to transform the results back into the row-per-group-per-time-bucket format that `formatResponseForTimeChart` expects.

(This is the same approach recently applied to the `Request Error Rate by endpoint` chart on the HTTP tab). 


## Before

<img width="1453" height="791" alt="Screenshot 2025-12-03 at 10 58 31 AM" src="https://github.com/user-attachments/assets/ffa697e4-25bb-4ac6-aed2-703cc3c547bf" />

## After

<img width="1451" height="825" alt="Screenshot 2025-12-03 at 10 57 40 AM" src="https://github.com/user-attachments/assets/42e46d2a-361e-490e-8976-18edeca39e0f" />
2025-12-03 20:04:24 +00:00
..
src fix: Fix Services Dashboard Database tab charts (#1435) 2025-12-03 20:04:24 +00:00
.env.test perf: Improve getKeyValues query performance for JSON keys (#1284) 2025-10-27 16:46:46 +00:00
.eslintignore feat: introduce common-utils package (#554) 2025-01-16 18:15:22 +00:00
.eslintrc.js fix: Update tsconfigs to resolve IDE type errors (#1150) 2025-09-11 08:55:14 -04:00
CHANGELOG.md Release HyperDX (#1325) 2025-11-19 04:24:41 +01:00
jest.config.js perf: Improve getKeyValues query performance for JSON keys (#1284) 2025-10-27 16:46:46 +00:00
jest.int.config.js perf: Improve getKeyValues query performance for JSON keys (#1284) 2025-10-27 16:46:46 +00:00
package.json Bump Typescript Version (app) (#1401) 2025-11-24 21:19:42 +00:00
README.md DX: running api + app + task concurrently with npm script (dev) (#567) 2025-01-23 17:31:25 +00:00
tsconfig.json Improve common-utils intellisense. Currently "Go to Definition" on an… (#1159) 2025-09-11 12:57:41 -06:00
tsup.config.ts feat: introduce common-utils package (#554) 2025-01-16 18:15:22 +00:00

How to test the package with HyperDX app/api

  1. Run yarn build in the root directory of this project (packages/common-utils)
  2. Run yarn dev in the root directory of app/api project (packages/app,api)
  3. You should be able to test utils with the app