@@ -38,7 +38,7 @@ Example Beam Java Pipelines using it:
3838 - ** Cloud NAT (Prerequisite)** : Allows private nodes to pull Docker images.
3939- ** Envoy Rate Limit Service** : A stateless Go/gRPC service that handles rate limit logic.
4040- ** Redis** : Stores the rate limit counters.
41- - ** StatsD Exporter ** : Sidecar container that converts StatsD metrics to Prometheus format, exposed on port ` 9102 ` .
41+ - ** Prometheus Metrics ** : Exposes Prometheus metrics on port ` 9090 ` . These metrics are exported to Google Cloud Monitoring .
4242- ** Internal Load Balancer** : A Google Cloud TCP Load Balancer exposing the Rate Limit service internally within the VPC.
4343
4444## Prerequisites:
@@ -82,7 +82,7 @@ cluster_name = "ratelimit-cluster" # Name of the GKE cluster
8282deletion_protection = true # Prevent accidental cluster deletion (set "true" for prod)
8383control_plane_cidr = "172.16.0.0/28" # CIDR for GKE control plane (must not overlap with subnet)
8484namespace = "envoy-ratelimiter" # Kubernetes namespace for deployment
85- enable_metrics = false # Deploy statsd-exporter sidecar
85+ enable_metrics = true # Enable metrics export to Google Cloud Monitoring
8686ratelimit_replicas = 1 # Initial number of Rate Limit pods
8787min_replicas = 1 # Minimum HPA replicas
8888max_replicas = 5 # Maximum HPA replicas
@@ -110,25 +110,34 @@ EOF
110110```
111111
112112# Deploy Envoy Rate Limiter:
113- 1. Initialize Terraform to download providers and modules:
113+
114+ 1. **Deploy Script (Recommended)**:
115+ Run the helper script to handle the deployment process automatically:
114116```bash
115- terraform init
117+ ./deploy.sh
116118```
119+ The script will provide the ip address of the load balancer once the deployment is complete.
117120
118- 2 . Plan and apply the changes:
121+ 2 . ** Deploy (Manual Alternative)** :
122+ If you prefer running Terraform manually, you can use the following commands:
119123``` bash
120- terraform plan -out=tfplan
121- terraform apply tfplan
124+ # Step 1: Initialize Terraform
125+ terraform init
126+
127+ # Step 2: Create Cluster
128+ terraform apply -target=time_sleep.wait_for_cluster
129+
130+ # Step 3: Create Resources
131+ terraform apply
122132```
123133
124- 3 . Connect to the service:
125134After deployment, get the ** Internal** IP address:
126135``` bash
127136terraform output load_balancer_ip
128137```
129138The service is accessible ** only from within the VPC** (e.g., via Dataflow workers or GCE instances in the same network) at ` <INTERNAL_IP>:8081 ` .
130139
131- 4 . ** Test with Dataflow Workflow** :
140+ 3 . ** Test with Dataflow Workflow** :
132141 Verify connectivity and rate limiting logic by running the example Dataflow pipeline.
133142
134143 ``` bash
@@ -150,11 +159,40 @@ The service is accessible **only from within the VPC** (e.g., via Dataflow worke
150159 ```
151160
152161
162+ # Observability & Metrics:
163+ This module supports exporting native Prometheus metrics to ** Google Cloud Monitoring** .
164+
165+ ` enable_metrics ` is set to ` true ` by default.
166+
167+ ### Sample Metrics
168+ | Metric Name | Description |
169+ | :--- | :--- |
170+ | ` ratelimit_service_rate_limit_total_hits ` | Total rate limit requests received. |
171+ | ` ratelimit_service_rate_limit_over_limit ` | Requests that exceeded the limit (HTTP 429). |
172+ | ` ratelimit_service_rate_limit_near_limit ` | Requests that are approaching the limit. |
173+ | ` ratelimit_service_call_should_rate_limit ` | Total valid gRPC calls to the service. |
174+
175+ * Note: You will also see many other Go runtime metrics (` go_* ` ) and Redis client metrics (` redis_* ` )
176+
177+ ### Viewing in Google Cloud Console
178+ 1 . Go to ** Monitoring** > ** Metrics Explorer** .
179+ 2 . Click ** Select a metric** .
180+ 3 . Search for ` ratelimit ` and select ** Prometheus Target** > ** ratelimit** .
181+ 4 . Select a metric (e.g., ` ratelimit_service_rate_limit_over_limit ` ) and click ** Apply** .
182+ 5 . Use ** Filters** to drill down by ` domain ` , ` key ` , and ` value ` (e.g., ` key=database ` , ` value=users ` ).
183+
153184# Clean up resources:
154185To destroy the cluster and all created resources:
186+
187+ ``` bash
188+ ./deploy.sh destroy
189+ ```
190+
191+ Alternatively:
155192``` bash
156193terraform destroy
157194```
195+
158196* Note: If ` deletion_protection ` was enabled, you must set it to ` false ` in ` terraform.tfvars ` before destroying.*
159197
160198# Variables description:
@@ -169,7 +207,7 @@ terraform destroy
169207| control_plane_cidr | CIDR block for GKE control plane | 172.16.0.0/28 |
170208| cluster_name | Name of the GKE cluster | ratelimit-cluster |
171209| namespace | Kubernetes namespace to deploy resources into | envoy-ratelimiter |
172- | enable_metrics | Deploy statsd-exporter sidecar | false |
210+ | enable_metrics | Enable metrics export to Google Cloud Monitoring | true |
173211| deletion_protection | Prevent accidental cluster deletion | false |
174212| ratelimit_replicas | Initial number of Rate Limit pods | 1 |
175213| min_replicas | Minimum HPA replicas | 1 |
0 commit comments