googleapis / googleapis/google-cloud-java

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

Đang mở
#11,913 1 bình luận 0 reaction 1 người được giao Được @cindy-peng nhận Xem trên GitHub
api: logging priority: p3
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.