Skip to content

Conversation

@anivar
Copy link
Contributor

@anivar anivar commented Aug 21, 2025

Overview

This PR implements issue #6838 by adding a counter metric to track the number of actual HTTP network requests made by the http.send builtin.

What this adds

  • New metric: rego_builtin_http_send_network_requests
  • Purpose: Track actual HTTP network calls made during policy evaluation
  • Scope: Counts only network requests, excludes cache hits

Implementation details

The counter increments in both cache implementations:

  • interQueryCache.ExecuteHTTPRequest() - for inter-query cache misses
  • intraQueryCache.ExecuteHTTPRequest() - for intra-query cache misses

This ensures all actual network requests are counted while cache hits are properly excluded.

Usage

When querying with ?metrics=true, the response will include:

{
  "metrics": {
    "counter_rego_builtin_http_send_network_requests": 3,
    "counter_rego_builtin_http_send_interquery_cache_hits": 1
  }
}

Testing

Added comprehensive test coverage in TestHTTPSendMetrics that verifies:

  • Counter increments for successful requests
  • Counter increments for failed requests
  • Counter excludes cache hits
  • Multiple requests increment correctly

Impact

This gives OPA users visibility into HTTP usage patterns in their policies, helping with:

  • Performance monitoring
  • Cost optimization
  • Debugging HTTP-related issues

Fixes #6838

@netlify
Copy link

netlify bot commented Aug 21, 2025

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 34d993d
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/68d153b91eb48e00085fb4ef
😎 Deploy Preview https://deploy-preview-7851--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@anivar anivar force-pushed the feat/http-send-metrics branch 3 times, most recently from 1b4ca05 to e36b64c Compare September 10, 2025 17:39
Copy link
Member

@sspaink sspaink left a comment

Choose a reason for hiding this comment

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

Thank you for implementing this, looks good.

Updating the documentation would be nice but perhaps that can be handled in a separate effort to resolve #6730

@anivar
Copy link
Contributor Author

anivar commented Sep 12, 2025

Thank you for implementing this, looks good.

Updating the documentation would be nice but perhaps that can be handled in a separate effort to resolve #6730

@sspaink Thank you for the review! I agree - will handle the documentation update in a separate PR to keep this one focused.

@charlieegan3
Copy link
Contributor

Thanks for this @anivar, if you fancy taking a go at #6730 that'd be super helpful since you know how this bit works now.

@charlieegan3 charlieegan3 merged commit f615913 into open-policy-agent:main Sep 22, 2025
78 of 83 checks passed
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.

[Metric] Capture number of http send calls made in a query

3 participants