Skip to content

Commit 4492ffb

Browse files
authored
Merge branch 'master' into fix-python-postcommit-dependency-1
2 parents b957f6b + b6bc904 commit 4492ffb

322 files changed

Lines changed: 3478 additions & 1420 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ class BeamModulePlugin implements Plugin<Project> {
676676
activemq_junit : "org.apache.activemq.tooling:activemq-junit:$activemq_version",
677677
activemq_kahadb_store : "org.apache.activemq:activemq-kahadb-store:$activemq_version",
678678
activemq_mqtt : "org.apache.activemq:activemq-mqtt:$activemq_version",
679+
aircompressor : "io.airlift:aircompressor:2.0.3",
679680
args4j : "args4j:args4j:2.33",
680681
auto_value_annotations : "com.google.auto.value:auto-value-annotations:$autovalue_version",
681682
// TODO: https://github.com/apache/beam/issues/34993 after stopping supporting Java 8
@@ -1534,7 +1535,6 @@ class BeamModulePlugin implements Plugin<Project> {
15341535
"AutoValueImmutableFields",
15351536
"AutoValueSubclassLeaked",
15361537
"BadImport",
1537-
"BadInstanceof",
15381538
"BigDecimalEquals",
15391539
"ComparableType",
15401540
"DoNotMockAutoValue",
@@ -1544,7 +1544,6 @@ class BeamModulePlugin implements Plugin<Project> {
15441544
"EqualsUnsafeCast",
15451545
"EscapedEntity",
15461546
"ExtendsAutoValue",
1547-
"InlineFormatString",
15481547
"InlineMeSuggester",
15491548
"InvalidBlockTag",
15501549
"InvalidInlineTag",
@@ -1555,35 +1554,28 @@ class BeamModulePlugin implements Plugin<Project> {
15551554
"JavaUtilDate",
15561555
"JodaConstructors",
15571556
"MalformedInlineTag",
1558-
"MissingSummary",
15591557
"MixedMutabilityReturnType",
15601558
"PreferJavaTimeOverload",
1561-
"MutablePublicArray",
15621559
"NonCanonicalType",
1563-
"ProtectedMembersInFinalClass",
15641560
"Slf4jFormatShouldBeConst",
15651561
"Slf4jSignOnlyFormat",
15661562
"StaticAssignmentInConstructor",
15671563
"ThreadPriorityCheck",
15681564
"TimeUnitConversionChecker",
15691565
"UndefinedEquals",
15701566
"UnescapedEntity",
1571-
"UnnecessaryLambda",
15721567
"UnnecessaryMethodReference",
15731568
"UnnecessaryParentheses",
15741569
"UnrecognisedJavadocTag",
15751570
"UnsafeReflectiveConstructionCast",
1576-
"UseCorrectAssertInTests",
15771571
// errorprone 3.2.0+ checks
15781572
"DirectInvocationOnMock",
15791573
"Finalize",
15801574
"JUnitIncompatibleType",
1581-
"LongDoubleConversion",
15821575
"MockNotUsedInProduction",
15831576
"NarrowCalculation",
15841577
"NullableTypeParameter",
15851578
"NullableWildcard",
1586-
"StringCharset",
15871579
"SuperCallToObjectMethod",
15881580
"UnnecessaryLongToIntConversion",
15891581
"UnusedVariable",
@@ -3124,7 +3116,8 @@ class BeamModulePlugin implements Plugin<Project> {
31243116
// pip 25.1 casues :sdks:python:installGcpTest stuck. Pin to 25.0.1 for now.
31253117
args '-c', ". ${project.ext.envdir}/bin/activate && " +
31263118
"pip install --pre --retries 10 --upgrade pip==25.0.1 --no-cache-dir && " +
3127-
"pip install --pre --retries 10 --upgrade tox --no-cache-dir"
3119+
"pip install --pre --retries 10 --upgrade tox --no-cache-dir && " +
3120+
"pip install --pre --retries 10 --upgrade setuptools build --no-cache-dir"
31283121
}
31293122
}
31303123
// Gradle will delete outputs whenever it thinks they are stale. Putting a
@@ -3165,14 +3158,16 @@ class BeamModulePlugin implements Plugin<Project> {
31653158
def distTarBall = "${pythonRootDir}/build/apache-beam.tar.gz"
31663159
def packages = "gcp,test,aws,azure,dataframe"
31673160
def extra = project.findProperty('beamPythonExtra')
3168-
if (extra) {
3169-
packages += ",${extra}"
3170-
}
3171-
31723161
project.exec {
31733162
executable 'sh'
31743163
args '-c', ". ${project.ext.envdir}/bin/activate && pip install --pre --retries 10 ${distTarBall}[${packages}]"
31753164
}
3165+
if (extra) {
3166+
project.exec {
3167+
executable 'sh'
3168+
args '-c', ". ${project.ext.envdir}/bin/activate && pip install --pre --retries 10 ${distTarBall}[${extra}]"
3169+
}
3170+
}
31763171
}
31773172
}
31783173

examples/java/src/main/java/org/apache/beam/examples/complete/game/injector/Injector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.beam.examples.complete.game.injector;
1919

20+
import static java.nio.charset.StandardCharsets.UTF_8;
21+
2022
import com.google.api.services.pubsub.Pubsub;
2123
import com.google.api.services.pubsub.model.PublishRequest;
2224
import com.google.api.services.pubsub.model.PubsubMessage;
@@ -327,7 +329,7 @@ public static void publishData(int numMessages, int delayInMillis) throws IOExce
327329
for (int i = 0; i < Math.max(1, numMessages); i++) {
328330
Long currTime = System.currentTimeMillis();
329331
String message = generateEvent(currTime, delayInMillis);
330-
PubsubMessage pubsubMessage = new PubsubMessage().encodeData(message.getBytes("UTF-8"));
332+
PubsubMessage pubsubMessage = new PubsubMessage().encodeData(message.getBytes(UTF_8));
331333
pubsubMessage.setAttributes(
332334
ImmutableMap.of(
333335
GameConstants.TIMESTAMP_ATTRIBUTE,
@@ -350,7 +352,7 @@ public static void publishDataToFile(String fileName, int numMessages, int delay
350352
PrintWriter out =
351353
new PrintWriter(
352354
new OutputStreamWriter(
353-
new BufferedOutputStream(new FileOutputStream(fileName, true)), "UTF-8"));
355+
new BufferedOutputStream(new FileOutputStream(fileName, true)), UTF_8));
354356

355357
try {
356358
for (int i = 0; i < Math.max(1, numMessages); i++) {

examples/terraform/envoy-ratelimiter/README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
8282
deletion_protection = true # Prevent accidental cluster deletion (set "true" for prod)
8383
control_plane_cidr = "172.16.0.0/28" # CIDR for GKE control plane (must not overlap with subnet)
8484
namespace = "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
8686
ratelimit_replicas = 1 # Initial number of Rate Limit pods
8787
min_replicas = 1 # Minimum HPA replicas
8888
max_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:
125134
After deployment, get the **Internal** IP address:
126135
```bash
127136
terraform output load_balancer_ip
128137
```
129138
The 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:
154185
To destroy the cluster and all created resources:
186+
187+
```bash
188+
./deploy.sh destroy
189+
```
190+
191+
Alternatively:
155192
```bash
156193
terraform 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 |
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
# This script deploys the Envoy Rate Limiter on GKE.
20+
21+
set -e
22+
23+
COMMAND=${1:-"apply"}
24+
25+
# 1. Initialize Terraform
26+
if [ ! -d ".terraform" ]; then
27+
echo "Initializing Terraform..."
28+
terraform init
29+
else
30+
# Verify terraform initialization is valid, or re-initialize
31+
terraform init -upgrade=false >/dev/null 2>&1 || terraform init
32+
fi
33+
34+
if [ "$COMMAND" = "destroy" ]; then
35+
echo "Destroying Envoy Rate Limiter Resources..."
36+
terraform destroy -auto-approve
37+
exit $?
38+
fi
39+
40+
if [ "$COMMAND" = "apply" ]; then
41+
echo "Deploying Envoy Rate Limiter..."
42+
43+
echo "--------------------------------------------------"
44+
echo "Creating/Updating GKE Cluster..."
45+
echo "--------------------------------------------------"
46+
# Deploy the cluster and wait for it to be ready.
47+
terraform apply -target=time_sleep.wait_for_cluster -auto-approve
48+
49+
echo ""
50+
echo "--------------------------------------------------"
51+
echo "Deploying Application Resources..."
52+
echo "--------------------------------------------------"
53+
# Deploy the rest of the resources
54+
terraform apply -auto-approve
55+
56+
echo ""
57+
echo "Deployment Complete!"
58+
echo "Cluster Name: $(terraform output -raw cluster_name)"
59+
echo "Load Balancer IP: $(terraform output -raw load_balancer_ip)"
60+
exit 0
61+
fi
62+
63+
echo "Usage:"
64+
echo " ./deploy.sh [apply] # Initialize and deploy resources (Default)"
65+
echo " ./deploy.sh destroy # Destroy resources"
66+
exit 1

examples/terraform/envoy-ratelimiter/prerequisites.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "google_project_service" "required" {
2121
"container",
2222
"iam",
2323
"compute",
24+
"monitoring",
2425
])
2526

2627
service = "${each.key}.googleapis.com"

0 commit comments

Comments
 (0)