設定服務頻率限制政策

本文說明如何為 Secure Web Proxy 設定服務頻率限制政策,保護系統免於流量過載,並管理傳出網路流量的費用。

事前準備

設定服務頻率限制政策

如要建立服務頻率限制政策,請在 YAML 檔案中定義設定,然後將該檔案匯入 Secure Web Proxy。

  1. 建立 my-rate-limit-policy.yaml 檔案,然後指定政策參數。

    以下範例會將傳送至大型語言模型 (LLM) 供應商 (foo.com) 的要求數量,限制為 Secure Web Proxy 閘道上每個代理每分鐘 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 執行個體的區域。

後續步驟