From 024b73d1d59fd68b1c24f662a7d2853ad863ab3d Mon Sep 17 00:00:00 2001 From: Simon Zeltser Date: Wed, 28 Oct 2020 12:40:07 -0700 Subject: [PATCH] test: fix list logs test flakiness (#301) * chore: debrand Cloud Logging library from Stackdriver * chore: add cdpe ops team to codeowners * fix: add monitored resource filter to flaky tests * fix: updated listlogs test for samples Co-authored-by: Jeff Ching --- .github/CODEOWNERS | 2 +- .readme-partials.yaml | 8 ++-- README.md | 24 +++++----- google-cloud-logging/pom.xml | 2 +- .../com/google/cloud/logging/LogEntry.java | 16 +++---- .../com/google/cloud/logging/Logging.java | 20 ++++----- .../google/cloud/logging/LoggingHandler.java | 40 ++++++++--------- .../google/cloud/logging/LoggingLevel.java | 6 +-- .../java/com/google/cloud/logging/Metric.java | 4 +- .../com/google/cloud/logging/MetricInfo.java | 4 +- .../java/com/google/cloud/logging/Sink.java | 2 +- .../com/google/cloud/logging/SinkInfo.java | 14 +++--- .../google/cloud/logging/Synchronicity.java | 6 +-- .../google/cloud/logging/package-info.java | 6 +-- .../cloud/logging/spi/v2/LoggingRpc.java | 6 +-- .../cloud/logging/testing/package-info.java | 2 +- .../google/cloud/logging/BaseSystemTest.java | 45 ++++++++++++++++--- .../cloud/logging/LoggingHandlerTest.java | 3 ++ .../cloud/logging/it/ITLoggingTest.java | 18 ++++++-- samples/snapshot/pom.xml | 2 +- .../java/com/example/logging/ListLogs.java | 16 +++++-- .../com/example/logging/QuickstartSample.java | 4 +- .../src/main/resources/logging.properties | 2 +- 23 files changed, 153 insertions(+), 99 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7b2a7ff16..050dc2bee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,4 +9,4 @@ **/*.java @googleapis/api-logging # The java-samples-reviewers team is the default owner for samples changes -samples/**/*.java @googleapis/java-samples-reviewers +samples/**/*.java @googleapis/java-samples-reviewers @googleapis/api-logging diff --git a/.readme-partials.yaml b/.readme-partials.yaml index d96ef9b4e..55b00cf14 100644 --- a/.readme-partials.yaml +++ b/.readme-partials.yaml @@ -1,6 +1,6 @@ custom_content: | #### Creating an authorized service object - To make authenticated requests to Stackdriver Logging, you must create a service object with + To make authenticated requests to Cloud Logging, you must create a service object with credentials. You can then make API calls by calling methods on the Logging service object. The simplest way to authenticate is to use [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). @@ -78,9 +78,9 @@ custom_content: | } ``` - #### Add a Stackdriver Logging handler to a logger + #### Add a Cloud Logging handler to a logger You can also register a `LoggingHandler` to a `java.util.logging.Logger` that publishes log entries - to Stackdriver Logging. Given the following logger: + to Cloud Logging. Given the following logger: ```java private final static Logger LOGGER = Logger.getLogger(MyClass.class.getName()); ``` @@ -88,7 +88,7 @@ custom_content: | ```java LoggingHandler.addHandler(LOGGER, new LoggingHandler()); ``` - After that, logs generated using `LOGGER` will be also directed to Stackdriver Logging. + After that, logs generated using `LOGGER` will be also directed to Cloud Logging. Notice that you can also register a `LoggingHandler` via the `logging.properties` configuration file. Adding, for instance, the following line: diff --git a/README.md b/README.md index 79d8d6509..0da797fbf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Google Stackdriver Logging Client for Java +# Google Cloud Logging Client for Java -Java idiomatic client for [Stackdriver Logging][product-docs]. +Java idiomatic client for [Cloud Logging][product-docs]. [![Maven][maven-version-image]][maven-version-link] ![Stability][stability-image] @@ -61,7 +61,7 @@ See the [Authentication][authentication] section in the base directory's README. ### Prerequisites -You will need a [Google Cloud Platform Console][developer-console] project with the Stackdriver Logging [API enabled][enable-api]. +You will need a [Google Cloud Platform Console][developer-console] project with the Cloud Logging [API enabled][enable-api]. [Follow these instructions][create-project] to get your project set up. You will also need to set up the local development environment by [installing the Google Cloud SDK][cloud-sdk] and running the following commands in command line: @@ -72,17 +72,17 @@ You will need a [Google Cloud Platform Console][developer-console] project with You'll need to obtain the `google-cloud-logging` library. See the [Quickstart](#quickstart) section to add `google-cloud-logging` as a dependency in your code. -## About Stackdriver Logging +## About Cloud Logging -[Stackdriver Logging][product-docs] allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud and Amazon Web Services. Using the BindPlane service, you can also collect this data from over 150 common application components, on-premises systems, and hybrid cloud systems. BindPlane is included with your Google Cloud project at no additional cost. +[Cloud Logging][product-docs] allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud and Amazon Web Services. Using the BindPlane service, you can also collect this data from over 150 common application components, on-premises systems, and hybrid cloud systems. BindPlane is included with your Google Cloud project at no additional cost. -See the [Stackdriver Logging client library docs][javadocs] to learn how to -use this Stackdriver Logging Client Library. +See the [Cloud Logging client library docs][javadocs] to learn how to +use this Cloud Logging Client Library. #### Creating an authorized service object -To make authenticated requests to Stackdriver Logging, you must create a service object with +To make authenticated requests to Cloud Logging, you must create a service object with credentials. You can then make API calls by calling methods on the Logging service object. The simplest way to authenticate is to use [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). @@ -160,9 +160,9 @@ while (entryIterator.hasNext()) { } ``` -#### Add a Stackdriver Logging handler to a logger +#### Add a Cloud Logging handler to a logger You can also register a `LoggingHandler` to a `java.util.logging.Logger` that publishes log entries -to Stackdriver Logging. Given the following logger: +to Cloud Logging. Given the following logger: ```java private final static Logger LOGGER = Logger.getLogger(MyClass.class.getName()); ``` @@ -170,7 +170,7 @@ You can register a `LoggingHandler` with the code: ```java LoggingHandler.addHandler(LOGGER, new LoggingHandler()); ``` -After that, logs generated using `LOGGER` will be also directed to Stackdriver Logging. +After that, logs generated using `LOGGER` will be also directed to Cloud Logging. Notice that you can also register a `LoggingHandler` via the `logging.properties` configuration file. Adding, for instance, the following line: @@ -209,7 +209,7 @@ To get help, follow the instructions in the [shared Troubleshooting document][tr ## Transport -Stackdriver Logging uses gRPC for the transport layer. +Cloud Logging uses gRPC for the transport layer. ## Java Versions diff --git a/google-cloud-logging/pom.xml b/google-cloud-logging/pom.xml index 6b4baf0fc..745e34c0a 100644 --- a/google-cloud-logging/pom.xml +++ b/google-cloud-logging/pom.xml @@ -7,7 +7,7 @@ jar Google Cloud Logging https://github.com/googleapis/java-logging - Java idiomatic client for Stackdriver Logging + Java idiomatic client for Cloud Logging com.google.cloud google-cloud-logging-parent diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java index f1ea52d9e..cf0848f02 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LogEntry.java @@ -32,12 +32,12 @@ import java.util.Objects; /** - * A Stackdriver Logging log entry. All log entries are represented via objects of this class. Log - * entries can have different type of payloads: an UTF-8 string (see {@link Payload.StringPayload}), - * a JSON object (see {@link Payload.JsonPayload}, or a protobuf object (see {@link - * Payload.ProtoPayload}). Entries can also store additional information about the operation or the - * HTTP request that generated the log (see {@link LogEntry#getOperation()} and {@link - * LogEntry#getHttpRequest()}, respectively). + * A Cloud Logging log entry. All log entries are represented via objects of this class. Log entries + * can have different type of payloads: an UTF-8 string (see {@link Payload.StringPayload}), a JSON + * object (see {@link Payload.JsonPayload}, or a protobuf object (see {@link Payload.ProtoPayload}). + * Entries can also store additional information about the operation or the HTTP request that + * generated the log (see {@link LogEntry#getOperation()} and {@link LogEntry#getHttpRequest()}, + * respectively). * * @see Log Entries and Logs */ @@ -139,7 +139,7 @@ public Builder setTimestamp(long timestamp) { return this; } - /** Sets the time the log entry was received by Stackdriver Logging. */ + /** Sets the time the log entry was received by Cloud Logging. */ public Builder setReceiveTimestamp(long receiveTimestamp) { this.receiveTimestamp = receiveTimestamp; return this; @@ -305,7 +305,7 @@ public Long getTimestamp() { return timestamp; } - /** Returns the time the log entry was received by Stackdriver Logging. */ + /** Returns the time the log entry was received by Cloud Logging. */ public Long getReceiveTimestamp() { return receiveTimestamp; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java index ede68fff9..151942df9 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Logging.java @@ -437,9 +437,9 @@ public static EntryListOption filter(String filter) { ApiFuture deleteLogAsync(String log); /** - * Lists the monitored resource descriptors used by Stackdriver Logging. This method returns a - * {@link Page} object that can be used to consume paginated results. Use {@link ListOption} to - * specify the page size or the page token from which to start listing resource descriptors. + * Lists the monitored resource descriptors used by Cloud Logging. This method returns a {@link + * Page} object that can be used to consume paginated results. Use {@link ListOption} to specify + * the page size or the page token from which to start listing resource descriptors. * *

Example of listing monitored resource descriptors, specifying the page size. * @@ -458,11 +458,11 @@ public static EntryListOption filter(String filter) { Page listMonitoredResourceDescriptors(ListOption... options); /** - * Sends a request for listing monitored resource descriptors used by Stackdriver Logging. This - * method returns a {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} - * returns an {@link AsyncPage} object that can be used to asynchronously handle paginated - * results. Use {@link ListOption} to specify the page size or the page token from which to start - * listing resource descriptors. + * Sends a request for listing monitored resource descriptors used by Cloud Logging. This method + * returns a {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns an + * {@link AsyncPage} object that can be used to asynchronously handle paginated results. Use + * {@link ListOption} to specify the page size or the page token from which to start listing + * resource descriptors. * *

Example of asynchronously listing monitored resource descriptors, specifying the page size. * @@ -678,8 +678,8 @@ ApiFuture> listMonitoredResourceDescripto void flush(); /** - * Sends a request to log entries to Stackdriver Logging. Use {@link WriteOption#logName(String)} - * to provide a log name for those entries that do not specify one. Use {@link + * Sends a request to log entries to Cloud Logging. Use {@link WriteOption#logName(String)} to + * provide a log name for those entries that do not specify one. Use {@link * WriteOption#resource(MonitoredResource)} to provide a monitored resource for those entries that * do not specify one. Use {@link WriteOption#labels(Map)} to provide some labels to be added to * every entry in {@code logEntries}. diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java index 776ff5ebd..76051cf72 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java @@ -35,14 +35,14 @@ import java.util.logging.SimpleFormatter; /** - * A logging handler that outputs logs generated with {@link java.util.logging.Logger} to - * Stackdriver Logging. + * A logging handler that outputs logs generated with {@link java.util.logging.Logger} to Cloud + * Logging. * *

Java logging levels (see {@link java.util.logging.Level}) are mapped to the following Google - * Stackdriver Logging severities: + * Cloud Logging severities: * - * - * + *
Java LevelStackdriver Logging Severity
+ * * * * @@ -53,9 +53,9 @@ *
Java LevelCloud Logging Severity
SEVEREERROR
WARNINGWARNING
INFOINFO
* *

Original Java logging levels are added as labels (with {@code levelName} and {@code - * levelValue} keys, respectively) to the corresponding Stackdriver Logging {@link LogEntry}. You - * can read entry labels using {@link LogEntry#getLabels()}. To use logging levels that correspond - * to Stackdriver Logging severities you can use {@link LoggingLevel}. + * levelValue} keys, respectively) to the corresponding Cloud Logging {@link LogEntry}. You can read + * entry labels using {@link LogEntry#getLabels()}. To use logging levels that correspond to Cloud + * Logging severities you can use {@link LoggingLevel}. * *

Configuration: By default each {@code LoggingHandler} is initialized using the * following {@code LogManager} configuration properties (that you can set in the {@code @@ -72,8 +72,8 @@ *

  • {@code com.google.cloud.logging.LoggingHandler.formatter} specifies the name of a {@link * Formatter} class to use (defaults to {@link SimpleFormatter}). *
  • {@code com.google.cloud.logging.LoggingHandler.flushLevel} specifies the flush log level. - * When a log with this level is published, logs are transmitted to the Stackdriver Logging - * service (defaults to {@link LoggingLevel#ERROR}). + * When a log with this level is published, logs are transmitted to the Cloud Logging service + * (defaults to {@link LoggingLevel#ERROR}). *
  • {@code com.google.cloud.logging.LoggingHandler.enhancers} specifies a comma separated list * of {@link LoggingEnhancer} classes. This handler will call each enhancer list whenever it * builds a {@link LogEntry} instance (defaults to empty list). @@ -81,7 +81,7 @@ * creating the default {@link MonitoredResource} (defaults to auto-detected resource type, * else "global"). *
  • {@code com.google.cloud.logging.Synchronicity} the synchronicity of the write method to use - * to write logs to the Stackdriver Logging service (defaults to {@link Synchronicity#ASYNC}). + * to write logs to the Cloud Logging service (defaults to {@link Synchronicity#ASYNC}). * * *

    To add a {@code LoggingHandler} to an existing {@link Logger} and be sure to avoid infinite @@ -105,7 +105,7 @@ public class LoggingHandler extends Handler { private volatile Logging logging; - // Logs with the same severity with the base could be more efficiently sent to Stackdriver. + // Logs with the same severity with the base could be more efficiently sent to Cloud. // Defaults to level of the handler or Level.FINEST if the handler is set to Level.ALL. // Currently there is no way to modify the base level, see // https://github.com/googleapis/google-cloud-java/issues/1740 . @@ -115,13 +115,13 @@ public class LoggingHandler extends Handler { private WriteOption[] defaultWriteOptions; - /** Creates an handler that publishes messages to Stackdriver Logging. */ + /** Creates an handler that publishes messages to Cloud Logging. */ public LoggingHandler() { this(null, null, null); } /** - * Creates a handler that publishes messages to Stackdriver Logging. + * Creates a handler that publishes messages to Cloud Logging. * * @param log the name of the log to which log entries are written */ @@ -130,20 +130,20 @@ public LoggingHandler(String log) { } /** - * Creates a handler that publishes messages to Stackdriver Logging. + * Creates a handler that publishes messages to Cloud Logging. * * @param log the name of the log to which log entries are written - * @param options options for the Stackdriver Logging service + * @param options options for the Cloud Logging service */ public LoggingHandler(String log, LoggingOptions options) { this(log, options, null); } /** - * Creates a handler that publishes messages to Stackdriver Logging. + * Creates a handler that publishes messages to Cloud Logging. * * @param log the name of the log to which log entries are written - * @param options options for the Stackdriver Logging service + * @param options options for the Cloud Logging service * @param monitoredResource the monitored resource to which log entries refer. If it is null then * a default resource is created based on the project ID and deployment environment. */ @@ -152,10 +152,10 @@ public LoggingHandler(String log, LoggingOptions options, MonitoredResource moni } /** - * Creates a handler that publishes messages to Stackdriver Logging. + * Creates a handler that publishes messages to Cloud Logging. * * @param log the name of the log to which log entries are written - * @param options options for the Stackdriver Logging service + * @param options options for the Cloud Logging service * @param monitoredResource the monitored resource to which log entries refer. If it is null then * a default resource is created based on the project ID and deployment environment. * @param enhancers List of {@link LoggingEnhancer} instances used to enhance any{@link LogEntry} diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java index 827a8ad74..b1c8c4f8a 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingLevel.java @@ -19,8 +19,8 @@ import java.util.logging.Level; /** - * This class adds some additional Java logging levels for Stackdriver Logging. Added levels fill in - * the gap between Java logging levels and Stackdriver Logging severities. + * This class adds some additional Java logging levels for Cloud Logging. Added levels fill in the + * gap between Java logging levels and Cloud Logging severities. * *

    Added levels in descending order are (between parenthesis the relation with Java logging * levels): @@ -85,7 +85,7 @@ private LoggingLevel(String name, int value, Severity severity) { this.severity = severity; } - /** Returns the Stackdriver Logging severity associated with this logging level. */ + /** Returns the Cloud Logging severity associated with this logging level. */ public Severity getSeverity() { return severity; } diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java index e2f7ddb18..cb0ebe791 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Metric.java @@ -26,8 +26,8 @@ import java.util.Objects; /** - * Stackdriver Logging metrics describe logs-based metric. The value of the metric is the number of - * log entries that match a logs filter (see {@link #getFilter()}). + * Cloud Logging metrics describe logs-based metric. The value of the metric is the number of log + * entries that match a logs filter (see {@link #getFilter()}). * *

    {@code Metric} adds a layer of service-related functionality over {@link MetricInfo}. Objects * of this class are immutable. To get a {@code Metric} object with the most recent information use diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java index 53ebb3334..9edc9abc2 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/MetricInfo.java @@ -24,8 +24,8 @@ import java.util.Objects; /** - * Stackdriver Logging metrics describe logs-based metric. The value of the metric is the number of - * log entries that match a logs filter (see {@link #getFilter()}). + * Cloud Logging metrics describe logs-based metric. The value of the metric is the number of log + * entries that match a logs filter (see {@link #getFilter()}). * * @see Logs-based Metrics * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java index 3eb85f9ab..3189ba251 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Sink.java @@ -26,7 +26,7 @@ import java.util.Objects; /** - * Stackdriver Logging sinks can be used to control the export of your logs. Each sink specifies the + * Cloud Logging sinks can be used to control the export of your logs. Each sink specifies the * export of a set of log entries to a certain destination. A sink consists of a name, unique to the * project, a filter for choosing the log entries to export and a destination for the log entries. * diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java index c265d4873..32baa78e9 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/SinkInfo.java @@ -26,7 +26,7 @@ import java.util.regex.Pattern; /** - * Stackdriver Logging sinks can be used to control the export of your logs. Each sink specifies the + * Cloud Logging sinks can be used to control the export of your logs. Each sink specifies the * export of a set of log entries to a certain destination. A sink consists of a name, unique to the * project, a filter for choosing the log entries to export and a destination for the log entries. * @@ -53,7 +53,7 @@ public abstract static class Destination implements Serializable { private final Type type; - /** Type of destination for Stackdriver Logging sink. */ + /** Type of destination for Cloud Logging sink. */ public enum Type { /** Specifies a Google Cloud Storage bucket as destination for the sink. */ BUCKET, @@ -455,8 +455,8 @@ static T fromPb(String destinationPb) { } /** - * Available log entry formats. Log entries can be written to Stackdriver Logging in either format - * and can be exported in either format. Version 2 is the preferred format. + * Available log entry formats. Log entries can be written to Cloud Logging in either format and + * can be exported in either format. Version 2 is the preferred format. */ public enum VersionFormat { V1(LogSink.VersionFormat.V1), @@ -512,7 +512,7 @@ public abstract static class Builder { * Sets an advanced logs filter. Only log entries matching that filter are exported. The filter * must be consistent with the log entry format specified with {@link * #setVersionFormat(VersionFormat)}, regardless of the format of the log entry that was - * originally written to Stackdriver Logging. Example (V2 format): {@code + * originally written to Cloud Logging. Example (V2 format): {@code * logName=projects/my-projectid/logs/syslog AND severity>=ERROR}. * * @see Advanced Log @@ -614,8 +614,8 @@ public T getDestination() { /** * Returns an advanced logs filter. Only log entries matching that filter are exported. The filter * must be consistent with the log entry format specified in {@link #getVersionFormat()}, - * regardless of the format of the log entry that wa originally written to Stackdriver Logging. - * Example (V2 format): {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}. + * regardless of the format of the log entry that wa originally written to Cloud Logging. Example + * (V2 format): {@code logName=projects/my-projectid/logs/syslog AND severity>=ERROR}. * * @see Advanced Log * Filters diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/Synchronicity.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/Synchronicity.java index bd704dfe6..65cc1222e 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/Synchronicity.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/Synchronicity.java @@ -17,9 +17,9 @@ package com.google.cloud.logging; /** - * Used to specify the behavior of write calls to the Stackdriver Logging service. Specifying SYNC - * will make synchronous calls; specifying ASYNC will make asynchronous calls. The default behavior - * is ASYNC. + * Used to specify the behavior of write calls to the Cloud Logging service. Specifying SYNC will + * make synchronous calls; specifying ASYNC will make asynchronous calls. The default behavior is + * ASYNC. */ public enum Synchronicity { SYNC, diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java index 037780ae2..6805da22d 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/package-info.java @@ -15,7 +15,7 @@ */ /** - * A client for Stackdriver Logging - Real-time log management and analysis. + * A client for Cloud Logging - Real-time log management and analysis. * *

    Here's a simple usage example for using google-cloud from Compute Engine/App Engine Flexible. * This example shows how to write and list log entries. For the complete source code see * *

    This second example shows how to use a {@link java.util.logging.Logger} to write log entries - * to Stackdriver Logging. The snippet installs a Stackdriver Logging handler using {@code + * to Cloud Logging. The snippet installs a Cloud Logging handler using {@code * LoggingHandler.addHandler(Logger, LoggingHandler)}. Notice that this could also be done through * the {@code logging.properties} file, adding the following line: * @@ -62,6 +62,6 @@ * logger.warning("test warning"); * } * - * @see Stackdriver Logging + * @see Cloud Logging */ package com.google.cloud.logging; diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingRpc.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingRpc.java index 5e72ab0c4..f198042bc 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingRpc.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/spi/v2/LoggingRpc.java @@ -96,9 +96,9 @@ public interface LoggingRpc extends AutoCloseable, ServiceRpc { ApiFuture delete(DeleteLogRequest request); /** - * Sends a request to write log entries to Stackdriver Logging. This method returns a {@code - * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a response object for - * the write operation. + * Sends a request to write log entries to Cloud Logging. This method returns a {@code ApiFuture} + * object to consume the result. {@link ApiFuture#get()} returns a response object for the write + * operation. * * @param request the request object containing all of the parameters for the API call */ diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java index 044ed2670..df5ee1b3f 100644 --- a/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java +++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/testing/package-info.java @@ -15,7 +15,7 @@ */ /** - * A testing helper for Stackdriver Logging. + * A testing helper for Cloud Logging. * *

    A simple usage example: * diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java index 20d77fdea..bf9b63b1f 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java @@ -17,6 +17,7 @@ package com.google.cloud.logging; import com.google.api.gax.paging.Page; +import com.google.cloud.MonitoredResource; import com.google.cloud.logging.testing.RemoteLoggingHelper; import com.google.common.collect.Iterators; import com.google.logging.v2.LogName; @@ -59,7 +60,7 @@ public static void afterClass() throws Exception { * Filters Documentation */ protected static String createEqualityFilter(String name, V value) { - return name + " = " + "\"" + value.toString() + "\""; + return name + "=" + "\"" + value.toString() + "\""; } /** @@ -74,19 +75,49 @@ protected static String createTimestampFilter(int hoursAgo) { return "timestamp>=\"" + RFC_3339.format(calendar.getTime()) + "\""; } - /** Helper to poll for logs until they are returned by the backend. */ - protected static Iterator waitForLogs(LogName logName) throws InterruptedException { - return waitForLogs(logName, 1); + protected static String appendResourceTypeFilter( + String currentFilter, MonitoredResource[] monitoredResources) { + StringBuilder filter = new StringBuilder(currentFilter); + if (monitoredResources != null && monitoredResources.length > 0) { + if (monitoredResources.length == 1) { + filter.append(" AND resource.type="); + filter.append(monitoredResources[0].getType()); + } else { + filter.append(" AND resource.type=("); + filter.append(monitoredResources[0].getType()); + + // OR between all monitored resources we search + for (int i = 1; i < monitoredResources.length; i++) { + filter.append(" OR "); + filter.append(monitoredResources[i].getType()); + } + filter.append(")"); + } + } + + return filter.toString(); } /** Helper to poll for logs until they are returned by the backend. */ - protected static Iterator waitForLogs(LogName logName, int minLogs) + protected static Iterator waitForLogs( + LogName logName, MonitoredResource[] monitoredResources, int minLogs) throws InterruptedException { - String filter = createEqualityFilter("logName", logName) + " AND " + createTimestampFilter(1); - Logging.EntryListOption[] options = {Logging.EntryListOption.filter(filter)}; + StringBuilder filter = new StringBuilder(); + filter.append(createTimestampFilter(1)); + filter.append(" AND "); + filter.append(createEqualityFilter("logName", logName)); + + String monitoredResourceFilter = + appendResourceTypeFilter(filter.toString(), monitoredResources); + + Logging.EntryListOption[] options = {Logging.EntryListOption.filter(monitoredResourceFilter)}; return waitForLogs(options, minLogs); } + protected static Iterator waitForLogs(LogName logName) throws InterruptedException { + return waitForLogs(logName, null, 1); + } + private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); protected static Iterator waitForLogs(Logging.EntryListOption[] options, int minLogs) diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java index 1a2390bf5..91a215fde 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java @@ -46,8 +46,10 @@ public class LoggingHandlerTest { private static final String LOG_NAME = "java.log"; private static final String MESSAGE = "message"; private static final String PROJECT = "project"; + private static final MonitoredResource DEFAULT_RESOURCE = MonitoredResource.of("global", ImmutableMap.of("project_id", PROJECT)); + private static final LogEntry FINEST_ENTRY = LogEntry.newBuilder(StringPayload.of(MESSAGE)) .setSeverity(Severity.DEBUG) @@ -153,6 +155,7 @@ public class LoggingHandlerTest { .setTrace("projects/projectId/traces/traceId") .setTimestamp(123456789L) .build(); + private static final String CONFIG_NAMESPACE = "com.google.cloud.logging.LoggingHandler"; private static final ImmutableMap CONFIG_MAP = ImmutableMap.builder() diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java index 4cefce9e3..6f8d26412 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java @@ -49,6 +49,13 @@ public class ITLoggingTest extends BaseSystemTest { private static final Payload.JsonPayload SECOND_PAYLOAD = Payload.JsonPayload.of(ImmutableMap.of("jsonKey", "jsonValue")); + private static final MonitoredResource GLOBAL_RESOURCE = + MonitoredResource.newBuilder("global").build(); + private static final MonitoredResource CLOUDSQL_RESOURCE = + MonitoredResource.newBuilder("cloudsql_database").build(); + private static final MonitoredResource[] MONITORED_RESOURCES_IN_TEST = + new MonitoredResource[] {GLOBAL_RESOURCE, CLOUDSQL_RESOURCE}; + @BeforeClass public static void insertLogs() { LogEntry firstEntry = @@ -56,7 +63,7 @@ public static void insertLogs() { .addLabel("key1", "value1") .setLogName(LOG_ID) .setHttpRequest(HttpRequest.newBuilder().setStatus(500).build()) - .setResource(MonitoredResource.newBuilder("global").build()) + .setResource(GLOBAL_RESOURCE) .build(); LogEntry secondEntry = @@ -64,7 +71,7 @@ public static void insertLogs() { .addLabel("key2", "value2") .setLogName(LOG_ID) .setOperation(Operation.of("operationId", "operationProducer")) - .setResource(MonitoredResource.newBuilder("cloudsql_database").build()) + .setResource(CLOUDSQL_RESOURCE) .build(); logging.write(ImmutableList.of(firstEntry)); logging.write(ImmutableList.of(secondEntry)); @@ -90,7 +97,7 @@ public void testListEntries() throws InterruptedException { LogName logName = LogName.ofProjectLogName(loggingOptions.getProjectId(), LOG_ID); // Find the log name and wait until we have at least 2 entries - Iterator iterator = waitForLogs(logName, 2); + Iterator iterator = waitForLogs(logName, MONITORED_RESOURCES_IN_TEST, 2); assertThat(iterator.hasNext()).isTrue(); LogEntry entry = iterator.next(); @@ -122,7 +129,10 @@ public void testSortedOrder() throws InterruptedException { LoggingOptions loggingOptions = logging.getOptions(); LogName logName = LogName.ofProjectLogName(loggingOptions.getProjectId(), LOG_ID); - String filter = createEqualityFilter("logName", logName) + " AND " + createTimestampFilter(1); + String tempFilter = + createTimestampFilter(1) + " AND " + createEqualityFilter("logName", logName); + String filter = appendResourceTypeFilter(tempFilter, MONITORED_RESOURCES_IN_TEST); + Logging.EntryListOption[] options = new Logging.EntryListOption[] { Logging.EntryListOption.filter(filter), diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 38eafca41..b526617b5 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -4,7 +4,7 @@ com.google.cloud logging-snapshot jar - Google Stackdriver Logging Snapshot Samples + Google Cloud Logging Snapshot Samples https://github.com/googleapis/java-logging