Skip to content

fix: metrics matching routes with path params first#2202

Merged
ctron merged 2 commits intoguacsec:mainfrom
ruromero:fix/analyze-recommend-metrics
Jan 14, 2026
Merged

fix: metrics matching routes with path params first#2202
ctron merged 2 commits intoguacsec:mainfrom
ruromero:fix/analyze-recommend-metrics

Conversation

@ruromero
Copy link
Copy Markdown
Contributor

@ruromero ruromero commented Jan 13, 2026

Fix #2201

Summary by Sourcery

Bug Fixes:

  • Fix incorrect route/middleware matching by registering parameterized endpoints after more specific PURL and vulnerability routes.

@ruromero ruromero requested a review from ctron January 13, 2026 16:45
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Reorders Actix-web route registrations for PURL and vulnerability endpoints so that routes with path parameters are registered after more specific routes, ensuring metrics and routing match the intended handlers.

Flow diagram for updated Actix route matching order

flowchart TD
    subgraph PurlEndpoints
        A["Incoming request /purl/recommend"] --> B{"Match route /purl/recommend?"}
        B -- "yes" --> C["Dispatch to handler recommend"]
        B -- "no" --> D{"Match route /purl/{id}?"}
        D -- "yes" --> E["Dispatch to handler get"]
        D -- "no" --> F["Return 404 or continue other routes"]
    end

    subgraph VulnerabilityEndpoints
        G["Incoming request /vuln/analyze"] --> H{"Match route /vuln/analyze?"}
        H -- "yes" --> I["Dispatch to handler analyze"]
        H -- "no" --> J{"Match route /vuln/analyze_v3?"}
        J -- "yes" --> K["Dispatch to handler analyze_v3"]
        J -- "no" --> L{"Match route /vuln/{id}?"}
        L -- "yes" --> M["Dispatch to handler get"]
        L -- "no" --> N["Return 404 or continue other routes"]
    end
Loading

File-Level Changes

Change Details Files
Adjusted PURL endpoint registration order to prioritize recommendation routes before generic get routes.
  • Reordered service registration so that the recommend endpoint is registered before the all and get endpoints in the PURL configure function.
  • Ensured that the get endpoint is now registered last among PURL routes to avoid it shadowing more specific routes.
modules/fundamental/src/purl/endpoints/mod.rs
Adjusted vulnerability endpoint registration order to register the generic get route after analysis routes.
  • Reordered service registration so that analyze and analyze_v3 endpoints are registered before the get endpoint in the vulnerability configure function.
  • Ensured vulnerability get is now last among vulnerability routes to prevent it from intercepting traffic meant for analysis endpoints and to improve metrics attribution.
modules/fundamental/src/vulnerability/endpoints/mod.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#2201 Ensure that the /recommend and /analyze endpoints are matched to their specific route patterns (rather than the generic parameterized routes like /v2/purl/{key}) so that OpenTelemetry metrics use the correct http_route labels.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Because the behavior now depends on the registration order of the routes, consider adding an inline comment near the .service(...) chain in both modules to explain why get must come after the more specific endpoints to prevent regressions from future refactoring.
  • To make the route ordering requirement harder to accidentally break, you might extract the .service(...) chains into small helper functions (e.g., register_specific_routes and register_catch_all_routes) so that the distinction between specific and parameterized routes is more explicit.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Because the behavior now depends on the registration order of the routes, consider adding an inline comment near the `.service(...)` chain in both modules to explain why `get` must come after the more specific endpoints to prevent regressions from future refactoring.
- To make the route ordering requirement harder to accidentally break, you might extract the `.service(...)` chains into small helper functions (e.g., `register_specific_routes` and `register_catch_all_routes`) so that the distinction between specific and parameterized routes is more explicit.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
@ruromero ruromero force-pushed the fix/analyze-recommend-metrics branch from aa55af2 to 4a2cacd Compare January 13, 2026 16:52
@PhilipCattanach
Copy link
Copy Markdown

If approved I guess this is something that needs to be included in the 2.2.1 release?

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.65%. Comparing base (82ce317) to head (ef67eab).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2202   +/-   ##
=======================================
  Coverage   68.64%   68.65%           
=======================================
  Files         379      379           
  Lines       21449    21449           
  Branches    21449    21449           
=======================================
+ Hits        14723    14725    +2     
+ Misses       5858     5851    -7     
- Partials      868      873    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ctron
Copy link
Copy Markdown
Contributor

ctron commented Jan 14, 2026

@ruromero I think the AI is right, and we should add a source code comment about this

@ctron ctron added the backport release/0.4.z Backport (0.4.z) label Jan 14, 2026
@ruromero
Copy link
Copy Markdown
Contributor Author

@ruromero I think the AI is right, and we should add a source code comment about this

done

Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
@ruromero ruromero force-pushed the fix/analyze-recommend-metrics branch from a464c29 to ef67eab Compare January 14, 2026 07:54
@ctron ctron added this pull request to the merge queue Jan 14, 2026
Merged via the queue into guacsec:main with commit 693278b Jan 14, 2026
6 checks passed
@trustify-ci-bot
Copy link
Copy Markdown

Backport failed for release/0.4.z, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release/0.4.z
git worktree add -d .worktree/backport-2202-to-release/0.4.z origin/release/0.4.z
cd .worktree/backport-2202-to-release/0.4.z
git switch --create backport-2202-to-release/0.4.z
git cherry-pick -x 809b6d465b91aad2d171a985885cc3807efdcf92 693278b24af4ea601219abb5ddac7049540e1f11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.4.z Backport (0.4.z)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics not matching the right path for /recommend and /analyze

3 participants