Commit Graph

5818 Commits

Author SHA1 Message Date
Philip Conrad 1565779099 Prepare v1.7.1 release (#7814)
Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
v1.7.1
2025-07-31 16:36:07 -04:00
Philip Conrad 9874953f5e cmd/parse: Move accidental pkg var to local var. (#7813)
This commit moves an accidental package-level definition of the `opa
parse` CLI subcommand to a local variable inside the `initParse`
function, similar to how we do command initialization for all other OPA
CLI subcommands.

Before this change, it was possible to see panics from the package
variable `cobra.Command` in `parse.go` having some of its flags redefined.
This fix makes it possible for `make generate-cli-docs` to run without
error again.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
(cherry picked from commit 47e2b74dda)
2025-07-31 15:39:59 -04:00
Philip Conrad 21a527db6e bugfix: Add back default cmd.RootCommand definition. (#7811)
This commit fixes an issue when upgrading codebases to OPA v1.7.0.

In PR #7797, we introduced the ability to provide "branding"
information in OPA commands and help messages, which would
allow easier customized OPA distributions in the future.

However, this changeset removed the public symbol `cmd.RootCommand`,
and required refactoring to use `cmd.Command`, which breaks automated
upgrades, such as those done by Dependabot.

This PR adds back the missing symbol, with the original/default "OPA"
branding provided. This should allow existing codebases to upgrade
without requiring any code changes.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-31 14:39:29 -04:00
Johan Fylling 45b6eb6639 Prepare v1.7.0 release (#7809)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
v1.7.0
2025-07-31 15:09:28 +02:00
Charlie Egan d0132ee99b store: Improve conflicting root error message (#7808)
Fixes #7806

```
{
  "errors": [
    {
      "message": "detected overlapping roots in bundle manifest with: [b2.tar.gz b1.tar.gz]"
    }
  ]
}
{
  "errors": [
    {
      "message": "bundles [b1.tar.gz, b2.tar.gz] have overlapping roots and cannot be activated simultaneously because bundle(s) [b1.tar.gz] specify empty root paths ('') which overlap with any other bundle root"
    }
  ]
}
```

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-31 12:16:12 +01:00
Charlie Egan 4647660eab docs: Revise docs index page wording (#7805)
- added link to playground
- removed some examples I felt were redundant
- made the constants example relevant to the example domain
- minor wording changes and fixes

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-31 09:43:59 +01:00
Charlie Egan ef9b6c8289 build: Show a warning when .manifest is ignored (#7807)
-b must be set for the user defined manifest to be used.

Related to https://github.com/open-policy-agent/opa/issues/7806

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-30 20:59:47 +01:00
dependabot[bot] f5f00a9108 build(deps): bump the dependencies group across 1 directory with 10 updates (#7803)
Bumps the dependencies group with 10 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [github.com/containerd/containerd/v2](https://github.com/containerd/containerd) | `2.1.1` | `2.1.3` |
| [github.com/dgraph-io/badger/v4](https://github.com/dgraph-io/badger) | `4.7.0` | `4.8.0` |
| [github.com/sergi/go-diff](https://github.com/sergi/go-diff) | `1.3.1` | `1.4.0` |
| [github.com/spf13/pflag](https://github.com/spf13/pflag) | `1.0.6` | `1.0.7` |
| [github.com/tchap/go-patricia/v2](https://github.com/tchap/go-patricia) | `2.3.2` | `2.3.3` |
| [github.com/vektah/gqlparser/v2](https://github.com/vektah/gqlparser) | `2.5.28` | `2.5.30` |
| [golang.org/x/net](https://github.com/golang/net) | `0.41.0` | `0.42.0` |
| [golang.org/x/time](https://github.com/golang/time) | `0.11.0` | `0.12.0` |
| [google.golang.org/grpc](https://github.com/grpc/grpc-go) | `1.73.0` | `1.74.2` |
| [sigs.k8s.io/yaml](https://github.com/kubernetes-sigs/yaml) | `1.4.0` | `1.6.0` |



Updates `github.com/containerd/containerd/v2` from 2.1.1 to 2.1.3
- [Release notes](https://github.com/containerd/containerd/releases)
- [Changelog](https://github.com/containerd/containerd/blob/main/RELEASES.md)
- [Commits](https://github.com/containerd/containerd/compare/v2.1.1...v2.1.3)

Updates `github.com/dgraph-io/badger/v4` from 4.7.0 to 4.8.0
- [Release notes](https://github.com/dgraph-io/badger/releases)
- [Changelog](https://github.com/hypermodeinc/badger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/dgraph-io/badger/compare/v4.7.0...v4.8.0)

Updates `github.com/sergi/go-diff` from 1.3.1 to 1.4.0
- [Commits](https://github.com/sergi/go-diff/compare/v1.3.1...v1.4.0)

Updates `github.com/spf13/pflag` from 1.0.6 to 1.0.7
- [Release notes](https://github.com/spf13/pflag/releases)
- [Commits](https://github.com/spf13/pflag/compare/v1.0.6...v1.0.7)

Updates `github.com/tchap/go-patricia/v2` from 2.3.2 to 2.3.3
- [Commits](https://github.com/tchap/go-patricia/compare/v2.3.2...v2.3.3)

Updates `github.com/vektah/gqlparser/v2` from 2.5.28 to 2.5.30
- [Release notes](https://github.com/vektah/gqlparser/releases)
- [Commits](https://github.com/vektah/gqlparser/compare/v2.5.28...v2.5.30)

Updates `golang.org/x/net` from 0.41.0 to 0.42.0
- [Commits](https://github.com/golang/net/compare/v0.41.0...v0.42.0)

Updates `golang.org/x/time` from 0.11.0 to 0.12.0
- [Commits](https://github.com/golang/time/compare/v0.11.0...v0.12.0)

Updates `google.golang.org/grpc` from 1.73.0 to 1.74.2
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.73.0...v1.74.2)

Updates `sigs.k8s.io/yaml` from 1.4.0 to 1.6.0
- [Release notes](https://github.com/kubernetes-sigs/yaml/releases)
- [Changelog](https://github.com/kubernetes-sigs/yaml/blob/master/RELEASE.md)
- [Commits](https://github.com/kubernetes-sigs/yaml/compare/v1.4.0...v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/containerd/containerd/v2
  dependency-version: 2.1.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: dependencies
- dependency-name: github.com/dgraph-io/badger/v4
  dependency-version: 4.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: github.com/sergi/go-diff
  dependency-version: 1.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: github.com/spf13/pflag
  dependency-version: 1.0.7
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: dependencies
- dependency-name: github.com/tchap/go-patricia/v2
  dependency-version: 2.3.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: dependencies
- dependency-name: github.com/vektah/gqlparser/v2
  dependency-version: 2.5.30
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: dependencies
- dependency-name: golang.org/x/net
  dependency-version: 0.42.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: golang.org/x/time
  dependency-version: 0.12.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: google.golang.org/grpc
  dependency-version: 1.74.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: sigs.k8s.io/yaml
  dependency-version: 1.6.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-29 15:46:18 +02:00
Stephan Renatus 9a73de98f7 sdk: options store takes precedence over ext store
Rationale is that if the user has passed a store into the SDK, it
probably has something in it already, like data and policies.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-25 20:56:17 +02:00
Anders Eknert 4c13c6cc9f perf: AST compiler optimizations (#7740)
Funnily, this started out as an attempt to look into issues reported
with compiling large policy sets... before I realized that it isn't
likely *this* compiler that has perf issues, but the one that "compiles"
bundles as part of activation. So while these fixes likely does little
to address that, there are still some rather nice improvements here, where
the big ones as ususal are mostly just wins from avoiding work where it's
possible.

For benchmarking I've used Regal's embedded bundle, which isn't great to
use over time, as it's a moving target. But since it's a pretty extensive
bundle and one that covers most features of OPA, it's at least good for
1:1 comparisons when testing perf improvements.

```
// 66555594 ns/op	50239492 B/op	 1083664 allocs/op - main
// 62569440 ns/op	38723015 B/op	  944277 allocs/op - compiler-optimizations pr
```
The B/op / alloc_space improvement is particularly nice here. What's noteworthy
is how relatively little impact that has on performance in this case. That may
be surprising but aligns pretty well with my previous experience of Go code where
a lot of time is spend in recursive walks — that simply takes time, no matter how
much you optimize. Oh well, less memory allocated for this is more memory to spend
elsewhere.

(I'm adding the benchmark used below to Regal in a parallel PR)

Signed-off-by: Anders Eknert <anders@styra.com>
2025-07-25 14:21:53 +02:00
Charlie Egan c95a0942c8 docs: Fix a number of minor docs typos (#7799)
Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-25 08:56:45 +01:00
Timothy Lee d0c0ae9730 add top-level token permissions for workflows (#7795)
Signed-off-by: Timothy Lee <tklee@google.com>
2025-07-24 11:49:09 +02:00
kevinstyra 94a953150a cmd: allow branding
This change allows users that build their own executable or "spin" of
OPA to give it a name, and have it reference itself properly in help
texts.

It's a vanity thing, but I think some people would appreciate it, hat
tip to the international association of pedants.

Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: kevinstyra <83973046+kevinstyra@users.noreply.github.com>
2025-07-24 11:33:23 +02:00
Stephan Renatus cba9eeedb8 loader: pass bundle name in AsBundle()
It seems correct to give the bundle a name, after all.
It's just metadata.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-24 10:55:24 +02:00
Philip Conrad 8190f997af plugins/logs: Add experimental intermediate results field.
This commit adds an experimental "intermediate results" field to
decision logs, and provides some basic plumbing in the server package
for attaching the intermediate results of an eval to the request
context.

Co-authored-by: Teemu Koponen <koponen@styra.com>
Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-24 07:01:55 +02:00
Stephan Renatus 62f48aa185 decisionlogs: add custom fields grab bag
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 23:01:37 +02:00
Stephan Renatus a2c769fe36 ast: add DefaultModuleLoader
This provides the means to inject modules _for all invocations of the
ast package in an executable_. It's handy if you want to include your
own set of base modules, with helper functions.

Since the module loader can be provided via other means, we need to
check both possibilities:

1. If there hasn't been a module loader set up before, just use
   the default module loader.

2. If there had been one set up before, run that first, then run
   the default one, and merge the results. This can be iterated,
   of course, if need be -- and should reach a fix point given
   that the individual loaders do.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 22:47:09 +02:00
Philip Conrad 5c312800e8 server/authorizer: Allow adding paths to validator. (#7792)
This commit provides an extension mechanism for the server authorizer,
allowing plugins and other server extensions to inform the authorizer
about the methods and paths where it should expect and parse request
bodies.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-23 20:36:03 +00:00
Stephan Renatus 52381423d3 test+eval: add helper to smuggle compiler through context
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 22:12:13 +02:00
Philip Conrad 614f3cdac0 server+logging: Add BatchDecisionID field to Decision Logs.
This commit adds a new field to Decision Log entries, allowing batches
of decisions to be correlated together later.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-23 20:23:25 +02:00
Stephan Renatus e4feab26f8 server+plugins: allow plugins to inject http handler middlewares
Before we had introduced `http.ServeMux` as "the router", we had been
using github.com/gorilla/mux. Using the latter, it was possible to
inject middlewares using the mux's `.Use()` method. This mechanism
allowed global middlewares to be injected from `runtime.Params`, for
example.

With `http.ServeMux`, that's no longer possible. However, it was never
an intentionally supported feature in the first place.

So this commit introduces HTTP handler middlewares as extension points.
It's modelled after `(*plugins.Manager).ExtraRoute()`.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 19:03:51 +02:00
Stephan Renatus f78319008a internal/config: keep unknown env replacements
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 18:55:43 +02:00
Stephan Renatus e3f6be6c22 cmd: use regoError to carry compiler errors into CLI machinery
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 17:17:50 +02:00
kevinstyra 36bae2aac6 cmd: use command.RunE to return errors and perform orderly shutdown of OPA
`os.Exit` immediately exits the program and doesn't run defer functions.
This can be problematic as any command.OnFinalize routines and any logic
after the command.Execute won't be run.

Also suppress all RunE cobra error and usage messages. These would be
printed twice otherwise.

Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: Kevin St. Pierre <kevin@styra.com>
2025-07-23 17:17:50 +02:00
Teemu Koponen 2d014a89bb plugins/discovery: Replace environment variables after evaluation.
This allows simple setups -- those feeding the OPA discovery plugin with
a static JSON file -- to still do env variable replacements.

This should be possible already, by using a policy to construct the
disco config, but it becomes easier now.

Co-authored-by: Teemu Koponen <koponen@styra.com>
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-23 17:09:41 +02:00
ToluGIT e48e7f51c5 docs: Add examples for crypto.sha256 and base64.encode built-in functions (#7762)
Adds examples for two more built in functions on their dedicated pages.

Signed-off-by: ToluGIT <93225033+ToluGIT@users.noreply.github.com>
Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: Charlie Egan <git@charlieegan3.com>
Co-authored-by: Stephan Renatus <stephan@styra.com>
2025-07-23 14:34:37 +00:00
dependabot[bot] 82a9803bed build(deps): bump on-headers and compression in /docs (#7785)
Bumps [on-headers](https://github.com/jshttp/on-headers) and [compression](https://github.com/expressjs/compression). These dependencies needed to be updated together.

Updates `on-headers` from 1.0.2 to 1.1.0
- [Release notes](https://github.com/jshttp/on-headers/releases)
- [Changelog](https://github.com/jshttp/on-headers/blob/master/HISTORY.md)
- [Commits](https://github.com/jshttp/on-headers/compare/v1.0.2...v1.1.0)

Updates `compression` from 1.8.0 to 1.8.1
- [Release notes](https://github.com/expressjs/compression/releases)
- [Changelog](https://github.com/expressjs/compression/blob/master/HISTORY.md)
- [Commits](https://github.com/expressjs/compression/compare/1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: on-headers
  dependency-version: 1.1.0
  dependency-type: indirect
- dependency-name: compression
  dependency-version: 1.8.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-21 11:45:55 +01:00
Charlie Egan 781a540228 docs: Update warning note in GraphQL API docs (#7737)
Fixes https://github.com/open-policy-agent/opa/issues/6586

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-18 14:09:55 +00:00
Philip Conrad 5a872a4166 bundle: Add support for bundle store and activation plugins. (#7771)
This commit adds support for changing out how bundle storage and
activation work. To allow swapping out bundle activation, two new
`bundle` package functions are provided:

 - `RegisterActivator`: Registers a bundle.Activator with a string ID.
 - `RegisterDefaultBundleActivator`: Sets the default bundle.Activator to
   use by ID.

Behind the scenes, a few new `bundle` package variables are used to
track what bundle activators are available, and which is the preferred
default.

This system allows registering many activators, and allows choosing the
bundle activator to use at activation time. The activator to use is
decided in the following order:

 - `(bundle.ActivateOpts).Plugin` is used when non-nil.
 - `bundle.bundleExtActivator` is used when an ID was set with
   `RegisterDefaultBundleActivator`.
 - The default/original bundle activator is used if no other selection
   was made.

To support swapping out bundle storage (useful when testing new bundle
designs), a new `bundle` package function is provided:

 - `RegisterStoreFunc`: Sets the function to use for creating bundle
   storage.

These two features together allow swapping out most of the bundle
activation flow, without requiring deep modification of the `bundle`
package. Lazy bundle loading mode is also enabled across many CLI
commands and other bundle loading points now when a non-default bundle
activator is set.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
Co-authored-by: Ashutosh Narkar <anarkar4387@gmail.com>
2025-07-17 17:23:12 +00:00
Stephan Renatus 5ef98c7493 store+runtime: extension points for custom stores (#7779)
* storage: allow overriding NonEmpty

Custom store implementations can now bring their own NonEmpty() methods,
which may be more efficient than what the generic method does.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>

* runtime: allow passing in custom store builder


Signed-off-by: Stephan Renatus <stephan@styra.com>

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-17 17:04:45 +00:00
Stephan Renatus 5eeed90a5c runtime: allow enabling NDBCache by default (#7780)
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-17 16:40:16 +00:00
Charlie Egan 9250b55f75 website: Add wildcard CORS for data/versions.json (#7784)
Turns out that CORS is either any host, or a specific host. We need to
match any opa versioned deployment host, so we need a *.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-17 15:32:05 +01:00
Charlie Egan 9c3bcbe4fd website: Render versions under /data/versions.json (#7783)
This will facilitate other sites checking the current version of the OPA
website.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-17 11:10:25 +00:00
Stephan Renatus 47f764e5be ast: add feature registration from the outside
If I add this to `main.go` (imagine another executable including OPA),

```diff
diff --git a/main.go b/main.go
index 9d5aea6c7c..5126479107 100644
--- a/main.go
+++ b/main.go
@@ -8,9 +8,11 @@
 	"os"
 
 	"github.com/open-policy-agent/opa/cmd"
+	"github.com/open-policy-agent/opa/v1/ast"
 )
 
 func main() {
+	ast.RegisterFeatures("foo", "bar", "baz")
 	if err := cmd.RootCommand.Execute(); err != nil {
 		os.Exit(1)
 	}
```

and I subsequently run `opa capabilities --current`, we'll find (other
stuff omitted):

```json
{
  "features": [
    "bar",
    "baz",
    "foo",
    "keywords_in_refs",
    "rego_v1"
  ]
}
```

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-17 12:45:36 +02:00
Charlie Egan 5430c72d5c website: Show link to the edge release of the docs (#7776)
I have also corrected some issues with a non / base path for the site
here which are mostly unrelated.

Changes to the release/build tasks will come in a different PR so we
only show the latest release and not the edge on
openpolicyagent.org/docs.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-17 09:20:13 +00:00
Stephan Renatus e092ff268d plugin/discovery: make Factories() merge the factories
Otherwise, setting something from the runtime parameter
ExtraDiscoveryOpts would be impossible: on runtime startup, the runtime
is injecting its own registered plugins via that method.

With this change, for example factories passed via discovery.Factories()
in ExtraDiscoveryOpts will be able to add to (or replace) the previously
registered plugins.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-16 19:51:54 +02:00
Stephan Renatus f6a7fca083 rego: pass along TracingOpts into EvalContext
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-16 19:51:40 +02:00
Stephan Renatus 84778e203d server: add hooks wiring + new hooks for inter-query caches
When an plugin http handler or some other mechanism wants to do rego
evaluations, too, it's beneficial to share the caches with the server.

This change introduces two new hook types to allow retrieving those
caches during server startup.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-15 20:31:16 +02:00
Stephan Renatus 3b5545ba1d server: ensure that wrapped middlewares all support http.Flusher
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-15 18:09:16 +02:00
Charlie Egan d2d21cce12 website: Set mobile and desktop tab sizes
Mobile uses 2, desktop uses 4. This is intended to show more of examples
on mobile.

Made two other small edits to improve the mobile presentation.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-15 13:43:10 +02:00
Charlie Egan 04eddc999b website: Ensure no hscroll on built-in tables (#7773)
This makes a number of changes to how the built in functions are
displayed to ensure that there is no horizontal scrolling when viewing
builtin in tables with longer function names.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-15 10:17:33 +01:00
Charlie Egan d34a2029be docs: Fix /docs/envoy-authorization/ 404 (#7770)
Fixes https://github.com/open-policy-agent/opa/issues/7755

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-07-15 08:30:57 +00:00
Stephan Renatus ba2e6a021b plugins: allow registering handlerfuncs with name+path
This way, the extra handler functions are still covered by prometheus
metrics and opentelemetry spans.

The previous method of directly registering routes with the router
bypassed the server's handler wrapping.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-14 18:17:30 +02:00
Philip Conrad 70e5ad126b loader+internal: Add bundle lazy loading mode across the runtime. (#7768)
This commit comprehensively plumbs in the bundle lazy loading mode
option in the compile, runtime, rego, and bundle packages. It also
includes the bare minimum plumbing to allow the path watcher utilities
to also toggle the option on.

In nearly all places where a default is expected, the lazy loading mode
is set to false (disabled) to avoid behavior changes.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
2025-07-11 20:18:18 +00:00
Stephan Renatus eaf10e0956 runtime: add ExtraDiscoveryOpts to runtime.Params
This allows injecting discovery options, such as hooks, or extra
factories, into the runtime. It's useful because when wrapping OPA, you
don't want to re-write the runtime package, you want to use it as-is.
With this, we can still configure a few internals.


Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-11 16:02:29 +02:00
Stephan Renatus e3594781df rego: expose QueryTracers, tracing.Options and Cancel from QueryContext
QueryTracers is required for parameterized subtests to work in a
different rego plugin.

tracing.Options are needed to have http.send and friends be wired up
with OTel when using a different rego plugin.

Cancellation is useful when the evaluation scenario is different from
the usual, like in bulk requests

Co-authored-by: Philip Conrad <philip@chariot-chaser.net>
Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-11 15:51:44 +02:00
Anders Eknert e61e638fe8 Benchmark fixes (#7765)
A number of benchmarks did not have a `for range b.N` (or equivalent) loop in
them, leading to nothing being measured. This PR fixes that, along with some
cleanups in benchmarks found along the way.

Also remove `b.StopTimer` where not absolutely necessary, as that is
[notoriously buggy](https://github.com/golang/go/issues/27217), and had some
benchmarks hang for a very long time.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-07-11 13:17:30 +02:00
Stephan Renatus 6aa579de3f cmd: only plumb through target if it was set
allowing the default to be changed by a rego target plugin.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2025-07-11 12:26:26 +02:00
Stephan Renatus 8f58f0459c v1/tester: support uint64 and float64 metrics in runBenchmark
This is quite hard to test, but if you're using a rego plugin that emits
metrics that are not int64 (such as counters), this would give a panic
at run time.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-10 21:35:14 +02:00
Stephan Renatus 334666355a opa exec: stop plugins before exit
This allows certain plugins to do their cleanup routines -- like sending
decision logs to some other location when using a custom decision log
setup.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2025-07-10 20:32:54 +02:00