googleapis / googleapis/google-cloud-java

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

オープン
#11,913 コメント 1 件 リアクション 0 件 担当者 1 名 @cindy-peng が担当を希望しています GitHub で見る
api: logging priority: p3
主要言語
Java
スター
2.1k
フォーク
1.2k
平均マージ
1日 23時間
マージ済み PR(30日)
154

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。