配置服务速率限制政策

本文档介绍如何为 Secure Web Proxy 配置 服务速率限制 政策 ,以保护您的系统免受流量过载的影响,并管理出站 Web 流量的 费用。

准备工作

设置服务速率限制政策

如需创建服务速率限制政策,请在 YAML 文件中定义配置,然后将该文件导入 Secure Web Proxy。

  1. 创建 my-rate-limit-policy.yaml 文件,然后指定政策参数。

    以下示例将发送给大型语言模型 (LLM) 提供商 (foo.com) 的请求数限制为:对于出站流量,Secure Web 代理网关上的每个代理每分钟 100 个请求。每个代理都由其客户端证书中的通用名称标识。

      name: "projects/ PROJECT_ID /locations/ LOCATION /rateLimitPolicies/test-policy"
      description: "Simple agent for LLM rate limiting."
      httpRules:
      # Match on the provider host name.
      - to:
          destination:
            hosts:
            - exact: "foo.com"
    
        # default RPM bucket
        rateLimitActions:
        - rateLimitBucket: "rl_default_rpm_limit"
    
      rateLimitBuckets:
      - name: "rl_default_rpm_limit"
        # Identify client by its client cert name
        keys:
        - keyType: PRINCIPAL
          principalType: CLIENT_CERT_COMMON_NAME
        defaultLimit:
          countLimit:
            count: 100
            interval: 1
            intervalUnit: MINUTES
    
      targets:
      - resource: "projects/ PROJECT_ID /locations/ LOCATION /gateways/ GATEWAY_NAME "
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目的 ID
    • LOCATION:Secure Web Proxy 实例的区域;例如, us-central1
    • GATEWAY_NAME:Secure Web Proxy 网关实例的名称
  2. 使用以下命令导入速率限制政策 YAML 文件:

    gcloud alpha network-security rate-limit-policies import test-policy \
      --source=my-rate-limit-policy.yaml \
      --location=LOCATION
    

    将 LOCATION 替换为 Secure Web Proxy 实例的区域。

后续步骤