发布

  • [OPIK-7101] Make project stats opt-in on /projects/retrieve (#7231)

    frostbyte_neo 发布于 2026-06-24 14:18:50 +00:00

    • [OPIK-7101] Make project stats opt-in on /projects/retrieve

    POST /v1/private/projects/retrieve (ProjectService.retrieveByName) is used
    by callers only to resolve a project name -> id, but on every call it
    recomputed full project analytics (feedback scores, traces/spans aggregation,
    duration, cost, counts) over ClickHouse. No first-party caller reads these
    fields: the TS/Python SDKs return project.id only, the frontend
    useProjectByName hook reads only .id, and internal ingestion uses the
    stats-free retrieveByNamesOrCreate. The stats were added in OPIK-287 for the
    projects table/dashboards (list + getById), and /retrieve was swept into that
    change. At high call rates (SDK name resolution) this saturated prod ClickHouse.

    Add an includeStats flag (default false) to ProjectRetrieve. The endpoint
    now skips the ClickHouse aggregations unless stats are explicitly requested,
    preserving the response contract (fields stay nullable, omitted = null) for any
    external consumer that opts in.

    • ProjectRetrieve: add includeStats + shouldIncludeStats() (default false)
    • ProjectService.retrieveByName(name, includeStats); extract enrichWithStats()
    • ProjectsResource passes retrieve.shouldIncludeStats()
    • Tests: happy path now requests includeStats(true); add default-off test
      asserting stats fields are null

    Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

    • [OPIK-7101] Fix retrieve test + mark includeStats @Nullable
    • Drop the lastUpdatedTraceAt null assertion in the default-off test:
      last_updated_trace_at is a projects table column (written on ingestion via
      recordLastUpdatedTrace), not part of the ClickHouse stats aggregation, so it
      is legitimately populated and cheap. The test still asserts the heavy stat
      fields (feedbackScores/duration/cost/usage/traceCount/...) are null.
    • Add @Nullable to ProjectRetrieve.includeStats so the optional DTO contract is
      explicit (per review feedback); shouldIncludeStats() still coalesces null to
      false.

    Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

    • refactor(projects): override includeStats accessor and assert full project in retrieve test

    Address review feedback on PR #7231:

    • ProjectRetrieve: override the canonical includeStats() accessor to coalesce
      null to false, removing the duplicate shouldIncludeStats() helper.
    • ProjectsResource: call retrieve.includeStats() at the single call site.
    • ProjectsResourceTest: assert the full expected Project (stats nulled, core
      fields populated) via recursive comparison instead of field-by-field nulls.

    Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com


    Co-authored-by: Claude Opus 4.8 (1M context) noreply@anthropic.com

    下载附件