31 Commits

Author SHA1 Message Date
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
Ashutosh Narkar ebc3ab241a Always include HTTP request context in incoming req context
Previously the HTTP request context was included in the
request context at the info access log level. This means
if the access log level was set to error for instance,
the context would not include the http request context and
hence it would not be surfaced via decision logs.

This change always add the http request context to the request
context so that HTTP info like headers will be surfaced via decision
logs irrespective of the access log level.

Fixes: #6951

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-08-23 07:50:56 -07:00
Ashutosh Narkar a8ac7b38bb plugins/logs: Include http request context in decision logs
It would be useful if users had the ability to enhance the
decision log with info from the incoming HTTP request such as
headers. This change allows users to configure headers whose
values if present in the incoming HTTP request would be
surfaced via the decision log. This can be extended in the
future to include more context from the request.

Fixes: #6693

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-05-20 11:08:42 -07:00
Stephan Renatus eb17a716b9 runtime/logging: actually do not panic when rctx is missing
Signed-off-by: Stephan Renatus <stephan@styra.com>
2023-12-22 09:29:26 -08:00
Ashutosh Narkar 8115976890 server: Remove partial query parameter (#6300)
The partial query parameter has been marked as deprecated since
v0.23.0. It's also removed from the docs since that time.

Fixes: #2266

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2023-10-11 10:09:24 +02:00
Torin Sandall a9cbc04765 runtime: Remove deprecation warning for ?watch flag
The watch feature was removed ~2.5 years ago in
faab37c37e so it should be fine to
remove the corresponding log message.

Signed-off-by: Torin Sandall <torin@styra.com>
2023-03-20 14:22:44 -07:00
AdrianArnautu 9e97f98d12 This change allows the HTTP clients to consume and send gzip compressed response and request body. (#5696)
It is available for the following REST API endpoints:
- GET & POST HTTP methods on /v0/data & /v1/data endpoints
- POST HTTP method on /v1/compile endpoint

HTTP clients can optionally:
- send 'Accept-Encoding: gzip' header and expect a gzip compressed body and a Content-Encoding: gzip response header. The server will send the content encoded as gzip only after a threshold defined by server.encoding.gzip.min_length (default value is 1024). If the size is below the threshold, the body is not compressed
- send 'Content-Encoding: gzip' header and a gzip compressed body and expect the server to correctly interpret the request

Fixes #5310

Signed-off-by: aarnautu <aarnautu@adobe.com>
2023-03-09 09:38:39 +01:00
Anders Eknert 9a597feb2e chore: don't use the deprecated ioutil functions (#5319)
Another annoyance removed :P

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-27 14:30:26 +02:00
Humberto Corrêa da Silva f1761ac77e server+runtime+logs: Add the req_id attribute on the decision logs (#5196)
Today it is not possible to correlate the decision log with
other types of logs (server, print, etc.) when the server log
level is >= INFO. The log correlation could be helpful in
troubleshooting.

A solution is to add a common attribute in all logs to make
the log correlation possible, so adding the req_id attribute
on decision logs, when server log level is >= INFO, will make it
possible.

Fixes: #5006

* Add documentation about decision log req_id attribute

The documentation purpose is to explain the relation with
others logs, how it could be used, and when it is included
on decision logs.

Signed-off-by: Humberto Corrêa da Silva <humbertoc_silva@hotmail.com>
2022-10-14 13:12:15 +02:00
Stephan Renatus 1df27c789b runtime/logging: only suppress payloads for handlers that compress responses (#4502)
* runtime/logging: only suppress payloads for handlers that compress responses

To get compressed responses, two things need to be true:

1. The client must accept compressed responses
2. The handler must reply with a compressed response

For general API requests, (1) holds most of the time. (2) is only true
for the metrics endpoint at them moment, since the 3rd party library we
use for serving the prometheus endpoint will do compression.

* runtime/logging: remove dead code

The http.Hijack stuff was related to a watch feature removed in
https://github.com/open-policy-agent/opa/commit/186ef99ffaa3b32e4ae2b4a8c6c59182e06770e4

dropInputParam was only used by its tests.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-30 10:01:34 +02:00
Christian Altamirano Ayala 3dd50d87f0 runtime: improve log output for binary response (#4498)
This change omits the response body when using compression on metrics endpoint and when pprof is enabled.

Signed-off-by: Christian Altamirano <christian.altamirano.ayala@gmail.com>
2022-03-27 12:58:36 +02:00
Torin Sandall 679c3de78b runtime: Enable print calls
This commit enables print() calls inside of the server for INFO and
DEBUG log levels. The print hook is plumbed through to the server via
the manager so that other server implementations (e.g., the Envoy
plugin) can be updated similarly.

The server will compile print() calls for the /v1/query API but not
others since (i) print() calls inside the policies will already have
been compiled and (ii) the queries are limited to fetching `data`
paths and therefore cannot contain print() calls themselves. The
bundle plugin has been updated to compile print() calls as well--this
way the bundle plugin/server will respect incoming bundles and not
attempt to override them.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-10-14 09:31:16 -07:00
Torin Sandall e9d04fc1f5 runtime: Refactor logger usage
This commit does not change any functionality except it provides
callers with a way to provide a logger when instantiating the
runtime. Previously, the runtime had hardcoded dependencies on the
global logrus logger which made it problematic to test logging
behaviour. With this change, the logger can be supplied as a
parameter (which allows the caller to mock out the logger in tests...)

As part of this change, the dependencies on logrus have been moved out
of the runtime package entirely.

This commit includes a breaking change to the
runtime.NewLoggingHandler function: the function now requires a logger
to be supplied.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-10-14 09:31:16 -07:00
Anders Eknert 968d49de3d Injectable logging implementation
Refactor logging to allow providing custom logging implementations to plugin
manager. This should allow us to keep logging as it is when running OPA as a
server, while injecting noop-loggers or custom, provided loggers for SDK client
implementations.

Fixes #3180

Signed-off-by: Anders Eknert <anders@eknert.com>
2021-03-05 14:42:39 +01:00
Torin Sandall 7821831dfa server: Deprecate the watch and partial query parameters
Related: https://github.com/open-policy-agent/opa/issues/2265
Related: https://github.com/open-policy-agent/opa/issues/2266

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-08-10 10:24:50 -04:00
Patrick East b48c534722 Run make fmt with new goimports cmd
Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-09-27 09:55:11 -04:00
Guangming Wang 952437ebe3 cleanup: fix some typos in code comment
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-08-21 09:24:37 -04:00
Patrick East 0ed56fef03 Change to using custom text log formatter
This is less sophisticated than the default logrus one, but it is
much easier to read the server output. Primarily with JSON fields
and multi-line strings. They are decoded and prettified.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2019-05-10 12:04:56 -07:00
Stephan Renatus 161722214d logging: log escaped path
Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-04-12 16:37:08 -07:00
Torin Sandall 38871c87d0 Revendoring logrus to deal with rename
See https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276 for more info.
2017-08-24 09:32:55 -07:00
Matthew Mussomele 4435880658 Implement watch API in the server 2017-07-20 17:07:51 -07:00
Torin Sandall 54d9193662 Improve OPA logging
This changes how OPA logs API requests and responses.

Before:
- OPA would not log at level.Info
- OPA would log request header and body and response header (but not
  body) at level.Debug.

After:
- OPA logs request and response headers at level.Info
- OPA includes request and response body at level.Debug.
2017-05-15 17:20:03 -07:00
Torin Sandall 7d7d2912ae Replace glog with logrus 2017-03-12 12:04:35 -07:00
Torin Sandall 0e39da4664 Improve request logging
Use httputil.DumpRequest as this is much cleaner than previous approach
and handles all requests (instead of just /data). With new approach we
can get rid of getInputParam and related tests.

Also, move slack link around.

Fixes #281
2017-02-28 17:14:41 -08:00
Torin Sandall 68fe788626 Split server types into separate package
This will let them be re-used by other sub-packages such as the
authorizer.
2017-02-22 14:49:21 -08:00
Torin Sandall ebc753cfd8 Rename the request document
Naming is hard. The "request" document is now the "input" document.
2017-01-18 16:37:32 -08:00
Torin Sandall 5ba261a6d8 Fix empty request parameter parsing
Return an error if the request parameter is empty. This indicates an error in
the caller.

Fixes #212
2017-01-17 13:32:56 -08:00
Torin Sandall 333bf4fb1e Update runtime with request changes 2016-12-19 09:59:04 -08:00
Torin Sandall d83f39a0d0 Suppress globals in HTTP access logs
Callers currently provide globals as query parameters. Because the query
params are often JSON values, they need to be escaped. This results in the
access logs being very noisy.

This change removes the "global" query params from the access logs at
V(2) and pretty prints them on a separate line at V(3).
2016-09-22 10:36:53 -07:00
Torin Sandall 12e299fdf2 Add basic access logs
Wrap the router so to capture response latency and implement an interceptor
that captures status codes and number of bytes written. Log the information
once the inner route completes.
2016-05-14 10:44:02 -07:00