Skip to content

Metric selects ignore valueExpression: gauge and sum charts always aggregate the raw value #3499

Open

Description

@bcanvural

What happened?

A builder select on a metric source accepts valueExpression, and the MCP query tools default it to "Value". Any other expression is dropped without an error. valueExpression: "Value / 86400" returns the same numbers as "Value".

On main (2bfc630), number tile, one series:

Metric type aggFn valueExpression Result Expected
gauge (points 86400, 172800) max Value 172800 172800
gauge max Value / 86400 172800 2
sum (cumulative 0, 60, 120) sum Value 120 120
sum sum Value / 60 120 2

The gauge path replaces the select's valueExpression with LastValue, and the sum path replaces it with Rate / last_value(Sum), so the user's expression never reaches the SQL:

Expected, either of:

  • apply it on the computed value (for example LastValue / 86400), which allows unit conversions without a formula; or
  • reject a non-default valueExpression on metric selects, so it doesn't fail silently.

Related: #2311 (count_distinct ignores valueExpression). Workaround: a formula (A / 86400).

Steps to reproduce

Reproduces on play.hyperdx.io? Didn't try.

An integration test in the style of packages/api/src/clickhouse/__tests__/renderChartConfig.int.test.ts, on main:

  1. Insert two gauge points for repro.disk.seconds (86400 and 172800, one minute apart).
  2. renderChartConfig with displayType: Number, select: [{ aggFn: 'max', metricType: 'gauge', metricName: 'repro.disk.seconds', valueExpression: 'Value / 86400' }], no granularity.
  3. The query returns 172800. The SQL selects max(toFloat64OrDefault(toString(LastValue))).

The same with a cumulative sum (aggFn: 'sum', valueExpression: 'Value / 60') returns the same value as Value.

How are you running HyperDX?

Helm (ClickStack chart 2.1.0) with the hyperdx:2-nightly image (2.42.0 plus the Node bump from #3456), our own ClickHouse 26.2.5.45. Reproduced on main 2bfc630 with the integration test above.

Where does it show up?

The API: MCP dashboard tools (a tile saved with valueExpression: "Value / 86400" showed raw seconds). The UI chart editor goes through the same renderChartConfig; we haven't checked whether it lets you set a metric valueExpression.

Debug info

N/A.

Logs

None; no error is raised.


Written with help from an AI assistant (Claude Code). The behaviour comes from our own deployment and an integration test on main.

Activity

  1. bcanvural commented on Oct 31, 2026

    @bcanvural
    ContributorAuthor

    We'd like to fix this, and there's a choice to make first.

    The UI can't hit it: for metric sources, the series editor hides the value expression and sets it to Value (ChartSeriesEditor.tsx). It comes in through the API:

    • the MCP query and dashboard-tile tools validate metric selects in getMetricSelectIssues and accept any valueExpression (they only default it to Value);
    • the v2 charts endpoint turns a field passed together with metricName into the valueExpression (external-api/v2/charts.ts).

    Either way the renderer then replaces it with its own per-bucket value, so the expression has no effect.

    Two possible fixes:

    1. Apply it. Use the expression on the computed value, e.g. Value / 86400 → LastValue / 86400. That's fine for linear expressions on gauges. For sums and histograms the order matters: an expression applied before the rate gives a different result from one applied after, e.g. log(Value).
    2. Reject it. In getMetricSelectIssues and the v2 charts endpoint, reject a metric select whose valueExpression isn't Value. The error message points to formulas (A / 86400) for math and to the tile's number format (e.g. duration, data units) for unit display.

    We'd go with 2. It's small, it matches what the UI already does, and formulas and number formats already cover what people use the expression for; the silent wrong number is the real problem. Which would you prefer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions