googleapis / googleapis/google-cloud-java

[java-logging] Google Cloud Logging: ‎LoggingImpl::populateMetadata calls MonitoredResourceUtil::getResource, even when LogEntry contains a MonitoredResource

Ouverte
#11,913 1 commentaire 0 réactions 1 personne assignée Réclamée par @cindy-peng Voir sur GitHub
api: logging priority: p3
Langage dominant
Java
Étoiles
2.1k
Forks
1.2k
Merge moyen
1 j 23 h
PR mergées (30 j)
154

Description

This ticket is about the code [here](https://github.com/googleapis/java-logging/blob/main/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java#L810).

If you use the logging api, and specify the `MonitoredResource` in the`LogEntry` like so:
```java
var logEntry = LogEntry.newBuilder(jsonPayload)
.setDestination(destination)
.setSeverity(severity)
.setLogName(logName)
.setTimestamp(request.timestamp())
.setResource(monitoredResource)
.build();

logging.write(List.of(logEntry));
```

A new `MonitoredResource` will be constructed [here](https://github.com/googleapis/java-logging/blob/main/google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingImpl.java#L825). This can result in an HTTP-call (going through `MonitoredResourceUtil::detectResourceType` and `com.google.cloud.MetadataConfig#getAttribute`), which has a big performance impact.

A workaround is to change the above example to:
```java
var logEntry = LogEntry.newBuilder(jsonPayload)
.setDestination(destination)
.setSeverity(severity)
.setLogName(logName)
.setTimestamp(request.timestamp())
.setResource(monitoredResource)
.build();

logging.write(List.of(logEntry), Logging.WriteOption.resource(monitoredResource));
```

But this shouldn't be needed if the `LogEntry` has the `MonitoredResource`.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.