Skip to content

docs: Document metrics for http.send, regex, and glob builtins - #8103

Merged
charlieegan3 merged 1 commit into
open-policy-agent:mainfrom
anivar:docs/builtin-metrics
Feb 25, 2026
Merged

charlieegan3 merged 1 commit into
open-policy-agent:mainfrom
anivar:docs/builtin-metrics

Conversation

@anivar

@anivar anivar commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

This PR addresses issue #6730 and the feedback from the closed PR #7929.

The original PR attempted to create a comprehensive metrics registry documenting all OPA metrics. After review, that approach was too broad - it created maintenance overhead and put documentation in places where users wouldn't naturally look for it.

This PR takes a simpler approach: document metrics right where users need them - on the builtin reference pages themselves. When someone is reading about http.send, they can scroll down and see exactly what metrics it exposes. Same for regex and glob.

Added Performance Metrics sections to three builtin pages:

  • http.send - Timer for execution time, counter for cache hits, counter for actual network requests (helps distinguish cached vs real requests)
  • regex - Cache hit counter that tracks when compiled patterns are reused
  • glob.match - Cache hit counter for compiled glob patterns

These are the most commonly used builtins that expose their own metrics. Also clarified the REST API docs to explain what additional metrics you get when you enable instrument=true.

Following reviewer feedback, this PR intentionally does NOT create a comprehensive registry, add a generator tool, or update monitoring.md/policy-performance.md. Those can be addressed separately if needed.

Fixes #6730

@anivar
anivar force-pushed the docs/builtin-metrics branch from 5eb1145 to 67ce08d Compare December 2, 2025 13:34
@netlify

netlify Bot commented Dec 2, 2025

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 5eb1145
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/692eeaae5408480008fc84d5
😎 Deploy Preview https://deploy-preview-8103--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.

@netlify

netlify Bot commented Dec 2, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 75a403b
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6930b2c3e0131000080ae9a0
😎 Deploy Preview https://deploy-preview-8103--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.

Comment thread docs/docs/rest-api.md Resolved
@stale

stale Bot commented Jan 2, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity in the last 30 days.

@stale stale Bot added the inactive label Jan 2, 2026
@anivar
anivar requested a review from charlieegan3 January 6, 2026 08:39
@stale stale Bot removed the inactive label Jan 6, 2026
@netlify

netlify Bot commented Jan 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 1735ad5
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6960eda8512dfd00083cc2fd
😎 Deploy Preview https://deploy-preview-8103--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 requested a review from charlieegan3 January 9, 2026 12:05
Comment thread docs/docs/rest-api.md Resolved
@netlify

netlify Bot commented Jan 20, 2026

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit e0d2a51
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/696fc153d0a27c00083cce56
😎 Deploy Preview https://deploy-preview-8103--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.

@charlieegan3

charlieegan3 commented Jan 28, 2026 •

Copy link
Copy Markdown
Member

Hey @anivar, have you had another chanced to look at this yet? Keen to get this in now if we can.

#8103 (comment)

@netlify

netlify Bot commented Jan 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit a0399f7
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/6984da495ea49c0008fb6821
😎 Deploy Preview https://deploy-preview-8103--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 docs/builtin-metrics branch 3 times, most recently from dcbc7a6 to a47d1de Compare January 28, 2026 19:27

@charlieegan3 charlieegan3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please can you leave all sections as they are, but review the http one as I think something is wrong there. Please provide the policy and commands you are using to test these docs in the thread.

I am finding this PR's updates very hard to review due to the rebasing, please do not rebase this PR until we are ready to merge so I can review changes as you make them.

| `output := glob.match("{cat,bat,[fr]at}", [], "rat")` | `true` | A glob with pattern-alternatives matchers. |
| `output := glob.match("{cat,bat,[fr]at}", [], "at")` | `false` | A glob with pattern-alternatives matchers. |

## Performance Metrics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This section has been checked, please leave it as is.

| ------ | ----------- |
| `timer_rego_builtin_http_send_ns` | Time spent in `http.send` calls during evaluation |
| `counter_rego_builtin_http_send_interquery_cache_hits` | Number of `http.send` requests served from the inter-query cache. Only present when [inter-query caching](/docs/configuration/#caching) is enabled |
| `counter_rego_builtin_http_send_network_requests` | Number of actual network requests made, excluding cached responses |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please share the command you are using to test this, I am not seeing counter_rego_builtin_http_send_interquery_cache_hits and counter_rego_builtin_http_send_network_requests with the ?metrics=true and config:

caching:
  inter_query_builtin_cache:
    max_size_bytes: 10485760

@anivar anivar Jan 30, 2026 •

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.

Here's the policy and commands I used to verify the http.send metrics:

  policy.rego:
  package httptest

  import rego.v1

  result := http.send({
      "method": "GET",
      "url": "https://httpbin.org/get",
      "cache": true,
      "force_cache": true,
      "force_cache_duration_seconds": 30,
  })

  config.yaml:
  caching:
    inter_query_builtin_cache:
      max_size_bytes: 10485760

Commands:
opa run --server --config-file config.yaml policy.rego

1st request — populates cache:
curl -s 'http://localhost:8181/v1/data/httptest/result?metrics=true'
# metrics: timer_rego_builtin_http_send_ns, counter_rego_builtin_http_send_network_requests: 1

2nd request — hits cache:
curl -s 'http://localhost:8181/v1/data/httptest/result?metrics=true'
# metrics: timer_rego_builtin_http_send_ns, counter_rego_builtin_http_send_interquery_cache_hits: 1

The cache hit counter requires "cache": true or "force_cache": true in the http.send request object . server-level caching config alone isn't sufficient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok great, thanks for clarifying this!


<PlaygroundExample dir={require.context('../_examples/regex/globs_match/role_patterns')} />

## Performance Metrics

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This section has been checked, please leave it as is.

Comment thread docs/docs/rest-api.md Outdated
When instrumentation is enabled there are several additional performance metrics
for the compilation stages. They follow the format of `timer_compile_stage_*_ns`
and `timer_query_compile_stage_*_ns` for the query and module compilation stages.
When query instrumentation is enabled (`instrument=true`), the following additional metrics are included:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not change this section has it has been checked.

@charlieegan3 charlieegan3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there was some confusion, my comments "This section has been checked, please leave it as is." meant just "please do not update this section in the next commit".

So in:

6ac30d4

You have brought back some older changes that I didn't think we wanted to keep.

I think now if we jump back to the version you had in e71a3bf and make the suggestd change about the http.send configuration in this review, then rebase against main, we should be good here.

| Metric | Description |
| ------ | ----------- |
| `timer_rego_builtin_http_send_ns` | Total time spent in `http.send` calls during query evaluation |
| `counter_rego_builtin_http_send_interquery_cache_hits` | Number of inter-query cache hits for `http.send` requests. Only appears when [inter-query caching is enabled](/docs/configuration/#caching) in OPA's configuration and the request includes `cache` or `force_cache` set to `true` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
| `counter_rego_builtin_http_send_interquery_cache_hits` | Number of inter-query cache hits for `http.send` requests. Only appears when [inter-query caching is enabled](/docs/configuration/#caching) in OPA's configuration and the request includes `cache` or `force_cache` set to `true` |
| `counter_rego_builtin_http_send_interquery_cache_hits` | Number of inter-query cache hits for `http.send` requests. Only appears when [inter-query caching is enabled](/docs/configuration/#caching) in OPA's configuration and the `http.send` request configuration has `cache` or `force_cache` set to `true` |

| ------ | ----------- |
| `timer_rego_builtin_http_send_ns` | Time spent in `http.send` calls during evaluation |
| `counter_rego_builtin_http_send_interquery_cache_hits` | Number of `http.send` requests served from the inter-query cache. Only present when [inter-query caching](/docs/configuration/#caching) is enabled |
| `counter_rego_builtin_http_send_network_requests` | Number of actual network requests made, excluding cached responses |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok great, thanks for clarifying this!

@anivar
anivar force-pushed the docs/builtin-metrics branch 2 times, most recently from 3d1e5aa to a0399f7 Compare February 5, 2026 17:58
@anivar
anivar requested a review from charlieegan3 February 24, 2026 02:46
@charlieegan3

Copy link
Copy Markdown
Member

Hi, the DCO check is failing, are you able to sign off your commits.

As I have explained in my previous PR reviews, #8103 (review) and #8103 (review), it is very hard to review this with the sweeping edits and the rebasing.

Would it be possible to avoid rebasing this while we work towards an acceptable version? Please ensure that all new commits have DCO as required, and please do not rebase from main until we are ready to merge to aid reviewing.

@anivar
anivar force-pushed the docs/builtin-metrics branch from a0399f7 to f9e962e Compare February 24, 2026 14:59
@anivar

anivar commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi, the DCO check is failing, are you able to sign off your commits.

As I have explained in my previous PR reviews, #8103 (review) and #8103 (review), it is very hard to review this with the sweeping edits and the rebasing.

Would it be possible to avoid rebasing this while we work towards an acceptable version? Please ensure that all new commits have DCO as required, and please do not rebase from main until we are ready to merge to aid reviewing.

I exactly followed your instruction last time and not rebased

@netlify

netlify Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit fc4b2a5
🔍 Latest deploy log https://app.netlify.com/projects/openpolicyagent/deploys/699ef12fe0386e0008d51f8f
😎 Deploy Preview https://deploy-preview-8103--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.

@charlieegan3 charlieegan3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok thanks, I have reviewed now and this looks good to me.

@charlieegan3
charlieegan3 enabled auto-merge (squash) February 25, 2026 12:55
Fixes open-policy-agent#6730

Signed-off-by: Anivar A Aravind <ping@anivar.net>
@charlieegan3
charlieegan3 merged commit 3c5b7c6 into open-policy-agent:main Feb 25, 2026
24 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.

[Documentation] No documentation for metric definitions

2 participants