Ejemplo n.º 1
0
 @Override
 public void notify(ZuulFilter filter, ExecutionStatus status) {
   DynamicCounter.increment(
       METRIC_PREFIX + filter.getClass().getSimpleName(),
       "status",
       status.name(),
       "filtertype",
       filter.filterType());
 }
Ejemplo n.º 2
0
  /**
   * Processes an individual ZuulFilter. This method adds Debug information. Any uncaught Thowables
   * are caught by this method and converted to a ZuulException with a 500 status code.
   *
   * @param filter
   * @return the return value for that filter
   * @throws ZuulException
   */
  public Object processZuulFilter(ZuulFilter filter) throws ZuulException {

    RequestContext ctx = RequestContext.getCurrentContext();
    boolean bDebug = ctx.debugRouting();
    final String metricPrefix = "zuul.filter-";
    long execTime = 0;
    String filterName = "";
    try {
      long ltime = System.currentTimeMillis();
      filterName = filter.getClass().getSimpleName();

      RequestContext copy = null;
      Object o = null;
      Throwable t = null;

      if (bDebug) {
        Debug.addRoutingDebug(
            "Filter " + filter.filterType() + " " + filter.filterOrder() + " " + filterName);
        copy = ctx.copy();
      }

      ZuulFilterResult result = filter.runFilter();
      ExecutionStatus s = result.getStatus();
      execTime = System.currentTimeMillis() - ltime;

      switch (s) {
        case FAILED:
          t = result.getException();
          ctx.addFilterExecutionSummary(filterName, ExecutionStatus.FAILED.name(), execTime);
          break;
        case SUCCESS:
          o = result.getResult();
          ctx.addFilterExecutionSummary(filterName, ExecutionStatus.SUCCESS.name(), execTime);
          if (bDebug) {
            Debug.addRoutingDebug(
                "Filter {"
                    + filterName
                    + " TYPE:"
                    + filter.filterType()
                    + " ORDER:"
                    + filter.filterOrder()
                    + "} Execution time = "
                    + execTime
                    + "ms");
            Debug.compareContextState(filterName, copy);
          }
          break;
        default:
          break;
      }

      if (t != null) throw t;

      usageNotifier.notify(filter, s);
      return o;

    } catch (Throwable e) {
      if (bDebug) {
        Debug.addRoutingDebug(
            "Running Filter failed "
                + filterName
                + " type:"
                + filter.filterType()
                + " order:"
                + filter.filterOrder()
                + " "
                + e.getMessage());
      }
      usageNotifier.notify(filter, ExecutionStatus.FAILED);
      if (e instanceof ZuulException) {
        throw (ZuulException) e;
      } else {
        ZuulException ex =
            new ZuulException(
                e, "Filter threw Exception", 500, filter.filterType() + ":" + filterName);
        ctx.addFilterExecutionSummary(filterName, ExecutionStatus.FAILED.name(), execTime);
        throw ex;
      }
    }
  }