+ *
+ * @return the created metric
+ * @throws LoggingException upon failure
+ */
+ Metric create(MetricInfo metric);
+
+ /**
+ * Creates a new exclusion in a specified parent resource. Only log entries belonging to that
+ * resource can be excluded. You can have up to 10 exclusions in a resource.
+ *
+ *
Example of creating the exclusion:
+ *
+ *
+ * {
+ * @code
+ * String exclusionName = "my_exclusion_name";
+ * Exclusion exclusion = Exclusion.of(exclusionName,
+ * "resource.type=gcs_bucket severity
+ *
+ * @return the created exclusion
+ * @throws LoggingException upon failure
+ */
+ Exclusion create(Exclusion exclusion);
+
/**
* Sends a request for creating a sink. This method returns a {@code ApiFuture} object to consume
* the result. {@link ApiFuture#get()} returns the created sink.
@@ -359,6 +399,45 @@ public static TailOption project(String project) {
*/
ApiFuture createAsync(SinkInfo sink);
+ /**
+ * Sends a request for creating a metric. This method returns a {@code ApiFuture} object to
+ * consume the result. {@link ApiFuture#get()} returns the created metric.
+ *
+ *
Example of asynchronously creating a metric for logs with severity higher or equal to ERROR.
+ *
+ *
+ */
+ ApiFuture createAsync(MetricInfo metric);
+
+ /**
+ * Sends a request to create the exclusion. This method returns an {@code ApiFuture} object to
+ * consume the result. {@link ApiFuture#get()} returns the created exclusion.
+ *
+ *
Example of asynchronously creating the exclusion:
+ *
+ *
+ */
+ ApiFuture createAsync(Exclusion exclusion);
+
/**
* Updates a sink or creates one if it does not exist.
*
@@ -380,6 +459,47 @@ public static TailOption project(String project) {
*/
Sink update(SinkInfo sink);
+ /**
+ * Updates a metric or creates one if it does not exist.
+ *
+ *
+ *
+ * @return the created metric
+ * @throws LoggingException upon failure
+ */
+ Metric update(MetricInfo metric);
+
+ /**
+ * Updates one or more properties of an existing exclusion.
+ *
+ *
Example of updating the exclusion:
+ *
+ *
+ * {
+ * @code
+ * String exclusionName = "my_exclusion_name";
+ * Exclusion exclusion = Exclusion
+ * .newBuilder(exclusionName, "resource.type=gcs_bucket severity
+ *
+ * @return the updated exclusion
+ * @throws LoggingException upon failure
+ */
+ Exclusion update(Exclusion exclusion);
+
/**
* Sends a request for updating a sink (or creating it, if it does not exist). This method returns
* a {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns the
@@ -402,6 +522,49 @@ public static TailOption project(String project) {
*/
ApiFuture updateAsync(SinkInfo sink);
+ /**
+ * Sends a request for updating a metric (or creating it, if it does not exist). This method
+ * returns a {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns the
+ * updated/created metric or {@code null} if not found.
+ *
+ *
Example of asynchronously updating a metric.
+ *
+ *
+ */
+ ApiFuture updateAsync(MetricInfo metric);
+
+ /**
+ * Sends a request to change one or more properties of an existing exclusion. This method returns
+ * an {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns the updated
+ * exclusion or {@code null} if not found.
+ *
+ *
- *
- * @return the created metric
- * @throws LoggingException upon failure
- */
- Metric create(MetricInfo metric);
-
- /**
- * Sends a request for creating a metric. This method returns a {@code ApiFuture} object to
- * consume the result. {@link ApiFuture#get()} returns the created metric.
- *
- *
Example of asynchronously creating a metric for logs with severity higher or equal to ERROR.
- *
- *
- *
- * @return the created metric
- * @throws LoggingException upon failure
- */
- Metric update(MetricInfo metric);
-
- /**
- * Sends a request for updating a metric (or creating it, if it does not exist). This method
- * returns a {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns the
- * updated/created metric or {@code null} if not found.
- *
- *
Example of asynchronously updating a metric.
- *
- *
- */
- ApiFuture updateAsync(MetricInfo metric);
-
/**
* Returns the requested metric or {@code null} if not found.
*
@@ -948,47 +1032,6 @@ ApiFuture> listMonitoredResourceDescripto
*/
ApiFuture deleteMetricAsync(String metric);
- /**
- * Creates a new exclusion in a specified parent resource. Only log entries belonging to that
- * resource can be excluded. You can have up to 10 exclusions in a resource.
- *
- *
Example of creating the exclusion:
- *
- *
- * {
- * @code
- * String exclusionName = "my_exclusion_name";
- * Exclusion exclusion = Exclusion.of(exclusionName,
- * "resource.type=gcs_bucket severity
- *
- * @return the created exclusion
- * @throws LoggingException upon failure
- */
- Exclusion create(Exclusion exclusion);
-
- /**
- * Sends a request to create the exclusion. This method returns an {@code ApiFuture} object to
- * consume the result. {@link ApiFuture#get()} returns the created exclusion.
- *
- *
Example of asynchronously creating the exclusion:
- *
- *
- */
- ApiFuture createAsync(Exclusion exclusion);
-
/**
* Gets the description of an exclusion or {@code null} if not found.
*
@@ -1033,49 +1076,6 @@ ApiFuture> listMonitoredResourceDescripto
*/
ApiFuture getExclusionAsync(String exclusion);
- /**
- * Updates one or more properties of an existing exclusion.
- *
- *
Example of updating the exclusion:
- *
- *
- * {
- * @code
- * String exclusionName = "my_exclusion_name";
- * Exclusion exclusion = Exclusion
- * .newBuilder(exclusionName, "resource.type=gcs_bucket severity
- *
- * @return the updated exclusion
- * @throws LoggingException upon failure
- */
- Exclusion update(Exclusion exclusion);
-
- /**
- * Sends a request to change one or more properties of an existing exclusion. This method returns
- * an {@code ApiFuture} object to consume the result. {@link ApiFuture#get()} returns the updated
- * exclusion or {@code null} if not found.
- *
- *
- */
- ApiFuture updateAsync(Exclusion exclusion);
-
/**
* Deletes the requested exclusion.
*
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingConfig.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingConfig.java
index 199754b58..b53f6ed84 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingConfig.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingConfig.java
@@ -104,11 +104,9 @@ List getEnhancers() {
List enhancers = new ArrayList<>();
if (list != null) {
Iterable items = Splitter.on(',').split(list);
- for (String e_name : items) {
+ for (String eName : items) {
Class extends LoggingEnhancer> clazz =
- ClassLoader.getSystemClassLoader()
- .loadClass(e_name)
- .asSubclass(LoggingEnhancer.class);
+ ClassLoader.getSystemClassLoader().loadClass(eName).asSubclass(LoggingEnhancer.class);
enhancers.add(clazz.getDeclaredConstructor().newInstance());
}
}
@@ -135,6 +133,10 @@ private String getProperty(String name, String defaultValue) {
return firstNonNull(getProperty(name), defaultValue);
}
+ private String getProperty(String propertyName) {
+ return manager.getProperty(className + "." + propertyName);
+ }
+
private Boolean getBooleanProperty(String name, Boolean defaultValue) {
String flag = getProperty(name);
if (flag != null) {
@@ -181,8 +183,4 @@ private Formatter getFormatterProperty(String name, Formatter defaultValue) {
}
return defaultValue;
}
-
- private String getProperty(String propertyName) {
- return manager.getProperty(className + "." + propertyName);
- }
}
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 8acad5a41..07f9fcd9e 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
@@ -453,9 +453,9 @@ public Boolean getAutoPopulateMetadata() {
* the Json format that can be parsed by the logging agent. If set to {@code false}, logs will be
* ingested to Cloud Logging by calling Logging API.
*
- *
This method is mutually exclusive with {@link #setLogTarget()}.
+ *
This method is mutually exclusive with {@link #setLogTarget(LogTarget)}.
*
- * @deprecated Use {@link #setLogTarget()}.
+ * @deprecated Use {@link #setLogTarget(LogTarget)}.
*/
@Deprecated
public void setRedirectToStdout(boolean value) {
@@ -475,7 +475,7 @@ public Boolean getRedirectToStdout() {
* to the corresponding stream in the Json format that can be parsed by the logging agent. If set
* to CLOUD_LOGGING, logs will be sent directly to the Google Cloud Logging API.
*
- *
This method is mutually exclusive with {@link #setRedirectToStdout()}.
+ *
This method is mutually exclusive with {@link #setRedirectToStdout(boolean)}.
*/
public void setLogTarget(LogTarget value) {
this.logTarget = value;
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
index 56f52bee0..8c813feb1 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java
@@ -90,7 +90,9 @@
import com.google.protobuf.Empty;
import com.google.protobuf.util.Durations;
import java.text.ParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
@@ -287,6 +289,16 @@ public Sink create(SinkInfo sink) {
return get(createAsync(sink));
}
+ @Override
+ public Metric create(MetricInfo metric) {
+ return get(createAsync(metric));
+ }
+
+ @Override
+ public Exclusion create(Exclusion exclusion) {
+ return get(createAsync(exclusion));
+ }
+
@Override
public ApiFuture createAsync(SinkInfo sink) {
CreateSinkRequest request =
@@ -297,11 +309,41 @@ public ApiFuture createAsync(SinkInfo sink) {
return transform(rpc.create(request), Sink.fromPbFunction(this));
}
+ @Override
+ public ApiFuture createAsync(MetricInfo metric) {
+ CreateLogMetricRequest request =
+ CreateLogMetricRequest.newBuilder()
+ .setParent(ProjectName.of(getOptions().getProjectId()).toString())
+ .setMetric(metric.toPb())
+ .build();
+ return transform(rpc.create(request), Metric.fromPbFunction(this));
+ }
+
+ @Override
+ public ApiFuture createAsync(Exclusion exclusion) {
+ CreateExclusionRequest request =
+ CreateExclusionRequest.newBuilder()
+ .setParent(ProjectName.of(getOptions().getProjectId()).toString())
+ .setExclusion(exclusion.toProtobuf())
+ .build();
+ return transform(rpc.create(request), Exclusion.FROM_PROTOBUF_FUNCTION);
+ }
+
@Override
public Sink update(SinkInfo sink) {
return get(updateAsync(sink));
}
+ @Override
+ public Metric update(MetricInfo metric) {
+ return get(updateAsync(metric));
+ }
+
+ @Override
+ public Exclusion update(Exclusion exclusion) {
+ return get(updateAsync(exclusion));
+ }
+
@Override
public ApiFuture updateAsync(SinkInfo sink) {
UpdateSinkRequest request =
@@ -314,6 +356,28 @@ public ApiFuture updateAsync(SinkInfo sink) {
return transform(rpc.update(request), Sink.fromPbFunction(this));
}
+ @Override
+ public ApiFuture updateAsync(MetricInfo metric) {
+ UpdateLogMetricRequest request =
+ UpdateLogMetricRequest.newBuilder()
+ .setMetricName(
+ LogMetricName.of(getOptions().getProjectId(), metric.getName()).toString())
+ .setMetric(metric.toPb())
+ .build();
+ return transform(rpc.update(request), Metric.fromPbFunction(this));
+ }
+
+ @Override
+ public ApiFuture updateAsync(Exclusion exclusion) {
+ UpdateExclusionRequest request =
+ UpdateExclusionRequest.newBuilder()
+ .setName(
+ LogExclusionName.of(getOptions().getProjectId(), exclusion.getName()).toString())
+ .setExclusion(exclusion.toProtobuf())
+ .build();
+ return transform(rpc.update(request), Exclusion.FROM_PROTOBUF_FUNCTION);
+ }
+
@Override
public Sink getSink(String sink) {
return get(getSinkAsync(sink));
@@ -370,13 +434,13 @@ public AsyncPage apply(ListSinksResponse listSinksResponse) {
}
@Override
- public Page listSinks(ListOption... options) {
- return get(listSinksAsync(options));
+ public ApiFuture> listSinksAsync(ListOption... options) {
+ return listSinksAsync(getOptions(), optionMap(options));
}
@Override
- public ApiFuture> listSinksAsync(ListOption... options) {
- return listSinksAsync(getOptions(), optionMap(options));
+ public Page listSinks(ListOption... options) {
+ return get(listSinksAsync(options));
}
@Override
@@ -442,13 +506,13 @@ public AsyncPage apply(ListLogsResponse listLogsResponse) {
}
@Override
- public Page listLogs(ListOption... options) {
- return get(listLogsAsync(options));
+ public ApiFuture> listLogsAsync(ListOption... options) {
+ return listLogsAsync(getOptions(), optionMap(options));
}
@Override
- public ApiFuture> listLogsAsync(ListOption... options) {
- return listLogsAsync(getOptions(), optionMap(options));
+ public Page listLogs(ListOption... options) {
+ return get(listLogsAsync(options));
}
@Override
@@ -529,11 +593,6 @@ public AsyncPage apply(
});
}
- @Override
- public Page listMonitoredResourceDescriptors(ListOption... options) {
- return get(listMonitoredResourceDescriptorsAsync(options));
- }
-
@Override
public ApiFuture> listMonitoredResourceDescriptorsAsync(
ListOption... options) {
@@ -541,34 +600,8 @@ public ApiFuture> listMonitoredResourceDe
}
@Override
- public Metric create(MetricInfo metric) {
- return get(createAsync(metric));
- }
-
- @Override
- public ApiFuture createAsync(MetricInfo metric) {
- CreateLogMetricRequest request =
- CreateLogMetricRequest.newBuilder()
- .setParent(ProjectName.of(getOptions().getProjectId()).toString())
- .setMetric(metric.toPb())
- .build();
- return transform(rpc.create(request), Metric.fromPbFunction(this));
- }
-
- @Override
- public Metric update(MetricInfo metric) {
- return get(updateAsync(metric));
- }
-
- @Override
- public ApiFuture updateAsync(MetricInfo metric) {
- UpdateLogMetricRequest request =
- UpdateLogMetricRequest.newBuilder()
- .setMetricName(
- LogMetricName.of(getOptions().getProjectId(), metric.getName()).toString())
- .setMetric(metric.toPb())
- .build();
- return transform(rpc.update(request), Metric.fromPbFunction(this));
+ public Page listMonitoredResourceDescriptors(ListOption... options) {
+ return get(listMonitoredResourceDescriptorsAsync(options));
}
@Override
@@ -626,13 +659,13 @@ public AsyncPage apply(ListLogMetricsResponse listMetricsResponse) {
}
@Override
- public Page listMetrics(ListOption... options) {
- return get(listMetricsAsync(options));
+ public ApiFuture> listMetricsAsync(ListOption... options) {
+ return listMetricsAsync(getOptions(), optionMap(options));
}
@Override
- public ApiFuture> listMetricsAsync(ListOption... options) {
- return listMetricsAsync(getOptions(), optionMap(options));
+ public Page listMetrics(ListOption... options) {
+ return get(listMetricsAsync(options));
}
@Override
@@ -649,21 +682,6 @@ public ApiFuture deleteMetricAsync(String metric) {
return transform(rpc.delete(request), LoggingImpl::emptyToBooleanFunction);
}
- @Override
- public Exclusion create(Exclusion exclusion) {
- return get(createAsync(exclusion));
- }
-
- @Override
- public ApiFuture createAsync(Exclusion exclusion) {
- CreateExclusionRequest request =
- CreateExclusionRequest.newBuilder()
- .setParent(ProjectName.of(getOptions().getProjectId()).toString())
- .setExclusion(exclusion.toProtobuf())
- .build();
- return transform(rpc.create(request), Exclusion.FROM_PROTOBUF_FUNCTION);
- }
-
@Override
public Exclusion getExclusion(String exclusion) {
return get(getExclusionAsync(exclusion));
@@ -678,22 +696,6 @@ public ApiFuture getExclusionAsync(String exclusion) {
return transform(rpc.get(request), Exclusion.FROM_PROTOBUF_FUNCTION);
}
- @Override
- public Exclusion update(Exclusion exclusion) {
- return get(updateAsync(exclusion));
- }
-
- @Override
- public ApiFuture updateAsync(Exclusion exclusion) {
- UpdateExclusionRequest request =
- UpdateExclusionRequest.newBuilder()
- .setName(
- LogExclusionName.of(getOptions().getProjectId(), exclusion.getName()).toString())
- .setExclusion(exclusion.toProtobuf())
- .build();
- return transform(rpc.update(request), Exclusion.FROM_PROTOBUF_FUNCTION);
- }
-
@Override
public boolean deleteExclusion(String exclusion) {
return get(deleteExclusionAsync(exclusion));
@@ -926,7 +928,9 @@ public void flush() {
* setting.
*/
private void writeLogEntries(Iterable logEntries, WriteOption... writeOptions) {
- if (closed) return;
+ if (closed) {
+ return;
+ }
switch (this.writeSynchronicity) {
case SYNC:
@@ -1045,13 +1049,13 @@ public AsyncPage apply(ListLogEntriesResponse listLogEntriesResponse)
}
@Override
- public Page listLogEntries(EntryListOption... options) {
- return get(listLogEntriesAsync(options));
+ public ApiFuture> listLogEntriesAsync(EntryListOption... options) {
+ return listLogEntriesAsync(getOptions(), optionMap(options));
}
@Override
- public ApiFuture> listLogEntriesAsync(EntryListOption... options) {
- return listLogEntriesAsync(getOptions(), optionMap(options));
+ public Page listLogEntries(EntryListOption... options) {
+ return get(listLogEntriesAsync(options));
}
static TailLogEntriesRequest buildTailLogEntriesRequest(
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java
index 263d915c2..1f87e874f 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/MonitoredResourceUtil.java
@@ -66,12 +66,12 @@ String getKey() {
}
private enum Resource {
- CloudRun("cloud_run_revision"),
- CloudFunction("cloud_function"),
- AppEngine("gae_app"),
- GceInstance("gce_instance"),
- K8sContainer("k8s_container"),
- Global("global");
+ CLOUD_RUN("cloud_run_revision"),
+ CLOUD_FUNCTION("cloud_function"),
+ APP_ENGINE("gae_app"),
+ GCE_INSTANCE("gce_instance"),
+ K8S_CONTAINER("k8s_container"),
+ GLOBAL("global");
private final String key;
@@ -84,20 +84,20 @@ String getKey() {
}
}
- private static final ImmutableMultimap resourceTypeWithLabels =
+ private static final ImmutableMultimap RESOURCE_TYPE_WITH_LABELS =
ImmutableMultimap.builder()
- .putAll(Resource.CloudFunction.getKey(), Label.FunctionName, Label.Region)
+ .putAll(Resource.CLOUD_FUNCTION.getKey(), Label.FunctionName, Label.Region)
.putAll(
- Resource.CloudRun.getKey(),
+ Resource.CLOUD_RUN.getKey(),
Label.RevisionName,
Label.ServiceName,
Label.CloudRunLocation,
Label.ConfigurationName)
.putAll(
- Resource.AppEngine.getKey(), Label.ModuleId, Label.VersionId, Label.Zone, Label.Env)
- .putAll(Resource.GceInstance.getKey(), Label.InstanceId, Label.Zone)
+ Resource.APP_ENGINE.getKey(), Label.ModuleId, Label.VersionId, Label.Zone, Label.Env)
+ .putAll(Resource.GCE_INSTANCE.getKey(), Label.InstanceId, Label.Zone)
.putAll(
- Resource.K8sContainer.getKey(),
+ Resource.K8S_CONTAINER.getKey(),
Label.GKELocation,
Label.ClusterName,
Label.NamespaceName,
@@ -147,7 +147,7 @@ public static MonitoredResource getResource(String projectId, String resourceTyp
MonitoredResource.Builder builder =
MonitoredResource.newBuilder(resourceType).addLabel(Label.ProjectId.getKey(), projectId);
- for (Label label : resourceTypeWithLabels.get(resourceType)) {
+ for (Label label : RESOURCE_TYPE_WITH_LABELS.get(resourceType)) {
String value = metadataLoader.getValue(label);
if (value != null) {
builder.addLabel(label.getKey(), value);
@@ -165,33 +165,33 @@ public static MonitoredResource getResource(String projectId, String resourceTyp
private static Resource detectResourceType() {
// expects supported Google Cloud resource to have access to metadata server
if (getter.getAttribute("") == null) {
- return Resource.Global;
+ return Resource.GLOBAL;
}
if (getter.getEnv("FUNCTION_SIGNATURE_TYPE") != null
&& getter.getEnv("FUNCTION_TARGET") != null) {
- return Resource.CloudFunction;
+ return Resource.CLOUD_FUNCTION;
}
if (getter.getEnv("K_SERVICE") != null
&& getter.getEnv("K_REVISION") != null
&& getter.getEnv("K_CONFIGURATION") != null) {
- return Resource.CloudRun;
+ return Resource.CLOUD_RUN;
}
if (getter.getEnv("GAE_INSTANCE") != null
&& getter.getEnv("GAE_SERVICE") != null
&& getter.getEnv("GAE_VERSION") != null) {
- return Resource.AppEngine;
+ return Resource.APP_ENGINE;
}
if (getter.getAttribute("instance/attributes/cluster-name") != null) {
- return Resource.K8sContainer;
+ return Resource.K8S_CONTAINER;
}
if (getter.getAttribute("instance/preempted") != null
&& getter.getAttribute("instance/cpu-platform") != null
&& getter.getAttribute("instance/attributes/gae_app_bucket") == null) {
- return Resource.GceInstance;
+ return Resource.GCE_INSTANCE;
}
// other Google Cloud resources (e.g. CloudBuild) might be misdetected
- return Resource.Global;
+ return Resource.GLOBAL;
}
/**
@@ -206,7 +206,7 @@ public static List getResourceEnhancers() {
private static List createEnhancers(Resource resourceType) {
List enhancers = new ArrayList<>(2);
- if (resourceType == Resource.AppEngine) {
+ if (resourceType == Resource.APP_ENGINE) {
enhancers.add(new TraceLoggingEnhancer(APPENGINE_LABEL_PREFIX));
if (MetadataLoader.ENV_FLEXIBLE.equals(metadataLoader.getValue(Label.Env))) {
enhancers.add(
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetter.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetter.java
index 6469d39b5..4d33ad435 100644
--- a/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetter.java
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetter.java
@@ -16,9 +16,6 @@
package com.google.cloud.logging;
-import com.google.cloud.MetadataConfig;
-import org.jspecify.nullness.Nullable;
-
public interface ResourceTypeEnvironmentGetter {
/**
@@ -41,22 +38,3 @@ public interface ResourceTypeEnvironmentGetter {
*/
String getAttribute(String name);
}
-
-final class ResourceTypeEnvironmentGetterImpl implements ResourceTypeEnvironmentGetter {
-
- @Override
- public @Nullable String getEnv(String name) {
- // handle exception thrown if a security manager exists and blocks access to the
- // process environment
- try {
- return System.getenv(name);
- } catch (SecurityException ex) {
- return null;
- }
- }
-
- @Override
- public String getAttribute(String name) {
- return MetadataConfig.getAttribute(name);
- }
-}
diff --git a/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetterImpl.java b/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetterImpl.java
new file mode 100644
index 000000000..fd546aa88
--- /dev/null
+++ b/google-cloud-logging/src/main/java/com/google/cloud/logging/ResourceTypeEnvironmentGetterImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2021 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;
+
+import com.google.cloud.MetadataConfig;
+import org.jspecify.nullness.Nullable;
+
+final class ResourceTypeEnvironmentGetterImpl implements ResourceTypeEnvironmentGetter {
+
+ @Override
+ public @Nullable String getEnv(String name) {
+ // handle exception thrown if a security manager exists and blocks access to the
+ // process environment
+ try {
+ return System.getenv(name);
+ } catch (SecurityException ex) {
+ return null;
+ }
+ }
+
+ @Override
+ public String getAttribute(String name) {
+ return MetadataConfig.getAttribute(name);
+ }
+}
diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/InstrumentationTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/InstrumentationTest.java
index e1e00bc0a..e1aa67f48 100644
--- a/google-cloud-logging/src/test/java/com/google/cloud/logging/InstrumentationTest.java
+++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/InstrumentationTest.java
@@ -68,11 +68,11 @@ public void testNoInstrumentationGenerated() {
@Test
public void testInstrumentationUpdated() {
Instrumentation.setInstrumentationStatus(false);
- LogEntry json_entry =
+ LogEntry jsonEntry =
LogEntry.newBuilder(generateInstrumentationPayload(JAVA_OTHER_NAME, JAVA_OTHER_VERSION))
.build();
verifyEntries(
- Instrumentation.populateInstrumentationInfo(ImmutableList.of(json_entry)),
+ Instrumentation.populateInstrumentationInfo(ImmutableList.of(jsonEntry)),
0,
1,
new HashSet<>(Arrays.asList(Instrumentation.JAVA_LIBRARY_NAME_PREFIX, JAVA_OTHER_NAME)),
@@ -84,11 +84,11 @@ public void testInstrumentationUpdated() {
@Test
public void testInvalidInstrumentationRemoved() {
Instrumentation.setInstrumentationStatus(false);
- LogEntry json_entry =
+ LogEntry jsonEntry =
LogEntry.newBuilder(generateInstrumentationPayload(JAVA_INVALID_NAME, JAVA_OTHER_VERSION))
.build();
verifyEntries(
- Instrumentation.populateInstrumentationInfo(ImmutableList.of(json_entry)),
+ Instrumentation.populateInstrumentationInfo(ImmutableList.of(jsonEntry)),
0,
1,
new HashSet<>(Arrays.asList(Instrumentation.JAVA_LIBRARY_NAME_PREFIX)),
@@ -97,15 +97,15 @@ public void testInvalidInstrumentationRemoved() {
public static JsonPayload generateInstrumentationPayload(
String libraryName, String libraryVersion) {
- Map json_data = new HashMap<>();
- Map instrumentation_data = new HashMap<>();
+ Map jsonData = new HashMap<>();
+ Map instrumentationData = new HashMap<>();
Map info = new HashMap<>();
info.put(Instrumentation.INSTRUMENTATION_NAME_KEY, libraryName);
info.put(Instrumentation.INSTRUMENTATION_VERSION_KEY, libraryVersion);
ImmutableList