googleapis / googleapis/google-cloud-java

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

Offen
#11,913 1 Kommentar 0 Reaktionen 1 zugewiesene Person Beansprucht von @cindy-peng Auf GitHub ansehen
api: logging priority: p3
Vorherrschende Sprache
Java
Sterne
2.1k
Forks
1.2k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
154

Beschreibung

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`.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.