如何从OPA服务器捕获所有请求日志

发布于 2025-01-24 16:36:04 字数 1293 浏览 3 评论 0原文

我正在使用开放策略代理( https://wwwww.openpolicyagent.org/docs.org/docs/latest/latest/ < /a>)。我正在Kubernetes中使用它。我正在进行各种用户流量。我有这样的容器日志:

{"client_addr":"[::1]:52362","level":"info","msg":"Received request.","req_body":"","req_id":21,"req_method":"GET","req_params":{},"req_path":"/v1/policies","time":"2022-04-26T15:39:57Z"}

{"client_addr":"[::1]:52362","level":"info","msg":"Sent response.","req_id":21,"req_method":"GET","req_path":"/v1/policies","resp_body":"","resp_bytes":28883,"resp_duration":4.901654,"resp_status":200,"time":"2022-04-26T15:39:57Z"}

我想使用这些日志进行监视,因为它们显示了响应状态请求详细信息,持续时间等。有人知道如何定期获取这些日志吗?我想将它们持续到我的数据库中。

我尝试了/指标端点: https://wwwwwww.openpolicyagent.org/docs/latest/latest/latest/监视/ 但这几乎没有细节,还不够富裕。

我还尝试了决策日志: https://www.openpolicyagent.org/docs/docs /最新/管理 - 决策/它们很好,但是它们没有涵盖对OPA的所有请求。

在我的用例中,我想填充Azure App Insights的请求数据库,

有没有办法捕获所有请求?

I'm using Open Policy Agent (https://www.openpolicyagent.org/docs/latest/). I'm using it in kubernetes. I have various user traffic going on. I have such container logs:

{"client_addr":"[::1]:52362","level":"info","msg":"Received request.","req_body":"","req_id":21,"req_method":"GET","req_params":{},"req_path":"/v1/policies","time":"2022-04-26T15:39:57Z"}

{"client_addr":"[::1]:52362","level":"info","msg":"Sent response.","req_id":21,"req_method":"GET","req_path":"/v1/policies","resp_body":"","resp_bytes":28883,"resp_duration":4.901654,"resp_status":200,"time":"2022-04-26T15:39:57Z"}

I would like to use these logs for monitoring, because they show response status request details, duration and so on. Does anyone has any idea how to get these logs on regular basis? I would like to persist them in my database.

I tried the /metrics endpoint: https://www.openpolicyagent.org/docs/latest/monitoring/
but it has little details, not rich enough for my need.

I also tried decision logs: https://www.openpolicyagent.org/docs/latest/management-decision-logs/ they are good, but they don't cover all the requests made to OPA.

In my use case, I would like to populate requests database of Azure App Insights

Is there a way to capture all the requests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稍尽春風 2025-01-31 16:36:04

决策记录状态API 对于健康检查,人们通常是人们在生产系统中登录的内容。这应该涵盖您可能拥有的任何需求,因为OPA只要健康就可以做出决定,并且如果它不健康,则状态API将被用来报告。

您是否发现您缺少 /没有被决策记录仪记录的东西吗?

Decision logging for decisions together with the status API for health checks is generally what people log in production systems. This should cover pretty much any need you might have since OPA will produce decisions as long as its healthy, and if it isn't healthy the status API will be used to report that.

Was there anything in particular you found missing / not logged by the decision logger?

分开我的手 2025-01-31 16:36:04

一种对我有用的方式:

  1. 创建一个自定义Docker容器。将OPA放在那里,并配置Python环境。
  2. 运行OPA并将所有日志传输到Python程序。
  3. python将按行读取日志,解析它们,然后使用 opencensus-ext-ext-azure 库,将它们发送到Azure App Insights。

A way that worked for me:

  1. Create a custom docker container. Put OPA there and configure python environment.
  2. Run OPA and stream all logs to python program.
  3. Python will read logs line by line, parse them, then using opencensus-ext-azure library, send them to Azure App Insights.
绝影如岚 2025-01-31 16:36:04

有效的方法:

由于OPA是一个Docker容器,它在Azure AKS资源中的Kubernetes中运行,这意味着将容器日志发送到containerLogs表,可以通过浏览来手动访问:Azure AKS Resources - &gt;日志

如何使用代码获取容器日志?请参阅下面的说明:

  1. 创建日志分析工作区资源,以累积容器日志。
  2. 转到Azure Kubernetes服务,转到诊断设置,将日志配置为您在第1点创建的日志分析空间。
  3. 使用 azure Monitor Log Analytics API 获取容器日志。
  4. 使用您喜欢的编程语言将日志发布到Azure App Insights。

A way that worked:

Since OPA is a docker container, which runs in kubernetes in Azure AKS resource, this means, container logs are sent to ContainerLogs table, which could be accessed manually by going: Azure AKS resource -> Logs

How to get container logs with code? Please see explanation below:

  1. Create Log Analytics workspace resource, to accumulate container logs.
  2. Go to Azure kubernetes service, go to Diagnostic settings, configure sending logs to log analytics workspace you created in point 1.
  3. Use Azure Monitor Log Analytics API to get container logs.
  4. Publish logs to Azure App insights using your favorite programming language.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文