发布

  • [OPIK-5023] [BE] refactor(filter): introduce ENUM_LEGACY field type for source legacy fallback (#5846)

    frostbyte_neo 发布于 2026-03-27 15:51:19 +00:00

    • [OPIK-5023] [BE] refactor(filter): introduce ENUM_LEGACY field type for source legacy fallback

    Centralise the legacy-fallback operator handling inside ANALYTICS_DB_OPERATOR_MAP
    by introducing FieldType.ENUM_LEGACY. The EQUAL and NOT_EQUAL templates for the
    new type encode the OR/AND fallback SQL directly in the map, removing the need for
    the separate LEGACY_FALLBACK_OPERATOR_MAP and buildWithLegacyFallback method.

    TraceField.SOURCE and SpanField.SOURCE are re-typed to ENUM_LEGACY so the behaviour
    is driven by the field type, consistent with every other operator/type pair.

    • fix(test): add ENUM_LEGACY to exhaustive FieldType switches in filter resource tests

    • refactor(tests): delegate filter helper methods to shared FilterTestUtils

    Replace duplicate getValidValue/getKey/getInvalidValue implementations
    in FindTraceThreadsResourceTest and GetTracesByProjectResourceTest with
    delegation to the shared FilterTestUtils utility class.

    • fix(filter): fix MissingFormatArgumentException and dedup legacyFallbackDbValue

    Fix MissingFormatArgumentException in toAnalyticsDbFilter when an
    ENUM_LEGACY field has no legacy fallback for a given value (e.g.
    source = "ui"): fall back to the plain ENUM template for that operator
    instead of calling template.formatted with too few arguments.

    Replace identical legacyFallbackDbValue anonymous overrides on
    TraceField.SOURCE and SpanField.SOURCE with a constructor-injected
    Function, eliminating the duplicate enum constant body.

    • test: add FilterTestUtils shared helper for filter test methods

    • refactor(filter): use @RequiredArgsConstructor and inline FilterTestUtils calls

    • fix: add missing FilterTestUtils import in FindSpansResourceTest

    • [OPIK-5023] [BE] refactor: apply ENUM_LEGACY function-based pattern to TraceThreadField

    • [OPIK-5023] [BE] refactor(filter): move legacy fallback logic to FieldType

    Per review feedback:

    • ENUM_LEGACY.buildFilter overrides the FieldType default, encoding the
      OR/AND legacy-clause logic directly on the type. Source::legacyFallbackDbValue
      is called once, in one place.
    • Field enums (SpanField, TraceField, TraceThreadField) no longer carry a
      Function<String,Optional> lambda; SOURCE just uses ENUM_LEGACY.
    • FilterQueryBuilder.toAnalyticsDbFilter delegates to the type's buildFilter,
      removing the if(ENUM_LEGACY) discriminator. Adding a new type with similar
      behaviour only requires overriding buildFilter in FieldType.
    • legacyFallbackDbValue removed from Field interface; it lives on FieldType.
    • FilterTestUtils uses @UtilityClass instead of manual private constructor.
    下载附件