/** * Adds debug details about changes that a given filter made to the request context. * @param filterName * @param copy */ public static void compareContextState(String filterName, SessionContext context, SessionContext copy) { // TODO - only comparing Attributes. Need to compare the messages too. Iterator<String> it = context.keySet().iterator(); String key = it.next(); while (key != null) { if ((!key.equals("routingDebug") && !key.equals("requestDebug"))) { Object newValue = context.get(key); Object oldValue = copy.get(key); if (oldValue == null && newValue != null) { addRoutingDebug(context, "{" + filterName + "} added " + key + "=" + newValue.toString()); } else if (oldValue != null && newValue != null) { if (!(oldValue.equals(newValue))) { addRoutingDebug(context, "{" +filterName + "} changed " + key + "=" + newValue.toString()); } } } if (it.hasNext()) { key = it.next(); } else { key = null; } } }
protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) { // Add a log statement for this exception. final String errorMsg = "Filter Exception: filter=" + filter.filterName() + ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage()); if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) { LOG.warn(errorMsg); } else { LOG.error(errorMsg, t); } // Store this filter error for possible future use. But we still continue with next filter in the chain. final SessionContext zuulCtx = inMesg.getContext(); zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t)); if (zuulCtx.debugRouting()) { Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" + filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage()); } }
/** * Adds debug details about changes that a given filter made to the request context. * @param filterName * @param copy */ public static void compareContextState(String filterName, SessionContext context, SessionContext copy) { // TODO - only comparing Attributes. Need to compare the messages too. Iterator<String> it = context.keySet().iterator(); String key = it.next(); while (key != null) { if ((!key.equals("routingDebug") && !key.equals("requestDebug"))) { Object newValue = context.get(key); Object oldValue = copy.get(key); if (oldValue == null && newValue != null) { addRoutingDebug(context, "{" + filterName + "} added " + key + "=" + newValue.toString()); } else if (oldValue != null && newValue != null) { if (!(oldValue.equals(newValue))) { addRoutingDebug(context, "{" +filterName + "} changed " + key + "=" + newValue.toString()); } } } if (it.hasNext()) { key = it.next(); } else { key = null; } } }
@Test public void testRequestDebug() { assertFalse(debugRouting(ctx)); assertFalse(debugRequest(ctx)); setDebugRouting(ctx, true); setDebugRequest(ctx, true); assertTrue(debugRouting(ctx)); assertTrue(debugRequest(ctx)); addRoutingDebug(ctx, "test1"); assertTrue(getRoutingDebug(ctx).contains("test1")); addRequestDebug(ctx, "test2"); assertTrue(getRequestDebug(ctx).contains("test2")); }
protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) { // Add a log statement for this exception. final String errorMsg = "Filter Exception: filter=" + filter.filterName() + ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage()); if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) { LOG.warn(errorMsg); } else { LOG.error(errorMsg, t); } // Store this filter error for possible future use. But we still continue with next filter in the chain. final SessionContext zuulCtx = inMesg.getContext(); zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t)); if (zuulCtx.debugRouting()) { Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" + filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage()); } }
protected void recordFilterCompletion(final ExecutionStatus status, final ZuulFilter<I, O> filter, long startTime, final ZuulMessage zuulMesg, final ZuulMessage startSnapshot) { final SessionContext zuulCtx = zuulMesg.getContext(); final long execTime = System.currentTimeMillis() - startTime; if (execTime >= FILTER_EXCESSIVE_EXEC_TIME.get()) { LOG.warn("Filter {} took {} ms to complete! status = {}", filter.filterName(), execTime, status.name()); } // Record the execution summary in context. switch (status) { case FAILED: zuulCtx.addFilterExecutionSummary(filter.filterName(), FAILED.name(), execTime); break; case SUCCESS: zuulCtx.addFilterExecutionSummary(filter.filterName(), SUCCESS.name(), execTime); if (startSnapshot != null) { //debugRouting == true Debug.addRoutingDebug(zuulCtx, "Filter {" + filter.filterName() + " TYPE:" + filter.filterType().toString() + " ORDER:" + filter.filterOrder() + "} Execution time = " + execTime + "ms"); Debug.compareContextState(filter.filterName(), zuulCtx, startSnapshot.getContext()); } break; default: break; } LOG.debug("Filter {} completed with status {}, UUID {}", filter.filterName(), status.name(), zuulMesg.getContext().getUUID()); // Notify configured listener. usageNotifier.notify(filter, status); }
@Test public void testRequestDebug() { assertFalse(debugRouting(ctx)); assertFalse(debugRequest(ctx)); setDebugRouting(ctx, true); setDebugRequest(ctx, true); assertTrue(debugRouting(ctx)); assertTrue(debugRequest(ctx)); addRoutingDebug(ctx, "test1"); assertTrue(getRoutingDebug(ctx).contains("test1")); addRequestDebug(ctx, "test2"); assertTrue(getRequestDebug(ctx).contains("test2")); }
Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());
protected void recordFilterCompletion(final ExecutionStatus status, final ZuulFilter<I, O> filter, long startTime, final ZuulMessage zuulMesg, final ZuulMessage startSnapshot) { final SessionContext zuulCtx = zuulMesg.getContext(); final long execTime = System.currentTimeMillis() - startTime; if (execTime >= FILTER_EXCESSIVE_EXEC_TIME.get()) { LOG.warn("Filter {} took {} ms to complete! status = {}", filter.filterName(), execTime, status.name()); } // Record the execution summary in context. switch (status) { case FAILED: zuulCtx.addFilterExecutionSummary(filter.filterName(), FAILED.name(), execTime); break; case SUCCESS: zuulCtx.addFilterExecutionSummary(filter.filterName(), SUCCESS.name(), execTime); if (startSnapshot != null) { //debugRouting == true Debug.addRoutingDebug(zuulCtx, "Filter {" + filter.filterName() + " TYPE:" + filter.filterType().toString() + " ORDER:" + filter.filterOrder() + "} Execution time = " + execTime + "ms"); Debug.compareContextState(filter.filterName(), zuulCtx, startSnapshot.getContext()); } break; default: break; } LOG.debug("Filter {} completed with status {}, UUID {}", filter.filterName(), status.name(), zuulMesg.getContext().getUUID()); // Notify configured listener. usageNotifier.notify(filter, status); }
Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());
/** * Adds debug details about changes that a given filter made to the request context. * @param filterName * @param copy */ public static void compareContextState(String filterName, SessionContext context, SessionContext copy) { // TODO - only comparing Attributes. Need to compare the messages too. Iterator<String> it = context.keySet().iterator(); String key = it.next(); while (key != null) { if ((!key.equals("routingDebug") && !key.equals("requestDebug"))) { Object newValue = context.get(key); Object oldValue = copy.get(key); if (oldValue == null && newValue != null) { addRoutingDebug(context, "{" + filterName + "} added " + key + "=" + newValue.toString()); } else if (oldValue != null && newValue != null) { if (!(oldValue.equals(newValue))) { addRoutingDebug(context, "{" +filterName + "} changed " + key + "=" + newValue.toString()); } } } if (it.hasNext()) { key = it.next(); } else { key = null; } } }
protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) { // Add a log statement for this exception. final String errorMsg = "Filter Exception: filter=" + filter.filterName() + ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage()); if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) { LOG.warn(errorMsg); } else { LOG.error(errorMsg, t); } // Store this filter error for possible future use. But we still continue with next filter in the chain. final SessionContext zuulCtx = inMesg.getContext(); zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t)); if (zuulCtx.debugRouting()) { Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" + filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage()); } }
@Test public void testRequestDebug() { assertFalse(debugRouting(ctx)); assertFalse(debugRequest(ctx)); setDebugRouting(ctx, true); setDebugRequest(ctx, true); assertTrue(debugRouting(ctx)); assertTrue(debugRequest(ctx)); addRoutingDebug(ctx, "test1"); assertTrue(getRoutingDebug(ctx).contains("test1")); addRequestDebug(ctx, "test2"); assertTrue(getRequestDebug(ctx).contains("test2")); }
protected void recordFilterCompletion(final ExecutionStatus status, final ZuulFilter<I, O> filter, long startTime, final ZuulMessage zuulMesg, final ZuulMessage startSnapshot) { final SessionContext zuulCtx = zuulMesg.getContext(); final long execTime = System.currentTimeMillis() - startTime; // Record the execution summary in context. switch (status) { case FAILED: zuulCtx.addFilterExecutionSummary(filter.filterName(), FAILED.name(), execTime); break; case SUCCESS: zuulCtx.addFilterExecutionSummary(filter.filterName(), SUCCESS.name(), execTime); if (startSnapshot != null) { //debugRouting == true Debug.addRoutingDebug(zuulCtx, "Filter {" + filter.filterName() + " TYPE:" + filter.filterType().toString() + " ORDER:" + filter.filterOrder() + "} Execution time = " + execTime + "ms"); Debug.compareContextState(filter.filterName(), zuulCtx, startSnapshot.getContext()); } break; default: break; } LOG.debug("Filter {} completed with status {}, UUID {}", filter.filterName(), status.name(), zuulMesg.getContext().getUUID()); // Notify configured listener. usageNotifier.notify(filter, status); }
Debug.addRoutingDebug(inMesg.getContext(), "Filter " + filter.filterType().toString() + " " + filter.filterOrder() + " " + filter.filterName());