-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
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
@@ -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.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
There was a problem hiding this 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.
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.
There was a problem hiding this 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.
This comment was marked as spam.
Sorry, something went wrong.
/** | ||
* 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return Resource.global; | ||
} | ||
|
||
protected static List<LoggingEnhancer> getResourceEnhancers() { |
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.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class MetadataConfig { |
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.
|
||
package com.google.cloud.logging; | ||
|
||
public interface LoggingErrorHandler { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
List<LoggingEnhancer> loggingEnhancers = MonitoredResourceUtil.getResourceEnhancers(); | ||
if (loggingEnhancers != null) { | ||
this.enhancers.addAll(loggingEnhancers); |
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 , @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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this 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.
@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. |
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