Skip to content

analytics-api: register routes via toolkit OperationBuilder - #1506

Merged
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:handlers-registration
Jun 26, 2026
Merged

analytics-api: register routes via toolkit OperationBuilder#1506
cyberantonz merged 2 commits into
constructorfabric:mainfrom
cyberantonz:handlers-registration

Conversation

@cyberantonz

@cyberantonz cyberantonz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Replace the raw axum::Router::route chain (21 endpoints) with the gears-rust toolkit OperationBuilder, so every route records an OpenAPI OperationSpec plus auth/license metadata in one place — the framework idiom used by api-gateway and the gears under gears-rust/gears.

Scope is handler-registration only: the builder is driven standalone against a local OpenApiRegistryImpl, and main.rs keeps serving the resulting axum::Router. AppState, every handler signature, and the tenant_middleware layer are unchanged. Serving /openapi.json and the full bootstrap-host/gear migration are tracked in #1505.

Summary by CodeRabbit

  • Documentation
    • Improved API metadata across service endpoints, including clearer summaries, authentication expectations, response details, and license information.
    • Added more consistent OpenAPI coverage for existing routes, making the API easier to understand and integrate with.

Replace the raw `axum::Router::route` chain (21 endpoints) with the
gears-rust toolkit `OperationBuilder`, so every route records an OpenAPI
OperationSpec plus auth/license metadata in one place — the framework
idiom used by api-gateway and the gears under gears-rust/gears.

Scope is handler-registration only: the builder is driven standalone
against a local OpenApiRegistryImpl, and main.rs keeps serving the
resulting axum::Router. AppState, every handler signature, and the
tenant_middleware layer are unchanged. Serving /openapi.json and the
full bootstrap-host/gear migration are tracked in constructorfabric#1505.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz requested a review from a team as a code owner June 26, 2026 12:54
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@cyberantonz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 6 minutes and 6 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21778fcf-0c92-41ac-9407-ad9e52271d7f

📥 Commits

Reviewing files that changed from the base of the PR and between f381ad7 and 579a6a1.

📒 Files selected for processing (2)
  • src/backend/services/analytics-api/Dockerfile
  • src/backend/services/analytics-api/src/api/mod.rs
📝 Walkthrough

Walkthrough

The analytics API crate now depends on toolkit, and its router registration was migrated to OperationBuilder with an in-process OpenAPI registry. The same endpoints remain registered, with per-route auth, license, and response metadata.

Changes

Analytics API Router Migration

Layer / File(s) Summary
Toolkit dependency and registry setup
src/backend/services/analytics-api/Cargo.toml, src/backend/services/analytics-api/src/api/mod.rs
Adds the toolkit dependency, imports OperationBuilder and OpenApiRegistryImpl, and initializes the router around an in-process OpenAPI registry.
Metric routes
src/backend/services/analytics-api/src/api/mod.rs
Re-registers metric CRUD and query endpoints with OperationBuilder, including operation IDs, summaries, auth, license, and response metadata.
Threshold and lookup routes
src/backend/services/analytics-api/src/api/mod.rs
Re-registers the metric-threshold, person lookup, and column catalog endpoints with the same handlers and new builder-based metadata.
Catalog, admin, and health routes
src/backend/services/analytics-api/src/api/mod.rs
Re-registers the catalog lookup, admin metric-threshold CRUD, and health endpoint through OperationBuilder with route documentation and response definitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

I hopped through routes with twitchy nose,
and tucked new metadata in tidy rows.
OpenAPI carrots, bright and neat,
make every endpoint jump to its beat. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: migrating analytics-api route registration to the toolkit OperationBuilder.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/backend/services/analytics-api/src/api/mod.rs`:
- Around line 302-309: The `/health` route is marked public in the router, but
that only affects docs and does not bypass runtime auth, so requests still hit
`tenant_middleware` and fail without X-Insight-Tenant-Id. Update the middleware
in `tenant_middleware` to explicitly skip tenant validation for the `/health`
path, or remove `/health` from the middleware-wrapped routes so
`handlers::health` can respond unauthenticated as intended.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96289829-fb6a-4e0c-ae17-3736be401ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 636f64d and f381ad7.

⛔ Files ignored due to path filters (1)
  • src/backend/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/backend/services/analytics-api/Cargo.toml
  • src/backend/services/analytics-api/src/api/mod.rs

Comment thread src/backend/services/analytics-api/src/api/mod.rs Outdated
Two fixes for PR constructorfabric#1506:

- Dockerfile: install protobuf-compiler in the builder stage. Depending on
  `toolkit` non-optionally pulls cf-gears-system-sdks (directory/gRPC), whose
  build script needs protoc; the builder image lacked it so the release build
  failed with exit 101. Mirrors the api-gateway Dockerfile.

- api/mod.rs: register /health on a separate router merged AFTER the tenant
  middleware layer, so it stays off the tenant-scoped path. k8s liveness/
  readiness probes hit /health directly on the pod with no X-Insight-Tenant-Id
  header; routing it through tenant_middleware would 400 every probe on a
  multi-tenant install (no tenant_default_id). Mirrors the gears-rust
  api-gateway host, which serves /health on its own top-level router and marks
  it public rather than routing it through per-request auth.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anton Zelenov <antonz@constructor.tech>
@cyberantonz
cyberantonz merged commit 65f206d into constructorfabric:main Jun 26, 2026
21 checks passed
@cyberantonz
cyberantonz deleted the handlers-registration branch July 3, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants