This repository was archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Issue #68 added request context scope * Issue #68 added request context scope * Issue #68 added skeleton Logging Handler * Issue #68 work in progress * Issue #68 work in progress * working implementation using a threadlocal to stop looping * Issue #68 update to latest google-cloud-java LoggingHandler * Issue #68 Updated to latest gcloud API removed copied LoggingHandlers removed instanceid from monitored resource * Issue #68 Use same labels as nginx * Issue #68 Code cleanups after review * Issue #68 Removed stackdriver logging, so this just configures JUL to capture the traceid and log to stderr * renamed traceid to traceId * gcloud api not currently used * Tunnel traceId in parameters #68 * Simplified with traceId lookup in formatter #68 * Use 8.2 beta stackdriver * Improved formatting * use logger name rather than source * run jetty from the webapp working directory so logging configuration may be relative * Testing logging Test googleapis/google-cloud-java#1535 and jetty-9.4.1-SNAPSHOT * use released 9.4.1 * Issue #68 minor clean ups * Do not CD to non existant directory * improved README * fixed Cloud SDK * Released beta of google-cloud-logging * updated google-cloud API to 0.8.3-beta * added remote test to check logging * Stackdriver logging testing improved comments check for traceid * upgrade to 0.9.2 * Test for zone * upgrade to 10.0 gcloud API * enable gae module only of GAE_INSTANCE environment variable is set * improved gae.mod documentation * GCP module Rename gae module and configuration to gcp Split the jetty.commands into jetty.commands and gcp.commands moved commands file to jetty-base/config-scripts updated setup-env-ext to run the gcp.commands when image is run with a GAE_INSTANCE set * fixed warnings * turn off stackdriver logging by default. Added instructions to enable. * Updates Update to latest openjdk-runtime with setup-env.d Update to latest jetty release * Use the PLATFORM env var * Improved jetty startup Added JETTY_PROPERTIES, JETTY_MODULES_ENABLE & JETTY_MODULES_DISABLE Removed duplicate code fron 50-jetty.bash * use launcher URL * Trimmed GCP specific configuration * Added structure tests for jetty setup script Also fixed unpack bug found as a result * Support passing just args * fix merge * Fixed test workspace paths for cloud build * review feedback * working directory is the root webapp * Improve handling of various types of command line. Fixed problem with handling of command line like "ls /var" Requires duplication of test for java from openjdk-runtime docker-entrypoint.bash, which should be modified to avoid the duplication. * upgrade cgloud API version to 0.13.0-beta * use package target * tested with FINE log level * Simplify entrypoint args processing The $@ arg array is kept complete between all scripts. * remove debug * remove debug * Test that the logging dependencies are hidden from webapp classpath * update README.md with instructions to keep INFO level on io.grpc.netty.level=INFO * Updated to lasted openjdk-runtime * fixed classloader test * fixed TODO * Update to jetty 9.4.5 and gcloud 1.0.1-SNAPSHOT * upgraded to gcloud-logging 1.0.1 * turn off debug * updated README for latest 1.0.1 gcloud-logging * update classpath exclusion \o/
- Loading branch information
Showing
21 changed files
with
496 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
jetty9-base/src/main/java/com/google/cloud/runtimes/jetty9/RequestContextScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.runtimes.jetty9; | ||
|
||
import com.google.cloud.logging.TraceLoggingEnhancer; | ||
|
||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.handler.ContextHandler; | ||
import org.eclipse.jetty.server.handler.ContextHandler.Context; | ||
import org.eclipse.jetty.server.handler.ContextHandler.ContextScopeListener; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* A Jetty {@link ContextScopeListener} that is called whenever | ||
* a container managed thread enters or exits the scope of a context and/or request. | ||
* Used to maintain {@link ThreadLocal} references to the current request and | ||
* Google traceID, primarily for logging. | ||
* @see TracingLogHandler | ||
*/ | ||
public class RequestContextScope implements ContextHandler.ContextScopeListener { | ||
static final Logger logger = Logger.getLogger(RequestContextScope.class.getName()); | ||
|
||
private static final String X_CLOUD_TRACE = "x-cloud-trace-context"; | ||
private static final ThreadLocal<Integer> contextDepth = new ThreadLocal<>(); | ||
|
||
@Override | ||
public void enterScope(Context context, Request request, Object reason) { | ||
if (logger.isLoggable(Level.FINE)) { | ||
logger.fine("enterScope " + context); | ||
} | ||
if (request != null) { | ||
Integer depth = contextDepth.get(); | ||
if (depth == null || depth.intValue() == 0) { | ||
depth = 1; | ||
String traceId = (String) request.getAttribute(X_CLOUD_TRACE); | ||
if (traceId == null) { | ||
traceId = request.getHeader(X_CLOUD_TRACE); | ||
if (traceId != null) { | ||
int slash = traceId.indexOf('/'); | ||
if (slash >= 0) { | ||
traceId = traceId.substring(0, slash); | ||
} | ||
request.setAttribute(X_CLOUD_TRACE, traceId); | ||
TraceLoggingEnhancer.setCurrentTraceId(traceId); | ||
} | ||
} else { | ||
depth = depth + 1; | ||
} | ||
contextDepth.set(depth); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void exitScope(Context context, Request request) { | ||
if (logger.isLoggable(Level.FINE)) { | ||
logger.fine("exitScope " + context); | ||
} | ||
Integer depth = contextDepth.get(); | ||
if (depth != null) { | ||
if (depth > 1) { | ||
contextDepth.set(depth - 1); | ||
} else { | ||
contextDepth.remove(); | ||
TraceLoggingEnhancer.setCurrentTraceId(null); | ||
} | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
jetty9-base/src/main/jetty-base/config-scripts/jetty.commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--create-startd | ||
|
||
--add-to-start=server,webapp,http,deploy,jsp,jstl,resources | ||
--approve-all-licenses | ||
--add-to-start=server,webapp,http,deploy,jsp,jstl,resources,logging-jul,jcl-slf4j | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
jetty9-base/src/main/jetty-base/etc/java-util-logging.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.level=INFO | ||
|
||
handlers=java.util.logging.ConsoleHandler | ||
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter | ||
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s%n | ||
|
||
## To use Stackdriver Logging replace the configuration above with the configuration below: | ||
# handlers=com.google.cloud.logging.LoggingHandler | ||
# com.google.cloud.logging.LoggingHandler.level=FINE | ||
# com.google.cloud.logging.LoggingHandler.log=gae_app.log | ||
# com.google.cloud.logging.LoggingHandler.resourceType=gae_app | ||
# com.google.cloud.logging.LoggingHandler.enhancers=com.google.cloud.logging.GaeFlexLoggingEnhancer | ||
# com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter | ||
# java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
jetty9-base/src/test/java/com/google/cloud/runtimes/jetty9/TestServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.runtimes.jetty9; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
|
||
@SuppressWarnings("serial") | ||
@WebServlet(urlPatterns = {"/", "/test/*"}, name = "TestServlet") | ||
public class TestServlet extends HttpServlet { | ||
static final Logger log = Logger.getLogger(TestServlet.class.getName()); | ||
|
||
@PostConstruct | ||
private void myPostConstructMethod() { | ||
log.info("preconstructed"); | ||
} | ||
|
||
@Override | ||
public void init() throws ServletException { | ||
log.info("init info"); | ||
getServletContext().log("init ServletContext.log"); | ||
} | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
log.info("doGet info"); | ||
getServletContext().log("doGet ServletContext.log"); | ||
|
||
if (request.getParameter("ex") != null) { | ||
try { | ||
throw (Throwable) Class.forName(request.getParameter("ex")).newInstance(); | ||
} catch (ServletException | IOException ex) { | ||
throw ex; | ||
} catch (Throwable th) { | ||
throw new ServletException(th); | ||
} | ||
} | ||
response.getWriter().println("Log Test"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.