Skip to content

Extract observe_request helper in GQLMetricMiddleware #8776

@hhoikoo

Description

@hhoikoo

Motivation

The GQLMetricMiddleware.resolve() method in src/ai/backend/manager/api/gql_legacy/schema.py contains three near-identical observe_request(...) call sites, each passing 7 keyword arguments. This repetition makes the method hard to read and makes subsequent changes (e.g., BA-4299 async timing fix, BA-4330 OTel tracing) produce unnecessarily large diffs that are difficult to review.

Objective

Extract the repeated metric_observer.observe_request(...) invocations in GQLMetricMiddleware.resolve() into a private helper method, reducing each call site to a single line. This is a pure refactoring with no behavior change.

Details

  • Add a private _observe_request() method to GQLMetricMiddleware that wraps graph_ctx.metric_observer.observe_request(...) with the common parameters (operation_type, field_name, parent_type, operation_name) captured once.
  • Replace all three existing observe_request(...) blocks (success, BackendAIError, BaseException) with calls to the helper.
  • Fix bare raise e to idiomatic raise in the except blocks (minor style cleanup).
  • No functional changes to metrics recording behavior.

Impact

  • Reduces the diff size of follow-up PRs (BA-4299 async timing fix, BA-4330 OTel tracing) by eliminating repeated boilerplate in their diffs.
  • No impact on other services or runtime behavior; the refactoring is internal to the GQL metric middleware.

JIRA Issue: BA-4378

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions