发布

  • [OPIK-4417] [BE][FE] Fix incorrect usage Sum aggregation in stats (#5266)

    frostbyte_neo 发布于 2026-03-02 17:26:17 +00:00

    • [OPIK-4417] [BE][FE] Fix incorrect usage Sum aggregation in spans/traces/threads stats

    The frontend was computing Sum as count * avg, which is wrong because
    avgMap(usage) only averages over rows that have the key in their map,
    while count includes all rows. This caused inflated sums especially
    when filtering by Trace ID (mix of LLM spans with tokens and tool spans
    without).

    Fix: add sumMap(usage) to the stats queries in SpanDAO, TraceDAO, and
    ThreadDAO, wire it through StatsMapper, and use the real sum on the
    frontend instead of the count * avg approximation.

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

    • [OPIK-4417] [BE] Fix usage_sum stats leaking into usage map

    getStatsUsage filtered with startsWith("usage") which also matched
    "usage_sum.*" keys, causing them to appear in the Project usage map
    as "sum.total_tokens" etc. Use startsWith("usage.") to be precise.

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

    • [OPIK-4417] [BE] Fix SpanDAO ILLEGAL_AGGREGATION and add usage_sum test coverage

    Qualify usage column with table alias s. to avoid ClickHouse interpreting
    sumMap(usage) as nesting inside avgMap(usage) AS usage alias. Also add
    calculateUsageSum to StatsUtils for proper test coverage of usage_sum stats.

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

    • [OPIK-4417] [BE] Fix thread stats test to expect usage_sum entries

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

    • [OPIK-4417] [BE] Address PR review: inline calculateUsageSum, use builder

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

    • [OPIK-4417] [BE] Use builder for AvgValueStat in thread test

    Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com


    Co-authored-by: Claude Opus 4.6 noreply@anthropic.com

    下载附件