Skip to content

[opa] Correlate OPA server log with Polaris requestId; add observability for non-200 errors from OPA server#5011

Merged
dimas-b merged 8 commits into
apache:mainfrom
gracechen09:opa-correlation
Jul 15, 2026
Merged

[opa] Correlate OPA server log with Polaris requestId; add observability for non-200 errors from OPA server#5011
dimas-b merged 8 commits into
apache:mainfrom
gracechen09:opa-correlation

Conversation

@gracechen09

Copy link
Copy Markdown
Contributor

This PR contains two changes:

  1. Today, requestId is randomly generated for OPA context, this PR changes it to the actual requestId so that OPA operators can correlate Polaris request with OPA server's decision logs

  2. When OPA returns non-200 errors, Polaris server only logs the exception but no information about the status code. For example, one can't find out whether it's an authorization failure or server unreachable failure from server logs. Therefore, this PR logs the status code for non-200 errors to make it easy to construct alerts based on different error code

Checklist

  • 🛡️ Don't disclose security issues! (contact security@apache.org)
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 8, 2026
@gracechen09
gracechen09 marked this pull request as ready for review July 8, 2026 19:05

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for more contributions, @gracechen09 !


private ImmutableContext buildContext() {
return ImmutableContext.builder().requestId(UUID.randomUUID().toString()).build();
String requestId = MDC.get("requestId");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think using MDC for carry data between Polaris components is a good idea.

Would it be possible to inject RequestIdSupplier instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah using RequestIdSupplier makes sense!

OpaAuthorizationConfig opaConfig,
Clock clock,
AsyncExec asyncExec,
Instance<RequestIdSupplier> requestIdSupplier) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why bother with Instance? ServiceProducers make this bean available in the request scope unconditionally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, just realized that OpaPolarisAuthorizer is built per request! I simplified the code to inject RequestIdSupplier directly in the factory

dimas-b
dimas-b previously approved these changes Jul 14, 2026
@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 14, 2026
@dimas-b

dimas-b commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@gracechen09 : Please resolve merge conflicts.

@dimas-b
dimas-b merged commit fe3a85d into apache:main Jul 15, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Jul 15, 2026
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