-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the req_id attribute on the decision logs #5006
Comments
Hi @humbertoc-silva ! And thanks for opening this. Maybe I'm missing something obvious here :) What does this add compared to the decision ID generated for a decision and added to the decision log entry? The request ID would still be generated by the OPA server, right? It might also be worth to point out that the |
Hi @anderseknert, The decision log ID has its own value, generally, a client application will get it when receiving a response from OPA and the responsible team will use it to filter the logs. But it can not help when we need to correlate the other logs generated by the server (request/response/print), e.g. I don't know which print precisely occurs in a certain decision. today it is not possible to correlate these other logs with the decision log. I agree that this correlation just makes sense if the log level is INFO or higher because if the log level is lower there is nothing to correlate. So, maybe the log level needs to be considered when adding the req_id to the decision logs. |
Thanks @humbertoc-silva! I guess the next question then would be — when decision logging is enabled, is there any real value in keeping the "request log" enabled too? AFAICS, there's not much added in terms of data not already present in the decision log itself. Firing off a request with OPA running as request log {
"client_addr": "127.0.0.1:53452",
"level": "info",
"msg": "Sent response.",
"req_id": 1,
"req_method": "GET",
"req_path": "/v1/data/policy/response",
"resp_bytes": 54,
"resp_duration": 0.6725,
"resp_status": 200,
"time": "2022-08-12T23:22:27+02:00"
} decision log {
"decision_id": "163be9bb-b8e7-4324-a99b-9263e498a116",
"labels": {
"id": "d71df7ba-b0ba-40ca-a3de-4e127158c7cd",
"version": "0.44.0-dev"
},
"level": "info",
"metrics": {
"counter_server_query_cache_hit": 0,
"timer_rego_external_resolve_ns": 250,
"timer_rego_input_parse_ns": 1708,
"timer_rego_query_compile_ns": 79958,
"timer_rego_query_eval_ns": 14125,
"timer_rego_query_parse_ns": 58542,
"timer_server_handler_ns": 257583
},
"msg": "Decision Log",
"path": "policy/response",
"requested_by": "127.0.0.1:53452",
"time": "2022-08-12T23:22:27+02:00",
"timestamp": "2022-08-12T21:22:27.575339Z",
"type": "openpolicyagent.org/decision_logs"
} If there are some error conditions that would stop e.g. the decision logger from logging at all, the normal error logging of OPA would hopefully be clear enough on what caused that error. Could definitely be some cases I'm not thinking of though 🙂 |
Some information is present on the decision log, some not, but when we have debugging log turned on via the Maybe I am doing misuse of the What do you think about this? |
Seems like a simple addition to make, so if it helps you with debugging, I don't see why not :) |
Do you think that the |
Hi @anderseknert, I took some time to understand the decision log plugin and how I saw that we just have I think that this method must be updated to include the |
Seems about right @humbertoc-silva 👍 I guess we'd want to create the |
Let me see if I got it. To always have the At a first glance, it makes sense to have the |
Agreed, if it just starts showing up in decision logs for everyone, there's probably going to be a lot of questions asked about its purpose 😅 So maybe we can start by only having it logged when the "request logger" is enabled. We can always change that later if we want. |
Hi @anderseknert, I will need help to get the request ID value on the decision log plugin. I will need to do a type assertion to extract the value from the context but the type Are there other places that use this information that could be used as an example? Thank you! |
In the meantime, I tried something here. Please, check my branch out and take a look. I moved the request context temporarily to the logging package to do a test. |
Hi @anderseknert, Did you have a chance to take a look at my branch? As I mentioned earlier, I moved the request context to do a test but I think it is not the best place to move this code. I would like your opinion and orientation about this. Thank you very much! |
Hey @humbertoc-silva! And sorry for the delay. Busy week with 2 releases.. 😅 |
👀 It looks OK-ish, but I wonder if we couldn't make the RequestID part of the decision struct ( |
Hi guys, I understand @anderseknert. @srenatus on the weekend I will try to implement using this approach, making the RequestID part of the decision log struct. Can I use the contributor's channel to ask questions about the implementation? Thank you! |
Of course, that's what it's for 😃 |
Hi guys, I created a new branch and implemented the feature following the @srenatus tip (making the RequestID part of the decision struct). Could you, @anderseknert and @srenatus, check my new branch out, please? Thank you. |
You could also open a PR right away. It's easier to comment on that etc |
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: open-policy-agent#5006 Signed-off-by: Humberto Corrêa da Silva <humbertoc_silva@hotmail.com>
The documentation purpose is to explain the relation with others logs, how it could be used, and when it is included on decision logs. Fixes: open-policy-agent#5006 Signed-off-by: Humberto Corrêa da Silva <humbertoc_silva@hotmail.com>
Explain that request ID is incremental and unique by OPA instance. Define RequestContext key as an unexported const to avoid colision and provide RequestContext type-safe accessors. More info: https://pkg.go.dev/context#Context.Value Fixes: open-policy-agent#5006 Signed-off-by: Humberto Corrêa da Silva <humbertoc_silva@hotmail.com>
…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>
…pen-policy-agent#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: open-policy-agent#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> Signed-off-by: Byron Lagrone <byron.lagrone@seqster.com>
What is the underlying problem you're trying to solve?
I'm working on OPA logs (request/response logs, decision logs, status logs, etc.). I've noticed that the request/response logs have a correlation through the
req_id
attribute. I've seen that debug logging with theprint
built-in function uses this attribute too. This is useful as I can correlate all logs related to a specific request/response.I would like to know if is it a good idea to have the
req_id
attribute on decision logs too. So the correlation would be complete and I could analyze all the logs generated by OPA when handling a single request/response.Describe the ideal solution
The ideal solution is to add the attribute
req_id
to the decision log.Additional Context
I am working with the console decision log but maybe the
req_id
could be useful when the decision log is configured to send the logs to a control plane too because I can search and correlate the other logs based on this attribute.The text was updated successfully, but these errors were encountered: