Skip to content

Commit bec21cf

Browse files
committed
[Dataflow Java Runner] Add support for sending logs directly to Cloud Logging
1 parent fcbb034 commit bec21cf

File tree

11 files changed

+1361
-254
lines changed

11 files changed

+1361
-254
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ class BeamModulePlugin implements Plugin<Project> {
757757
google_cloud_datastore_v1_proto_client : "com.google.cloud.datastore:datastore-v1-proto-client:2.34.0", // [bomupgrader] sets version
758758
google_cloud_firestore : "com.google.cloud:google-cloud-firestore", // google_cloud_platform_libraries_bom sets version
759759
google_cloud_kms : "com.google.cloud:google-cloud-kms", // google_cloud_platform_libraries_bom sets version
760+
google_cloud_logging : "com.google.cloud:google-cloud-logging", // google_cloud_platform_libraries_bom sets version
760761
google_cloud_pubsub : "com.google.cloud:google-cloud-pubsub", // google_cloud_platform_libraries_bom sets version
761762
// [bomupgrader] the BOM version is set by scripts/tools/bomupgrader.py. If update manually, also update
762763
// libraries-bom version on sdks/java/container/license_scripts/dep_urls_java.yaml
@@ -772,7 +773,6 @@ class BeamModulePlugin implements Plugin<Project> {
772773
google_http_client_apache_v2 : "com.google.http-client:google-http-client-apache-v2", // google_cloud_platform_libraries_bom sets version
773774
google_http_client_gson : "com.google.http-client:google-http-client-gson", // google_cloud_platform_libraries_bom sets version
774775
google_http_client_jackson : "com.google.http-client:google-http-client-jackson:1.29.2",
775-
google_http_client_gson : "com.google.http-client:google-http-client-gson", // google_cloud_platform_libraries_bom sets version
776776
google_http_client_protobuf : "com.google.http-client:google-http-client-protobuf", // google_cloud_platform_libraries_bom sets version
777777
google_oauth_client : "com.google.oauth-client:google-oauth-client:$google_oauth_clients_version",
778778
google_oauth_client_java6 : "com.google.oauth-client:google-oauth-client-java6:$google_oauth_clients_version",

runners/google-cloud-dataflow-java/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ dependencies {
110110
implementation library.java.google_http_client
111111
implementation library.java.google_http_client_gson
112112
permitUnusedDeclared library.java.google_http_client_gson // BEAM-11761
113+
implementation library.java.google_cloud_logging
114+
permitUnusedDeclared library.java.google_cloud_logging // BEAM-11761
113115
implementation library.java.hamcrest
114116
implementation library.java.jackson_annotations
115117
implementation library.java.jackson_core

runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/options/DataflowWorkerLoggingOptions.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,38 @@ enum Level {
6666

6767
void setDefaultWorkerLogLevel(Level level);
6868

69+
/**
70+
* Controls the log level for which messages are uploaded to Cloud Logging. If a message is
71+
* configured to be sent to both directly to cloud logging and default disk-based logging it will
72+
* just be sent to disk-based logging. This allows for configuration such as
73+
* "--defaultWorkerLogLevel=WARN --defaultWorkerDirectLoggerLevel=INFO where INFO logs will be
74+
* directly sent to cloud logging and WARN logs and higher will be sent to disk-based logging.
75+
*
76+
* <p>Note that this is just the default and may be overridden for specific classes with
77+
* --workerDirectLogLevelOverrides.
78+
*/
79+
@Description(
80+
"Controls the default direct to Cloud Logging level of all logs without a log level override."
81+
+ "If a message is configured to be sent to both directly to cloud logging and default disk-based logging "
82+
+ "it will just be sent to disk-based logging.")
83+
@Default.Enum("OFF")
84+
Level getDefaultWorkerDirectLoggerLevel();
85+
86+
void setDefaultWorkerDirectLoggerLevel(Level level);
87+
88+
@Description(
89+
"The maximum buffered bytes for records in the queue that are being sent directly to Cloud Logging.")
90+
@Default.Long(100L * 1024 * 1024)
91+
Long getWorkerDirectLoggerBufferByteLimit();
92+
93+
void setWorkerDirectLoggerBufferByteLimit(Long value);
94+
95+
@Description("The maximum buffered elements in the queue being sent directly to Cloud Logging.")
96+
@Default.Long(1_000_000)
97+
Long getWorkerDirectLoggerBufferElementLimit();
98+
99+
void setWorkerDirectLoggerBufferElementLimit(Long value);
100+
69101
/**
70102
* Controls the log level given to messages printed to {@code System.out}.
71103
*
@@ -121,6 +153,48 @@ enum Level {
121153

122154
void setWorkerLogLevelOverrides(WorkerLogLevelOverrides value);
123155

156+
/**
157+
* This option controls the direct log levels for specifically named loggers. If a message is
158+
* configured to be sent to both directly to cloud logging and default disk-based logging it will
159+
* just be sent to disk-based logging. If an override only exists for a logger for direct logging,
160+
* the --defaultWorkerLogLevel will be used for the non-direct configuration for the logger.
161+
*
162+
* <p>Later options with equivalent names override earlier options.
163+
*
164+
* <p>See {@link WorkerLogLevelOverrides} for more information on how to configure logging on a
165+
* per {@link Class}, {@link Package}, or name basis. If used from the command line, the expected
166+
* format is {"Name":"Level",...}, further details on {@link WorkerLogLevelOverrides#from}.
167+
*/
168+
@Description(
169+
"This option controls the direct log levels for specifically named loggers. "
170+
+ "The expected format is {\"Name\":\"Level\",...}. The Dataflow worker supports a logging "
171+
+ "hierarchy based off of names that are '.' separated. For example, by specifying the value "
172+
+ "{\"a.b.c.Foo\":\"DEBUG\"}, the logger for the class 'a.b.c.Foo' will be configured to "
173+
+ "output logs at the DEBUG level. Similarly, by specifying the value {\"a.b.c\":\"WARN\"}, "
174+
+ "all loggers underneath the 'a.b.c' package will be configured to output logs at the WARN "
175+
+ "level. System.out and System.err levels are configured via loggers of the corresponding "
176+
+ "name. Also, note that when multiple overrides are specified, the exact name followed by "
177+
+ "the closest parent takes precedence. Note that if an override is just provided for the direct log level "
178+
+ "for a logger, the default non-direct log level will be used for non-direct logs.")
179+
WorkerLogLevelOverrides getWorkerDirectLogLevelOverrides();
180+
181+
void setWorkerDirectLogLevelOverrides(WorkerLogLevelOverrides value);
182+
183+
@Default.Boolean(true)
184+
@Description(
185+
"If true, when there are errors with sending logs directly to Cloud Logging, the logs will fallback to "
186+
+ "disk-based logging. If false, such logs will be dropped.")
187+
Boolean getDirectLoggingFallbackToDiskOnErrors();
188+
189+
void setDirectLoggingFallbackToDiskOnErrors(Boolean value);
190+
191+
@Default.Integer(10)
192+
@Description(
193+
"If an error is encountered with sending logs directly to Cloud Logging, direct logging will not be attempted for this many seconds.")
194+
Integer getDirectLoggingCooldownSeconds();
195+
196+
void setDirectLoggingCooldownSeconds(Integer value);
197+
124198
/**
125199
* Defines a log level override for a specific class, package, or name.
126200
*

runners/google-cloud-dataflow-java/worker/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ dependencies {
193193

194194
implementation library.java.google_auth_library_credentials
195195
implementation library.java.proto_google_common_protos
196+
implementation library.java.google_cloud_logging
196197

197198
// Conscrypt shouldn't be included here because Conscrypt won't work when being shaded.
198199
// (Context: https://github.com/apache/beam/pull/13846)

0 commit comments

Comments
 (0)