googleapis / googleapis/google-cloud-java

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

Abierto
#11,913 1 comentario 0 reacciones 1 asignado Reclamado por @cindy-peng Ver en GitHub
api: logging priority: p3
Lenguaje dominante
Java
Estrellas
2.1k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
154

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.