From 816d25777819def466de74bb95ffaee9b611b723 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 20:58:11 +0000 Subject: [PATCH 1/6] chore(main): release 0.128.11-SNAPSHOT (#976) :robot: I have created a release *beep* *boop* --- ### Updating meta-information for bleeding-edge SNAPSHOT release. --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please). --- pom.xml | 2 +- samples/snapshot/pom.xml | 2 +- .../java/com/google/cloud/logging/logback/LoggingAppender.java | 2 +- versions.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 170d6bec8..bfea39f4e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 google-cloud-logging-logback - 0.129.10-alpha + 0.129.11-alpha-SNAPSHOT jar Google Cloud Logging Logback Appender https://github.com/googleapis/java-logging-logback diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 948fb8188..0c345d0e3 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,7 +28,7 @@ com.google.cloud google-cloud-logging-logback - 0.129.10-alpha + 0.129.11-alpha-SNAPSHOT diff --git a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 42ae0df89..48274898a 100644 --- a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -108,7 +108,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase { // See // https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files // {x-version-update-start:google-cloud-logging-logback:current} - public static final String DEFAULT_INSTRUMENTATION_VERSION = "0.129.10-alpha"; + public static final String DEFAULT_INSTRUMENTATION_VERSION = "0.129.11-alpha-SNAPSHOT"; // {x-version-update-end} private static boolean instrumentationAdded = false; private static final Object instrumentationLock = new Object(); diff --git a/versions.txt b/versions.txt index 6850a3f41..18dd74d40 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-logging-logback:0.129.10-alpha:0.129.10-alpha +google-cloud-logging-logback:0.129.10-alpha:0.129.11-alpha-SNAPSHOT From d93c150933cc57e1d8377f72eba20e7107d998f8 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 11 Jan 2023 17:56:43 +0000 Subject: [PATCH 2/6] chore(deps): update dependency com.google.cloud:google-cloud-logging-logback to v0.129.10-alpha (#978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): update dependency com.google.cloud:google-cloud-logging-logback to v0.129.10-alpha * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- README.md | 6 +++--- samples/install-without-bom/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 972a0bd8a..b77c30efd 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-logging-logback - 0.129.9-alpha + 0.129.10-alpha ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-logging-logback:0.129.9-alpha' +implementation 'com.google.cloud:google-cloud-logging-logback:0.129.10-alpha' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.129.9-alpha" +libraryDependencies += "com.google.cloud" % "google-cloud-logging-logback" % "0.129.10-alpha" ``` ## Authentication diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index d7f9056f0..4abc15795 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,7 +29,7 @@ com.google.cloud google-cloud-logging-logback - 0.129.9-alpha + 0.129.10-alpha From afbe09c62647bca8eb9aa51f5ab63a13396800f7 Mon Sep 17 00:00:00 2001 From: losalex <90795544+losalex@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:26:21 -0800 Subject: [PATCH 3/6] feat: Add support for batching configuration (#977) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add support for batching configuration * Add space * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Remove redundant HTML appender tag * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add failing dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .readme-partials.yaml | 18 +++- README.md | 18 +++- pom.xml | 10 ++- .../logback/LogbackBatchingSettings.java | 87 +++++++++++++++++++ .../logging/logback/LoggingAppender.java | 32 ++++++- .../logback/LoggingAppenderLogbackTest.java | 57 ++++++++++++ .../google/cloud/logging/logback/logback.xml | 57 ++++++++++++ 7 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/google/cloud/logging/logback/LogbackBatchingSettings.java create mode 100644 src/test/java/com/google/cloud/logging/logback/LoggingAppenderLogbackTest.java create mode 100644 src/test/java/com/google/cloud/logging/logback/logback.xml diff --git a/.readme-partials.yaml b/.readme-partials.yaml index 3a9925d33..209e8a391 100644 --- a/.readme-partials.yaml +++ b/.readme-partials.yaml @@ -17,7 +17,7 @@ custom_content: | application.log - WARNING + WARN SYNC @@ -43,7 +43,21 @@ custom_content: | - true + true + + + + 100 + 1000 + 500 + 10000 + 100000 + Ignore + diff --git a/README.md b/README.md index b77c30efd..5aabe0ea6 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter application.log - WARNING + WARN SYNC @@ -114,7 +114,21 @@ See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter - true + true + + + + 100 + 1000 + 500 + 10000 + 100000 + Ignore + diff --git a/pom.xml b/pom.xml index bfea39f4e..166bb603a 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,15 @@ com.google.protobuf protobuf-java - + + + com.google.api + gax + + + org.threeten + threetenbp + diff --git a/src/main/java/com/google/cloud/logging/logback/LogbackBatchingSettings.java b/src/main/java/com/google/cloud/logging/logback/LogbackBatchingSettings.java new file mode 100644 index 000000000..48e8b7b9a --- /dev/null +++ b/src/main/java/com/google/cloud/logging/logback/LogbackBatchingSettings.java @@ -0,0 +1,87 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.logging.logback; + +import com.google.api.gax.batching.BatchingSettings; +import com.google.api.gax.batching.FlowControlSettings; +import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import org.threeten.bp.Duration; + +/** + * This class is used only to provide batch settings configuration in logback.xml since {@link + * com.google.api.gax.batching.BatchingSettings} cannot be used as is with logback configuration + * described in https://logback.qos.ch/manual/configuration.html. All data members below are simply + * copy of {@link com.google.api.gax.batching.BatchingSettings} class, so it could be used with + * logback.xml. + */ +public class LogbackBatchingSettings { + private Long elementCountThreshold = null; + private Long requestByteThreshold = null; + private Long delayThreshold = null; + private Long maxOutstandingElementCount = null; + private Long maxOutstandingRequestBytes = null; + private LimitExceededBehavior limitExceededBehavior = null; + + public void setElementCountThreshold(Long value) { + elementCountThreshold = value; + } + + public void setRequestByteThreshold(Long value) { + requestByteThreshold = value; + } + + public void setDelayThreshold(Long value) { + delayThreshold = value; + } + + public void setMaxOutstandingElementCount(Long value) { + maxOutstandingElementCount = value; + } + + public void setMaxOutstandingRequestBytes(Long value) { + maxOutstandingRequestBytes = value; + } + + public void setLimitExceededBehavior(LimitExceededBehavior value) { + limitExceededBehavior = value; + } + + public BatchingSettings build() { + BatchingSettings.Builder settings = BatchingSettings.newBuilder(); + if (elementCountThreshold != null) { + settings.setElementCountThreshold(elementCountThreshold); + } + if (requestByteThreshold != null) { + settings.setRequestByteThreshold(requestByteThreshold); + } + if (delayThreshold != null) { + settings.setDelayThreshold(Duration.ofMillis(delayThreshold)); + } + if (maxOutstandingElementCount != null + || maxOutstandingRequestBytes != null + || limitExceededBehavior != null) { + FlowControlSettings.Builder flowControlSettings = FlowControlSettings.newBuilder(); + flowControlSettings.setMaxOutstandingElementCount(maxOutstandingElementCount); + flowControlSettings.setMaxOutstandingRequestBytes(maxOutstandingRequestBytes); + if (limitExceededBehavior != null) { + flowControlSettings.setLimitExceededBehavior(limitExceededBehavior); + } + settings.setFlowControlSettings(flowControlSettings.build()); + } + return settings.build(); + } +} diff --git a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 48274898a..3d88bceb0 100644 --- a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -63,7 +63,7 @@ * <log>application.log</log> * * <!-- Optional: defaults to {@code "ERROR"} --> - * <flushLevel>WARNING</flushLevel> + * <flushLevel>WARN</flushLevel> * * <!-- Optional: defaults to {@code ASYNC} --> * <writeSynchronicity>SYNC</writeSynchronicity> @@ -91,6 +91,20 @@ * * <!-- Optional: specifies if a batch's valid entries should be written even if some other entry failed due to an error. Defaults to {@code true} --> * <partialSuccess>true</partialSuccess> + * + * <!-- Optional: In the asynchronous mode the call(s) to Logging API takes place asynchronously and few calls to `write()` + * method may be batched together to compose a single call to Logging API. In order to control the batching settings, + * the `logbackBatchingSettings` section can be used as shown below. + * See [BatchingSettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.batching.BatchingSettings) + * for more info regarding parameters shown below --> + * <logbackBatchingSettings> + * <elementCountThreshold>100</elementCountThreshold> + * <requestByteThreshold>1000</requestByteThreshold> + * <delayThreshold>500</delayThreshold> + * <maxOutstandingElementCount>10000</maxOutstandingElementCount> + * <maxOutstandingRequestBytes>100000</maxOutstandingRequestBytes> + * <limitExceededBehavior>Ignore</limitExceededBehavior> + * </logbackBatchingSettings> * </appender> * */ @@ -131,6 +145,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase { private Synchronicity writeSyncFlag = Synchronicity.ASYNC; private final Set enhancerClassNames = new HashSet<>(); private final Set loggingEventEnhancerClassNames = new HashSet<>(); + private LogbackBatchingSettings logbackBatchingSettings = null; /** * Sets a threshold for log severity level to flush all log entries that were batched so far. @@ -224,6 +239,19 @@ public void setRedirectToStdout(boolean flag) { redirectToStdout = flag; } + /** + * Sets the {@link LogbackBatchingSettings} to be used for the asynchronous mode call(s) to + * Logging API + * + *

Default to {@code null}. + * + * @param batchingSettings the {@link LogbackBatchingSettings} to be used for asynchronous mode + * call(s) to Logging API + */ + public void setLogbackBatchingSettings(LogbackBatchingSettings batchingSettings) { + logbackBatchingSettings = batchingSettings; + } + /** * Sets the flag indicating if a batch's valid entries should be written even if some other entry * failed due to an error. @@ -430,6 +458,8 @@ protected LoggingOptions getLoggingOptions() { } // opt-out metadata auto-population to control it in the appender code builder.setAutoPopulateMetadata(false); + builder.setBatchingSettings( + this.logbackBatchingSettings != null ? this.logbackBatchingSettings.build() : null); loggingOptions = builder.build(); } return loggingOptions; diff --git a/src/test/java/com/google/cloud/logging/logback/LoggingAppenderLogbackTest.java b/src/test/java/com/google/cloud/logging/logback/LoggingAppenderLogbackTest.java new file mode 100644 index 000000000..7691549e1 --- /dev/null +++ b/src/test/java/com/google/cloud/logging/logback/LoggingAppenderLogbackTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.logging.logback; + +import static com.google.common.truth.Truth.assertThat; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.joran.JoranConfigurator; +import ch.qos.logback.core.joran.spi.JoranException; +import com.google.api.gax.batching.FlowController.LimitExceededBehavior; +import com.google.cloud.logging.LoggingOptions; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LoggingAppenderLogbackTest { + @Test + public void testLoggingOptionsFromLogbackXMLFileConfig() throws JoranException { + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + JoranConfigurator jc = new JoranConfigurator(); + jc.setContext(context); + context.reset(); + jc.doConfigure("src/test/java/com/google/cloud/logging/logback/logback.xml"); + Logger logger = LoggerFactory.getLogger(LoggingAppenderLogbackTest.class); + assertThat(logger.getName()) + .isEqualTo("com.google.cloud.logging.logback.LoggingAppenderLogbackTest"); + LoggingAppender appender = (LoggingAppender) context.getLogger("ROOT").getAppender("CLOUD"); + LoggingOptions options = appender.getLoggingOptions(); + assertThat(options.getAutoPopulateMetadata()).isEqualTo(false); + assertThat(options.getBatchingSettings().getDelayThreshold().toMillis()).isEqualTo(500); + assertThat(options.getBatchingSettings().getElementCountThreshold()).isEqualTo(100); + assertThat(options.getBatchingSettings().getIsEnabled()).isEqualTo(true); + assertThat(options.getBatchingSettings().getRequestByteThreshold()).isEqualTo(1000); + assertThat(options.getBatchingSettings().getFlowControlSettings().getLimitExceededBehavior()) + .isEqualTo(LimitExceededBehavior.Ignore); + assertThat( + options.getBatchingSettings().getFlowControlSettings().getMaxOutstandingElementCount()) + .isEqualTo(10000); + assertThat( + options.getBatchingSettings().getFlowControlSettings().getMaxOutstandingRequestBytes()) + .isEqualTo(100000); + } +} diff --git a/src/test/java/com/google/cloud/logging/logback/logback.xml b/src/test/java/com/google/cloud/logging/logback/logback.xml new file mode 100644 index 000000000..d0ec77843 --- /dev/null +++ b/src/test/java/com/google/cloud/logging/logback/logback.xml @@ -0,0 +1,57 @@ + + + + + INFO + + + + application.log + + + WARN + + + SYNC + + + false + + + true + + + global + + + src/test/java/com/google/cloud/logging/logback/dummy-credentials.json + + + String + + + + + + true + + + + 100 + 1000 + 500 + 10000 + 100000 + Ignore + + + + + + + From 6758979c3e3abaf24a8bfd3eb3c6b7cf954b7913 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 12 Jan 2023 01:42:54 +0000 Subject: [PATCH 4/6] deps: update dependency com.google.cloud:google-cloud-logging to v3.14.1 (#980) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 166bb603a..a5e8e0e5a 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 1.2.11 5.1.0 1.1.3 - 3.14.0 + 3.14.1 1.7.36 1.10.1 From d179bf849fbe03234931d5d1484b2fbe43b7726b Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 12 Jan 2023 22:18:31 +0000 Subject: [PATCH 5/6] build(deps): update dependency org.apache.maven.plugins:maven-project-info-reports-plugin to v3.4.2 (#979) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a5e8e0e5a..53b4e49ca 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.4.1 + 3.4.2 From 1707ac9c8e75c053baacd46e0358eb50718c2832 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:58:31 -0800 Subject: [PATCH 6/6] chore(main): release 0.129.0 (#981) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ pom.xml | 2 +- samples/snapshot/pom.xml | 2 +- .../cloud/logging/logback/LoggingAppender.java | 2 +- versions.txt | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cafb9cc9..1e9d277e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Changelog +## [0.129.0](https://github.com/googleapis/java-logging-logback/compare/v0.128.10...v0.129.0) (2023-01-12) + + +### Features + +* Add support for batching configuration ([#977](https://github.com/googleapis/java-logging-logback/issues/977)) ([afbe09c](https://github.com/googleapis/java-logging-logback/commit/afbe09c62647bca8eb9aa51f5ab63a13396800f7)) + + +### Dependencies + +* Update dependency com.google.cloud:google-cloud-logging to v3.14.1 ([#980](https://github.com/googleapis/java-logging-logback/issues/980)) ([6758979](https://github.com/googleapis/java-logging-logback/commit/6758979c3e3abaf24a8bfd3eb3c6b7cf954b7913)) + ## [0.128.10](https://github.com/googleapis/java-logging-logback/compare/v0.128.9...v0.128.10) (2023-01-09) diff --git a/pom.xml b/pom.xml index 53b4e49ca..f81eab132 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 google-cloud-logging-logback - 0.129.11-alpha-SNAPSHOT + 0.130.0-alpha jar Google Cloud Logging Logback Appender https://github.com/googleapis/java-logging-logback diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 0c345d0e3..8da300213 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,7 +28,7 @@ com.google.cloud google-cloud-logging-logback - 0.129.11-alpha-SNAPSHOT + 0.130.0-alpha diff --git a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java index 3d88bceb0..53603481c 100644 --- a/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java +++ b/src/main/java/com/google/cloud/logging/logback/LoggingAppender.java @@ -122,7 +122,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase { // See // https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files // {x-version-update-start:google-cloud-logging-logback:current} - public static final String DEFAULT_INSTRUMENTATION_VERSION = "0.129.11-alpha-SNAPSHOT"; + public static final String DEFAULT_INSTRUMENTATION_VERSION = "0.130.0-alpha"; // {x-version-update-end} private static boolean instrumentationAdded = false; private static final Object instrumentationLock = new Object(); diff --git a/versions.txt b/versions.txt index 18dd74d40..9c5b766d2 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-logging-logback:0.129.10-alpha:0.129.11-alpha-SNAPSHOT +google-cloud-logging-logback:0.130.0-alpha:0.130.0-alpha