Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging refactor of JUL + monitored resource construction #1847

Merged
merged 32 commits into from
Apr 19, 2017

Conversation

jabubake
Copy link
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
@@ -174,6 +174,7 @@ public LoggingHandler(String log, LoggingOptions options, MonitoredResource moni
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
Member

@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
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
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
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
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
Member

@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
Member

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

Some last cleanup items.

version_id,
zone
}
appId("app_id"),

This comment was marked as spam.

/**
* Monitored resource construction utilities to detect resource type and add labels.
*/
abstract class MonitoredResourceUtil {

This comment was marked as spam.

This comment was marked as spam.

return Resource.global;
}

protected static List<LoggingEnhancer> getResourceEnhancers() {

This comment was marked as spam.

This comment was marked as spam.

import java.net.HttpURLConnection;
import java.net.URL;

public class MetadataConfig {

This comment was marked as spam.

This comment was marked as spam.


package com.google.cloud.logging;

public interface LoggingErrorHandler {

This comment was marked as spam.

import java.util.Set;

/** Configurable logging service with level-based flush and error handling */
public class LoggingService {

This comment was marked as spam.

This comment was marked as spam.

adding javadoc
visibilty update on MonitoredResourceUtil
switch (resourceType) {
case GaeAppFlex:
enhancers = new ArrayList<>();
enhancers.add(new TraceLoggingEnhancer());

This comment was marked as spam.

This comment was marked as spam.


List<LoggingEnhancer> loggingEnhancers = MonitoredResourceUtil.getResourceEnhancers();
if (loggingEnhancers != null) {
this.enhancers.addAll(loggingEnhancers);

This comment was marked as spam.

This comment was marked as spam.

@jabubake
Copy link
Contributor Author

@garrettjonesgoogle , @pongad : I've moved the flush functionality to LoggingImpl. PTAL.

writeLogEntries(logEntries, options);
for (LogEntry logEntry : logEntries) {
// flush pending writes if log severity at or above flush severity
if (logEntry.getSeverity().compareTo(flushSeverity) >= 0) {

This comment was marked as spam.

This comment was marked as spam.

Copy link
Member

@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
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
Contributor Author

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

@meltsufin
Copy link
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
Contributor Author

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

@coveralls
Copy link

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
Member

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
Member

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

@garrettjonesgoogle
Copy link
Member

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

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