Logging refactor of JUL + monitored resource construction#1847
Logging refactor of JUL + monitored resource construction#1847jabubake merged 32 commits intogoogleapis:masterfrom
Conversation
TODO : tests
| value = MetadataConfig.getInstanceId(); | ||
| break; | ||
| case "cluster_name": | ||
| value = MetadataConfig.getClusterName(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
removing flush size config : needs to be better exposed in loggingoptions for control
| this.flushLevel = config.getFlushLevel(); | ||
| String logName = firstNonNull(log, config.getLogName()); | ||
|
|
||
| LoggingOptions loggingOptions = (options != null) ? options : LoggingOptions.getDefaultInstance(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
garrettjonesgoogle
left a comment
There was a problem hiding this comment.
Just some quick initial comments.
| } | ||
| return null; | ||
| } | ||
| } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
|
|
||
| package com.google.cloud.logging; | ||
| /** |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import static com.google.common.base.MoreObjects.firstNonNull; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| public class LoggingHelper { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // return null if can't determine | ||
| return null; | ||
| // return project id from metadata config | ||
| return MetadataConfig.getProjectId(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| String getLogName() { | ||
| return getProperty( logFileNameTag, "java.log"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| private final List<Enhancer> enhancers; | ||
| private LoggingHelper loggingHelper; | ||
| private List<Enhancer> enhancers; | ||
| private ErrorHandler errorHandler; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| LoggingOptions loggingOptions = (options != null) ? options : LoggingOptions.getDefaultInstance(); | ||
| if (options == null) { | ||
| options = LoggingOptions.getDefaultInstance(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| this.flushLevel = config.getFlushLevel(); | ||
| String logName = firstNonNull(log, config.getLogName()); | ||
|
|
||
| LoggingOptions loggingOptions = (options != null) ? options : LoggingOptions.getDefaultInstance(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| try { | ||
| logEntryBuilder = logEntryBuilderFor(record); | ||
| } catch (Exception ex) { | ||
| errorHandler.handleFormatError(ex); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| loggingHelper.close(); | ||
| } | ||
|
|
||
| public synchronized void setFlushLevel(Level level) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
renaming helper -> service
|
@michaelbausor @garrettjonesgoogle ran the Google java formatter. |
|
Codacy seems to be really mad at you, but the flushing code looks fine (at least not any worse than it was before 😆 ). Lots of unit test failures though, are you setting default properties correctly? |
|
@gregw PTAL |
| case "instance_id": | ||
| value = MetadataConfig.getInstanceId(); | ||
| break; | ||
| case "cluster_name": |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| break; | ||
| case "gce_instance": | ||
| labels = new String[] {"instance_id", "zone"}; | ||
| break; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| public class TraceEnhancer implements Enhancer { | ||
|
|
||
| private static final ThreadLocal<String> traceId = new ThreadLocal<>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| package com.google.cloud.logging; | ||
|
|
||
| /** A Log Enhancer. Used to enhance the {@link LogEntry} */ | ||
| public interface Enhancer { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import com.google.cloud.MonitoredResource; | ||
| import com.google.cloud.logging.Logging.WriteOption; | ||
| import com.google.common.util.concurrent.Uninterruptibles; | ||
| import java.util.*; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return "gae_app_standard"; | ||
| } | ||
| if (MetadataConfig.getInstanceId() != null) { | ||
| return "gce_instance"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
garrettjonesgoogle
left a comment
There was a problem hiding this comment.
I finally got a chance to complete a deep review.
| import com.google.common.base.Strings; | ||
| import java.util.List; | ||
|
|
||
| import java.util.*; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } catch (Exception e) { | ||
| // Ignore exceptions, they are propagated to the error manager. | ||
| } | ||
| } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| public class MetadataConfig { | ||
|
|
||
| private static final String metadataUrl = "http://metadata/computeMetadata/v1/"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return getAttribute("instance/", attributeName); | ||
| } | ||
|
|
||
| private static String getAttribute(String prefix, String attributeName) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| private static final String formatterTag = "formatter"; | ||
| private static final String synchronicityTag = "synchronicity"; | ||
| private static final String resourceTypeTag = "resourceType"; | ||
| private static final String enchancersTag = "enhancers"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import com.google.cloud.ServiceOptions; | ||
| import com.google.common.base.Strings; | ||
|
|
||
| import java.util.*; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| addToMap(map, Resource.gce_instance, Label.instance_id, Label.zone); | ||
|
|
||
| resourceTypeWithLabels = Collections.unmodifiableMap(map); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| }); | ||
| break; | ||
| for (LoggingEnhancer enhancer : enhancers) { | ||
| enhancer.enhanceLogEntry(builder); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| public class LoggingService { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| public synchronized void setFlushSeverity(Severity severity) { | ||
| flushSeverity = severity; | ||
| } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
garrettjonesgoogle
left a comment
There was a problem hiding this comment.
LGTM after my open question to @pongad is answered, and other people's feedback is addressed
| package com.google.cloud.logging; | ||
|
|
||
| /* | ||
| */ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
pongad
left a comment
There was a problem hiding this comment.
The volatile makes sense to me. LGTM.
|
@gregw, I've addressed your comments, PTAL. |
|
@jabubake You might want to take a look at |
|
@meltsufin : will look into it. @garrettjonesgoogle recommends we do that it in a separate PR. |
|
LGTM |
|
@jabubake and @garrettjonesgoogle thanks pulling this together! When can we expect a push to Maven? |
|
We should have a release by the end of the week. |
#1847) * chore: Update generation configuration at Wed Aug 6 02:42:06 UTC 2025 * chore: Update generation configuration at Thu Aug 7 02:41:33 UTC 2025 * chore: Update generation configuration at Fri Aug 8 02:40:44 UTC 2025 * chore: Update generation configuration at Sat Aug 9 02:31:48 UTC 2025 * chore: Update generation configuration at Sun Aug 10 02:43:08 UTC 2025 * chore: Update generation configuration at Mon Aug 11 02:41:33 UTC 2025 * chore: Update generation configuration at Tue Aug 12 02:31:18 UTC 2025 * chore: Update generation configuration at Wed Aug 13 02:31:58 UTC 2025 * chore: Update generation configuration at Thu Aug 14 05:52:20 UTC 2025 * chore: Update generation configuration at Fri Aug 15 02:34:46 UTC 2025 * chore: Update generation configuration at Sat Aug 16 02:30:28 UTC 2025 * chore: generate libraries at Sat Aug 16 02:31:03 UTC 2025 * chore: Update generation configuration at Wed Aug 20 02:30:01 UTC 2025 * chore: generate libraries at Wed Aug 20 02:30:31 UTC 2025 * chore: Update generation configuration at Thu Aug 21 02:29:14 UTC 2025 * chore: Update generation configuration at Fri Aug 22 02:30:19 UTC 2025 * chore: Update generation configuration at Sat Aug 23 02:27:53 UTC 2025 * chore: Update generation configuration at Tue Aug 26 02:29:37 UTC 2025 * chore: Update generation configuration at Wed Aug 27 02:28:43 UTC 2025 * chore: Update generation configuration at Thu Aug 28 02:27:37 UTC 2025 * chore: Update generation configuration at Fri Aug 29 02:29:06 UTC 2025 * chore: generate libraries at Fri Aug 29 02:29:32 UTC 2025 * chore: Update generation configuration at Sat Aug 30 02:25:09 UTC 2025 * chore: Update generation configuration at Wed Sep 3 02:24:33 UTC 2025 * chore: Update generation configuration at Thu Sep 4 02:25:23 UTC 2025 * chore: Update generation configuration at Fri Sep 5 02:26:27 UTC 2025 * chore: Update generation configuration at Sat Sep 6 02:25:42 UTC 2025 * chore: generate libraries at Sat Sep 6 02:26:13 UTC 2025 * chore: Update generation configuration at Tue Sep 9 02:27:36 UTC 2025 * chore: Update generation configuration at Wed Sep 10 02:25:35 UTC 2025 * chore: Update generation configuration at Thu Sep 11 02:27:53 UTC 2025 --------- Co-authored-by: Blake Li <[email protected]>
🤖 I have created a release *beep* *boop* --- ## [2.28.2](https://togithub.com/googleapis/java-datastore/compare/v2.28.1...v2.28.2) (2025-05-16) ### Dependencies * Update dependency com.google.cloud:sdk-platform-java-config to v3.48.0 ([#1847](https://togithub.com/googleapis/java-datastore/issues/1847)) ([7ed3232](https://togithub.com/googleapis/java-datastore/commit/7ed32321a5c84c4b2f61094e4c4adb5e36e5bc1b)) * Update googleapis/sdk-platform-java action to v2.58.0 ([#1853](https://togithub.com/googleapis/java-datastore/issues/1853)) ([eef820d](https://togithub.com/googleapis/java-datastore/commit/eef820d017f5e00245924d551abe172a2a39e29f)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
…ntials requests (#1847) * fix: Add configurable connect and read timeouts to STS requests * chore: Fix lint issues * chore: Add connect and read timeout to identity pool creds * chore: Propogate connect and read timeouts to all calls
googleapis#1847) * chore: Update generation configuration at Wed Aug 6 02:42:06 UTC 2025 * chore: Update generation configuration at Thu Aug 7 02:41:33 UTC 2025 * chore: Update generation configuration at Fri Aug 8 02:40:44 UTC 2025 * chore: Update generation configuration at Sat Aug 9 02:31:48 UTC 2025 * chore: Update generation configuration at Sun Aug 10 02:43:08 UTC 2025 * chore: Update generation configuration at Mon Aug 11 02:41:33 UTC 2025 * chore: Update generation configuration at Tue Aug 12 02:31:18 UTC 2025 * chore: Update generation configuration at Wed Aug 13 02:31:58 UTC 2025 * chore: Update generation configuration at Thu Aug 14 05:52:20 UTC 2025 * chore: Update generation configuration at Fri Aug 15 02:34:46 UTC 2025 * chore: Update generation configuration at Sat Aug 16 02:30:28 UTC 2025 * chore: generate libraries at Sat Aug 16 02:31:03 UTC 2025 * chore: Update generation configuration at Wed Aug 20 02:30:01 UTC 2025 * chore: generate libraries at Wed Aug 20 02:30:31 UTC 2025 * chore: Update generation configuration at Thu Aug 21 02:29:14 UTC 2025 * chore: Update generation configuration at Fri Aug 22 02:30:19 UTC 2025 * chore: Update generation configuration at Sat Aug 23 02:27:53 UTC 2025 * chore: Update generation configuration at Tue Aug 26 02:29:37 UTC 2025 * chore: Update generation configuration at Wed Aug 27 02:28:43 UTC 2025 * chore: Update generation configuration at Thu Aug 28 02:27:37 UTC 2025 * chore: Update generation configuration at Fri Aug 29 02:29:06 UTC 2025 * chore: generate libraries at Fri Aug 29 02:29:32 UTC 2025 * chore: Update generation configuration at Sat Aug 30 02:25:09 UTC 2025 * chore: Update generation configuration at Wed Sep 3 02:24:33 UTC 2025 * chore: Update generation configuration at Thu Sep 4 02:25:23 UTC 2025 * chore: Update generation configuration at Fri Sep 5 02:26:27 UTC 2025 * chore: Update generation configuration at Sat Sep 6 02:25:42 UTC 2025 * chore: generate libraries at Sat Sep 6 02:26:13 UTC 2025 * chore: Update generation configuration at Tue Sep 9 02:27:36 UTC 2025 * chore: Update generation configuration at Wed Sep 10 02:25:35 UTC 2025 * chore: Update generation configuration at Thu Sep 11 02:27:53 UTC 2025 --------- Co-authored-by: Blake Li <[email protected]>
…ntials requests (#1847) * fix: Add configurable connect and read timeouts to STS requests * chore: Fix lint issues * chore: Add connect and read timeout to identity pool creds * chore: Propogate connect and read timeouts to all calls
🤖 I have created a release *beep* *boop* --- ## [2.28.2](https://togithub.com/googleapis/java-datastore/compare/v2.28.1...v2.28.2) (2025-05-16) ### Dependencies * Update dependency com.google.cloud:sdk-platform-java-config to v3.48.0 ([#1847](https://togithub.com/googleapis/java-datastore/issues/1847)) ([bf4a27d](https://togithub.com/googleapis/java-datastore/commit/bf4a27de072d4fe803a14b945e5289932a0d7581)) * Update googleapis/sdk-platform-java action to v2.58.0 ([#1853](https://togithub.com/googleapis/java-datastore/issues/1853)) ([41f9a5d](https://togithub.com/googleapis/java-datastore/commit/41f9a5d9343ddc5a94e2cf598a05e1ef4650cb4d)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
…29.0 (#1847) * chore(deps): update dependency com.google.cloud:libraries-bom to v26.29.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
…29.0 (#1847) * chore(deps): update dependency com.google.cloud:libraries-bom to v26.29.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Auto detection of select resources to get JUL working across GCP environments and refactoring of code to help support more adapters like Slf4j.
Testing across GCP in progress.
See Issue #1654