Skip to content

Extract benchmark feature guard as middleware#2094

Merged
cezudas merged 8 commits intomainfrom
cezudas/OPS-3873
Mar 11, 2026
Merged

Extract benchmark feature guard as middleware#2094
cezudas merged 8 commits intomainfrom
cezudas/OPS-3873

Conversation

@cezudas
Copy link
Contributor

@cezudas cezudas commented Mar 10, 2026

Centralizes benchmark access validation for better extensibility.
Part of OPS-3873.

@linear
Copy link

linear bot commented Mar 10, 2026

@cezudas cezudas requested a review from ravikiranvm March 10, 2026 13:00
@cezudas cezudas marked this pull request as ready for review March 10, 2026 13:00
Copilot AI review requested due to automatic review settings March 10, 2026 13:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors benchmark feature-flag access validation into a guard object retrieved via a factory function, aiming to centralize/standardize benchmark access checks for future extensibility (OPS-3873).

Changes:

  • Replace direct assertBenchmarkFeatureEnabled(...) calls with getBenchmarkFeatureGuard().assertBenchmarkFeatureEnabled(...) in the benchmark controller.
  • Convert the benchmark feature guard from a standalone function to a BenchmarkFeatureGuard object with an updated method signature including organizationId.
  • Introduce benchmark-feature-guard-factory.ts to provide the guard instance.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/server/api/src/app/benchmark/benchmark.controller.ts Updates all benchmark endpoints to use the guard factory and pass organizationId into the guard call.
packages/server/api/src/app/benchmark/benchmark-feature-guard.ts Refactors the guard into a typed object and updates the guard API to include organizationId.
packages/server/api/src/app/benchmark/benchmark-feature-guard-factory.ts Adds a factory function that returns the guard implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@cezudas cezudas requested a review from MarceloRGonc March 10, 2026 13:16
cezudas added 2 commits March 10, 2026 20:57
Replace per-handler assertBenchmarkFeatureEnabled calls with a single
app.addHook('preHandler', ...) registered at the plugin scope, following
the established hook pattern used across the codebase.

Made-with: Cursor
logger.info(
'Benchmark access denied: FINOPS_BENCHMARK_ENABLED flag is not enabled',
{ provider, projectId },
{ projectId: request.principal.projectId },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see no good reason to log the provider, as this guard checks only the value of system env variable

Copy link
Contributor

Choose a reason for hiding this comment

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

As we discussed, we don't need this factory.

@cezudas cezudas changed the title Extract benchmark feature guard into factory pattern Extract benchmark feature guard as middleware Mar 11, 2026
@sonarqubecloud
Copy link

@cezudas cezudas requested a review from MarceloRGonc March 11, 2026 09:22
@cezudas cezudas merged commit 4e19460 into main Mar 11, 2026
25 checks passed
@cezudas cezudas deleted the cezudas/OPS-3873 branch March 11, 2026 09:51
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.

3 participants