Add x-rate-limit响应头到负载均衡器

huangapple go评论64阅读模式
英文:

Add x-rate-limit response headers to the load balancer

问题

我配置了Cloud Armor 速率限制规则,我想将以下自定义响应标头附加到我的全局外部HTTP(S)负载均衡器后端。

x-ratelimit-limit: 当前时间段内可用的最大请求数。
x-ratelimit-remaining: 当前时间段内剩余的请求数。
x-ratelimit-reset: 预计速率限制将重置的UNIX时间戳。

自定义标头文档中似乎没有速率限制变量。然而,文档中后面有关于Cloud Armor响应标头的注意:

> 您可以配置Google Cloud Armor以插入自定义标头和值。

我找到了--request-headers-to-add规则设置,但我需要一种访问当前Cloud Armor速率限制值的方式。

我的用例是否不可能实现,还是有人可以指引我走正确的方向?

英文:

I configured a Cloud Armor rate limiting rule and i would like to attach the following custom response headers to my global external HTTP(S) load balancer backend.

x-ratelimit-limit: The maximum number of requests available in the current time frame.
x-ratelimit-remaining: The number of remaining requests in the current time frame.
x-ratelimit-reset: A UNIX timestamp of the expected time when the rate limit will reset.

In the custom headers documentation no rate limit variable seems to exist. There is however a notice about Cloud Armor Response Headers further down:

> You can configure Google Cloud Armor to insert a custom header and value.

I found the --request-headers-to-add rule setting but i need some way to access the current Cloud Armor rate limit values.

Is my use case not possible or can anyone point me in the right direction?

答案1

得分: 1

你可以创建一个云函数来检索 Cloud Armor 速率限制值,以执行以下操作:

  • 创建一个使用 Google Cloud 客户端库的云函数,该函数用于检索 Cloud Armor 速率限制值并设置自定义响应标头。将此代码部署到您的项目中。
  • 现在,配置您的全局外部 HTTP(S) 负载均衡器以通过云函数路由请求。创建一个后端服务,将其指向云函数的 URL,然后将后端服务添加到负载均衡器后端配置中。请查看 Cloud 负载均衡官方文档以获取更多信息。
英文:

You can create a Cloud Function to retrieve Cloud Armor rate limit values to do this:

  • Create a code with Cloud Function which retrieves the Cloud Armor rate limit values and sets the custom response headers. Use Google Cloud Client Libraries for this and deploy the code into your project.
  • Now configure your global external HTTP(S) load balancer to route requests through the Cloud Function. Create a backend service which points to the Cloud Function URL and then add backend service to the load balancer backend configuration. Please check Cloud Load Balancing official documentation.

huangapple
  • 本文由 发表于 2023年2月26日 19:43:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75571745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定