Skip to content

Logging refactor of JUL + monitored resource construction#1847

Merged
jabubake merged 32 commits intogoogleapis:masterfrom
jabubake:ja_logging_refactor
Apr 19, 2017
Merged

Logging refactor of JUL + monitored resource construction#1847
jabubake merged 32 commits intogoogleapis:masterfrom
jabubake:ja_logging_refactor

Conversation

@jabubake
Copy link
Copy Markdown
Contributor

@jabubake jabubake commented Apr 3, 2017

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

@jabubake jabubake added the api: logging Issues related to the Cloud Logging API. label Apr 3, 2017
@jabubake jabubake requested a review from pongad April 3, 2017 16:07
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 3, 2017
value = MetadataConfig.getInstanceId();
break;
case "cluster_name":
value = MetadataConfig.getClusterName();

This comment was marked as spam.

This comment was marked as spam.

jabubake added 2 commits April 3, 2017 10:21
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.

Copy link
Copy Markdown
Contributor

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some quick initial comments.

}
return null;
}
}

This comment was marked as spam.

*/

package com.google.cloud.logging;
/**

This comment was marked as spam.

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.

Copy link
Copy Markdown
Contributor

@michaelbausor michaelbausor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jabubake! I've just done an initial review - one thing is it looks like it would be good to run the Google Java formatter to clean up some of the indentation issues.

(cc @pongad who asked me to review)

// return null if can't determine
return null;
// return project id from metadata config
return MetadataConfig.getProjectId();

This comment was marked as spam.

}

String getLogName() {
return getProperty( logFileNameTag, "java.log");

This comment was marked as spam.

}
}


This comment was marked as spam.

private final List<Enhancer> enhancers;
private LoggingHelper loggingHelper;
private List<Enhancer> enhancers;
private ErrorHandler errorHandler;

This comment was marked as spam.


LoggingOptions loggingOptions = (options != null) ? options : LoggingOptions.getDefaultInstance();
if (options == null) {
options = LoggingOptions.getDefaultInstance();

This comment was marked as spam.

this.flushLevel = config.getFlushLevel();
String logName = firstNonNull(log, config.getLogName());

LoggingOptions loggingOptions = (options != null) ? options : LoggingOptions.getDefaultInstance();

This comment was marked as spam.

try {
logEntryBuilder = logEntryBuilderFor(record);
} catch (Exception ex) {
errorHandler.handleFormatError(ex);

This comment was marked as spam.

This comment was marked as spam.

loggingHelper.close();
}

public synchronized void setFlushLevel(Level level) {

This comment was marked as spam.

jabubake added 2 commits April 5, 2017 12:24
renaming helper -> service
@jabubake
Copy link
Copy Markdown
Contributor Author

jabubake commented Apr 5, 2017

@michaelbausor @garrettjonesgoogle ran the Google java formatter.
I renamed the class to LoggingService : its a wrapper class, if you have a preferred name suggestion, let me know.

@pongad
Copy link
Copy Markdown
Contributor

pongad commented Apr 6, 2017

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?

@meltsufin
Copy link
Copy Markdown
Member

@gregw PTAL

case "instance_id":
value = MetadataConfig.getInstanceId();
break;
case "cluster_name":

This comment was marked as spam.

break;
case "gce_instance":
labels = new String[] {"instance_id", "zone"};
break;

This comment was marked as spam.

*/
public class TraceEnhancer implements Enhancer {

private static final ThreadLocal<String> traceId = new ThreadLocal<>();

This comment was marked as spam.

package com.google.cloud.logging;

/** A Log Enhancer. Used to enhance the {@link LogEntry} */
public interface Enhancer {

This comment was marked as spam.

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.

return "gae_app_standard";
}
if (MetadataConfig.getInstanceId() != null) {
return "gce_instance";

This comment was marked as spam.

Copy link
Copy Markdown
Contributor

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

} catch (Exception e) {
// Ignore exceptions, they are propagated to the error manager.
}
}

This comment was marked as spam.

This comment was marked as spam.


public class MetadataConfig {

private static final String metadataUrl = "http://metadata/computeMetadata/v1/";

This comment was marked as spam.

This comment was marked as spam.

return getAttribute("instance/", attributeName);
}

private static String getAttribute(String prefix, String attributeName) {

This comment was marked as spam.

This comment was marked as spam.

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.

import com.google.cloud.ServiceOptions;
import com.google.common.base.Strings;

import java.util.*;

This comment was marked as spam.


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.

});
break;
for (LoggingEnhancer enhancer : enhancers) {
enhancer.enhanceLogEntry(builder);

This comment was marked as spam.

This comment was marked as spam.

import java.util.List;
import java.util.Set;

public class LoggingService {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


public synchronized void setFlushSeverity(Severity severity) {
flushSeverity = severity;
}

This comment was marked as spam.

This comment was marked as spam.

Copy link
Copy Markdown
Contributor

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@pongad pongad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The volatile makes sense to me. LGTM.

@jabubake
Copy link
Copy Markdown
Contributor Author

@gregw, I've addressed your comments, PTAL.

@meltsufin
Copy link
Copy Markdown
Member

@jabubake You might want to take a look at grpc-context as an alternative thread local to carry the trace id.

@jabubake
Copy link
Copy Markdown
Contributor Author

@meltsufin : will look into it. @garrettjonesgoogle recommends we do that it in a separate PR.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.08%) to 80.858% when pulling cca8fc4 on jabubake:ja_logging_refactor into 455f739 on GoogleCloudPlatform:master.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

LGTM

@jabubake jabubake merged commit 101e56e into googleapis:master Apr 19, 2017
@jabubake jabubake deleted the ja_logging_refactor branch April 19, 2017 00:02
@meltsufin
Copy link
Copy Markdown
Member

@jabubake and @garrettjonesgoogle thanks pulling this together! When can we expect a push to Maven?

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

We should have a release by the end of the week.

meltsufin pushed a commit that referenced this pull request Dec 22, 2025
#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]>
chingor13 pushed a commit that referenced this pull request Feb 24, 2026
…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
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 11, 2026
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]>
chingor13 pushed a commit that referenced this pull request Mar 12, 2026
…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
lqiu96 pushed a commit that referenced this pull request Mar 20, 2026
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
meltsufin pushed a commit that referenced this pull request Apr 29, 2026
…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>
meltsufin pushed a commit that referenced this pull request May 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: logging Issues related to the Cloud Logging API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants