Commit Graph

47 Commits

Author SHA1 Message Date
Sebastian Spaink 8e2f1807ac config: validate configuration with Rego and warn on unknown options (#8891)
Part of #2745

Like most of his ideas, @anderseknert's suggestion to use Rego to
replace the `validateAndInjectDefaults` functions throughout the
codebase is another winner.

This PR starts the migration by replacing the top-level
`validateAndInjectDefaults` in `v1/config/config.go` with an embedded
policy, `validate.rego`. The policy injects the top-level defaults
(`default_decision`, `default_authorization_decision`, `labels`) and
reports unrecognized configuration options, so a typo such as
`decision_log` instead of `decision_logs` is logged as a warning at
startup rather than silently ignored.

It's evaluated in `ParseConfig` using the low-level `ast`/`topdown`
packages rather than the top-level `rego` package. This keeps `config`
off the heavy `rego → bundle → …` dependency web (which would otherwise
create import cycles as more packages' tests reach `config`), and we
don't need any of the `rego` package's conveniences here — it's one
module compiled once and a single query. The Rego unit tests run in CI
via `build/run-rego-tests.sh` (and locally with `make rego-test`).

This sets the foundation for the other plugin
`validateAndInjectDefaults` functions to migrate to Rego as well; where
the logic isn't too complicated it should be a fairly easy replacement.
At the moment all known keys live in `validate.rego` under `_specs` to
support the "warn on unrecognized options" check, but the
plugin-specific entries can move closer to each plugin as it migrates.
It would also be nice for `_specs` to be auto-generated somehow in the
future.

Supporting extension of config validation with custom policies is
something I'd like to follow up with, so keeping #2745 open for now.

I also think these policies could be reusable with
[java-opa-sdk](https://github.com/open-policy-agent/java-opa-sdk) 👀

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
2026-07-15 11:16:03 -05:00
Charlie Egan 7bdfe03927 runtime: Remove goautomaxprocs and automemlimit (#8869)
The memory pressure in low resource containers this PR aimed to fix was
actually caused by #8817, which was fixed in #8829. The
automaxprocs/automemlimit dependencies are no longer needed as was
intended in #8696.

This reverts commit 88c01e659c and updates
docs to match the current behaviour.

---------

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2026-07-08 14:13:57 +00:00
Charlie Egan 88c01e659c runtime: Restore goautomaxprocs, add automemlimit (#8784)
This PR reverts the change in #8696 where automaxprocs was removed. This
meant the go language default of 2 procs vs 1 was used. In some memory
constrained deployments of OPA, this caused OOM issues where the server
used more memory than before with 2 processes running. This PR restores
the automaxprocs dependency and this behaviour.

This PR also follows other data-heavy CNCF projects in pairing this with
automemlimit to automate the setting of GOMEMLIMIT based on the cgroup
data too.

This makes no change for users manually setting these, but hopefully
will provide some sensible defaults that work well for most cases, and
better than the Go defaults in low resource deployments.

<details>
<summary>Other projects</summary>

*
https://github.com/prometheus/prometheus/blob/2ad3a871701531d1485f678acb7523cd0aa31789/go.mod#L11
*
https://github.com/istio/istio/blob/4985ae369245dcc91bc107a0c47ea41ded0c1a12/go.mod#L8
*
https://github.com/grafana/alloy/blob/e11d0f03e2b2e727161fb2169cade54698e17bd8/go.mod#L19
* https://github.com/thanos-io/thanos/blob/main/go.mod#L9
* https://github.com/kubernetes/kube-state-metrics/blob/main/go.mod#L6
* https://github.com/authzed/spicedb/blob/main/go.mod#L22

</details>

---------

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2026-06-15 13:54:43 +00:00
Anders Eknert 12cad2a326 Remove automaxprocs dependency (#8696)
This is handled natively by Go since 1.25, so this dependency should no
longer be needed. See references below for more information. Only
notable difference seems to be that Go sets a minimum value of 2 while
the automaxprocs lib has a minimum value of 1. Go seems to account for
much more though, so I don't think that difference alone warrants the
inclusion of this dependency. Users who really want GOMAXPROCS=1 can
always set that themselves.

References:
- https://github.com/golang/go/issues/73193
- https://github.com/uber-go/automaxprocs/issues/98

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
2026-05-26 12:37:43 +02:00
Stephan Renatus cb54e9c14f runtime: rule labels metadata processing follow-ups (#8613)
 We now parse rego metadata annotations by default.

Rule annotations now support a `labels` field. During policy eval,
labels from all successfully evaluated rules are collected and included
in each decision log entry as a top-level `rule_labels` array. Each
element preserves the label map from one evaluated rule. Exact
duplicates are omitted.

```rego
# METADATA
# labels:
#   severity: low
#   team: platform
allow if input.role == "admin"
```

The resulting decision log entry will contain:

```json
{"rule_labels": [{"severity": "low", "team": "platform"}]}
```

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-05-08 15:00:26 +00:00
Stephan Renatus a7b87cd127 cli: enable file_logger plugin
The plugin registration step was missing before, so the code, while in
the tree, was not active and the plugin couldn't be used.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-05-05 11:35:43 +02:00
Michael Munch 12b7290697 distributedtracing: export Prometheus metrics via OTLP (#8450)
* distributedtracing: export Prometheus metrics via OTLP

Add support for pushing OPA's existing Prometheus metrics to an
OpenTelemetry collector via OTLP, eliminating the need for a dedicated
scraper sidecar. Uses the OTel Prometheus bridge to read from OPA's
prometheus.Registry and export through an OTLP metric exporter (gRPC
or HTTP), reusing the same address and TLS configuration as traces.

New config fields: distributed_tracing.metrics (bool, default false)
and distributed_tracing.metrics_export_interval_ms (int, default 60000).

Fixes #7591

Signed-off-by: Michael Munch <mm.munk@gmail.com>

* metricsexport: decouple metrics export into top-level config section

Extract metrics export from distributed_tracing into its own
metrics_export config section with independent type (otlp/grpc,
otlp/http), address, and TLS settings. This allows exporting
Prometheus metrics via OTLP without enabling tracing, and to a
different endpoint than traces.

- Extract shared TLS helpers into internal/tlsutil
- Add MetricsExport field to top-level Config
- Create internal/metricsexport package with Init, config parsing
- Remove metrics fields from distributedtracing
- Update runtime to call metricsexport.Init separately
- Move e2e tests to v1/test/e2e/metricsexport
- Add Metrics Export section to configuration docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Michael Munch <mm.munk@gmail.com>

* ci: retrigger checks

Signed-off-by: Michael Munch <mm.munk@gmail.com>

* go.mod: upgrade dependencies downgraded during rebase

Modules like containerd, go-sqlbuilder, OpenTelemetry, and golang.org/x/*
were at older versions than main after a rebase. Upgrade them to match or
exceed main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Michael Munch <mm.munk@gmail.com>

* Update internal/distributedtracing/distributedtracing_test.go

Signed-off-by: Michael Munch <mm.munk@gmail.com>

---------

Signed-off-by: Michael Munch <mm.munk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 14:09:51 +00:00
Stephan Renatus aa38bb5b57 logging: make WithContext() optional
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-03-30 10:20:13 +02:00
Stephan Renatus d0041c64d9 runtime+server: logger plugins (#8434)
This PR brings support for pluggable logging implementations via the logger plugin interface, which is based on Go's standard log/slog.Handler interface. This allows any slog.Handler implementation to be used as a logger plugin. Loggers can be referenced via the server.logger_plugin configuration option; and can also be used for decision logs. OPA includes a built-in file logger plugin (file_logger) that writes structured JSON logs with rotation support using lumberjack. Users can also implement and register custom logger plugins when building OPA.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-03-26 10:39:06 -05:00
Stephan Renatus e0d66617c3 plugins/rest: various changes re: TLS, *http.Client caching (#8376)
* plugins/rest: cache *http.Client and auth plugin

This will require further changes to cert TLS and token auth methods to
stay compatible with the previous behaviour.

* plugins/rest: configurable re-read interval for TLS cert+key

Defaulting to re-reading all the time, more or less like we did before.

(I write "more or less" because we now do it in `GetClientCertificate()`.)

* plugins/rest: document change (code comments, CHANGELOG)
* plugins/rest: set minimum TLS version where `&tls.Config{}` is used
* plugins/rest: ensure min TLS version and ciphersuites are used

...as  configured with the server.


Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-03-17 08:30:57 +01:00
Anders Eknert 037101cd7c Linter configuration cleanup (#8397)
And enable more staticcheck linters. I saw staticcheck failures
mentioned in another PR, so thought I'd check it out.

- `WriteString(fmt.Sprintf)` -> `fmt.Fprintf`
- Rewrite calls to deprecated `*Rule.Path()`
- Don't use `==` to compare `time.Time`
- Use inline ignores over config exclusions of paths
- Remove 'varcheck' ignores as no longer used
- Remove v0 topdown/graphql.go (!)

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
2026-03-06 22:07:35 +00:00
Charlie Egan 446f836c39 test: Extract runtime Info to new package (#8362)
This will allow Go SDK users to access this previously internal package.

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2026-02-24 08:46:35 +01:00
alex60217101990 83627c62a0 runtime: add custom storage backend registration API (#8303)
Implements RegisterStorageBackend() to allow Go module users to inject custom
storage implementations during early-stage package init (hardcoded at build time).

Previously this was only possible through params.StoreBuilder which required
direct SDK usage.

Key changes:
- Add RegisterStorageBackend() and StorageBackendBuilder type in v1/runtime
- Modify storage initialization to check registered backends

Fixes #8277

Signed-off-by: alex60217101990 <alex6021710@gmail.com>
2026-02-10 13:37:33 +01:00
Charlie Egan 6601188c64 runtime: Correct naming & docs for version checking (#8191)
* runtime: Correct naming of version checking code

Rename telemetry functionality to version checking to accurately reflect
current behavior following
https://github.com/open-policy-agent/opa/pull/7756.

The system only checks GitHub releases for version updates without sending
any data about the OPA instance and so the privacy docs have been updated too.

Signed-off-by: Charlie Egan <charlie_egan@apple.com>

* Make WithTelemetryGatherers a no-op

Deprecate WithTelemetryGatherers since telemetry gathering has been removed.
The function now returns a no-op to maintain API compatibility without
breaking existing code that might uses it.

Signed-off-by: Charlie Egan <charlie_egan@apple.com>

---------

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2026-01-08 10:25:38 +00:00
Anders Eknert e03ac2f200 Bump golangci-lint, more gocritic linters (#8052)
- Bump golangci-lint -> 2.6.2
- Fix all `deprecatedComment` "notices should be in a dedicated paragraph, separated from the rest" reports
- Enable `appendCombine` and fix all "appendCombine: can combine chain of X appends into one" notices
- Enable `preferFprint` and fix the few reported issues
- Fix various issues reported only once or twice, like `zeroByteRepeat`

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
2025-11-17 11:08:39 +01:00
Q bafd4db332 fix runtime tests: close watcher & set default GracefulShutdownPeriod (#7991)
* runtime server: close watcher
* add default GracefulShutdownPeriod to avoid immediate context deadline exceed

Signed-off-by: Max Qian <zq2@illinois.edu>
2025-10-27 13:07:55 -05:00
Anders Eknert d3f34a3387 Modernize analyzer fixes (#7965)
Have done this some time in the past, but there was a few
new issues this would highlight now that we're on Go 1.24.

Mostly:
- Use `b.Loop()` in benchmarks
- Use `strings.SplitSeq` where possible
- Remove `omitempty` tag for types that can't be empty

Signed-off-by: Anders Eknert <anders@eknert.com>
2025-10-10 17:51:02 +02:00
Sebastian Spaink d102e453e5 fix: print eval errors to stderr (#7880)
updated the presentation package print functions to accept a parameter to print to stderr.

Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
2025-09-11 16:13:15 -05:00
Ville Vesilehto f77322b3fb build: bump Go version requirement to 1.24 (#7839)
Go 1.23 is no longer supported as per Go release policy.

Changes:

- Use Go v1.24.6 as the project SDK requirement
- Apply lint fixes for Go 1.24
- Fix "non-constant format string in call" issues as seen in CI.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
2025-08-24 09:02:09 +02:00
Charlie Egan 11e52c4df6 v1/plugins: Address race in config access (#7825)
* v1/plugins: Address race in config access

I ran into this race condition on another PR:

https://github.com/open-policy-agent/opa/actions/runs/16655603110/job/47139789057

I have tried to make all manager.Config access thread-safe by adding new
getters for used values. GetConfig is regrettably based on a JSON
roundtrip deep copy of the config. This us used in tests (fine) but also
in the discovery plugin:

https://github.com/open-policy-agent/opa/blob/2d014a89bbbc307d7204817220146ffae992e838/v1/plugins/discovery/discovery.go#L122

getPluginSet is very tightly coupled to the manager.Config and because
of it's dependencies on status and the other plugins packages, it's hard
to break out.

So, for now, I think this is an improvement and worth getting a second
opinion on before more refactoring.

Signed-off-by: Charlie Egan <charlie@styra.com>

* v1/config: Use add Clone to config

This makes the use of the manager's config more thread-safe and
consistent without more API changes.

Signed-off-by: Charlie Egan <charlie@styra.com>

* topdown: Add clone() funcs for config structs

NamedValueCacheConfig.Clone, InterQueryBuiltinValueCacheConfig.Clone and
InterQueryBuiltinCacheConfig.Clone have been added.

All Clone methods return a deep copy of the struct. This is tested for
missed new fields using PopulateAllFields, a generic function that
stuffs structs with values for all fields.

Signed-off-by: Charlie Egan <charlie@styra.com>

* plugins: Clone new config

Signed-off-by: Charlie Egan <charlie@styra.com>

---------

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-08-13 12:24:16 +00:00
Charlie Egan 16158ba8c9 runtime: Update server init check (#7818)
I saw a panic here: https://github.com/open-policy-agent/opa/actions/runs/16652495113/job/47128828522
and think it's related to the server init check returning before the
addrs are set.

I update all cases where a similar check on logs is done.

I am unsure how the log could come before the server is initialized, but
sometimes funny things happen in race detector ordering and this looks
more correct to me.

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-08-07 16:18:41 +00: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
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 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
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
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
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 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
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
Johan Fylling 9a423eceab report: Fetching latest OPA release version from GH (#7756)
instead of telemetry server.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2025-07-08 13:19:40 +02:00
Anders Eknert dfb4d0bdcc Replace gorilla/mux dependency with http.ServeMux (#7676)
I was curious to see how much work this would entail, and it turned out to
be... some :) Particularly porting some of the features exposed as settings
by gorilla mux, like removing trailing slashes, or escaping `/` in matched
paths.

This change is breaking by necessity, as some public functions previously
accepted arguments straight from the mux library. I don't really see any
way around that if we want to get rid of the dependency. I don't think
that too many external projects use code from the server directly though,
so I'm thinking the impact should be minimal? Happy to hear what others
think.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-06-10 01:47:34 +02:00
Anders Eknert 8ba08ac80c Apply modernize linter fixes (#7599)
Following up on #7566, and now applying the more exciting
modernizations. fmt.Appendf was new to me! But especially
the contains checks are so much better IMHO. I have reviewed
all changes myself and did a few manual changes where it
became obvious that things could be improved a little further.

(the modernize analyzer still has some issues running against
OPA, and I have manually worked around those for the time being)

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-20 23:12:13 +02:00
Anders Eknert e43ef0a979 Use any in place of interface{} (#7566)
Earlier this evening I tried to run the Go
[modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
analyzer on OPA. That didn't go as planned:

- https://github.com/golang/go/issues/73661
- https://github.com/golang/go/issues/73663

While we wait for that to be fixed, I figured an old-fashioned
search-and-replace across the repo may work for at least the
`interface{}` to `any` conversion. That should help make it easier
to see the other fixes as applied by the modernize tool once it has
had those issues resolved.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-12 13:57:48 +02:00
Anders Eknert bd5ceb5142 Enable unused-receiver linter (revive) (#7448)
Signed-off-by: Anders Eknert <anders@styra.com>
2025-03-14 11:41:25 +01:00
Johan Fylling a389d9a800 test: Fixing broken tests (#7387)
`TestControlPlaneSpans` could case a race condition, where the discovery plugin is manually triggered before/during server initialization, resulting in the manager config being changed while actively consumed.

Replacing `Runtime.serverInitialized` boolean field with more granular enum type state, to allow test-runtime to hold off on triggering plugins until runtime is actively waiting for plugin ready state.

Currently, manager config writes are guarded by an internal mutex, while config reads are largely unguarded. A broader fix here might be to deprecate the public `plugins.Manager.Context` field, replacing it with a getter that guards the config with an r/w-lock.

Also fixing:

* Possible race condition in telemetry reporter by using r/w-mutex guarded compiler getter instead of direct field access
* AWS signing tests where signing randomly failed because of too small mock random value used in test

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2025-02-25 22:15:54 +01:00
Anders Eknert afb30d3f9d Add gocritic linter, fix a bunch of stuff (#7377)
Brace yourselves! For there are many touched files here. No changes
in semantics however.

Spent a long time trying out the various optional rules gocritic
provides, and settled for a few of them. There are more I really
like, but that would take many hours to address across the codebase.

Perhaps others find gocritic too pedantic? If so, we can merge the
fixes without enabling the rule.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-02-24 16:28:41 +01:00
Magnus Jungsbluth 3591a08d03 Enable tracing for discovery plugin (#7299)
* Enable distributed tracing for control plane traffic

Signed-off-by: Magnus Jungsbluth <magnus.jungsbluth@zalando.de>
2025-02-05 20:05:53 +01:00
Anders Eknert 55e87e79ae Add perfsprint linter (#7334)
And update code to conform to the rule.

- Replace unnecessary fmt.Sprintf with string concatenation
- Replace fmt.Sprint with more efficient strconv.Itoa
- Replace static fmt.Errorf calls with more efficient errors.New

Thanks @srenatus for pushing me down this rabbit hole!

Signed-off-by: Anders Eknert <anders@styra.com>
2025-01-31 20:24:05 +01:00
Ashutosh Narkar 9a7d920494 Update docs and server binding addr per OPA v1.0 specs (#7140)
This changes updates the docs and all the policy examples in them to
be OPA v1.0-compliant. It also binds the OPA server to `localhost`
interface by default per OPA v1.0 specs.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Co-authored-by: Charlie Egan <charlie@styra.com>
2024-12-19 12:25:47 +01:00
Stephan Renatus 9ea4b1075d runtime: send version report less often when long-running
When an OPA instance runs for a long time, it seems odd to send version reports
every hour. I think it's unlikely that someone watches the logs at that point.

So this change makes OPA report every 6 hours (plus a random time between 0 and
60 minutes), after it has reported hourly (+spray) for 6 times.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2024-12-18 09:27:56 +01:00
Johan Fylling a179a24c48 v1 API
All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.

Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.

Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:27:34 +01:00
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00