/** * Start a stopwatch. * Time is accumulated if the stopwatch is already registered * * @param caller the caller to name this stopwatch with its class's simple name * * @return The stopwatch */ public static TimedPhase startTiming(Object caller) { return startTiming(caller.getClass().getSimpleName()); }
@Override public void filter(final ContainerRequestContext request) { RequestLog.startTiming("TestLogWrapper"); }
@Override public void filter(final ContainerRequestContext request) { RequestLog.startTiming("TestLogWrapper"); }
@Override public void filter(final ClientRequestContext request) { RequestLog.startTiming("TestLogWrapper"); }
@Override public void filter(final ClientRequestContext request) { RequestLog.startTiming("TestLogWrapper"); }
/** * Stop the most recent stopwatch and start this one. * Time is accumulated if the stopwatch is already registered. * * @param nextPhase the name of the stopwatch to be started * * @deprecated This method is too dependent on context that can be too easily changed by internal method calls. * Each timer should be explicitly started by {@link RequestLog#startTiming(String)} and stopped by * {@link RequestLog#stopTiming(String)} instead */ @Deprecated public static void switchTiming(String nextPhase) { stopMostRecentTimer(); startTiming(nextPhase); }
/** * Stop the request timer, start the response timer, and then invoke the failure callback code. * * @param error The error that caused the failure */ default void dispatch(Throwable error) { RequestLog.stopTiming(REQUEST_WORKFLOW_TIMER); RequestLog.startTiming(RESPONSE_WORKFLOW_TIMER); invoke(error); } }
@Override @Deprecated public Filter getQueryFilter() { try (TimedPhase timer = RequestLog.startTiming("BuildingDruidFilter")) { return filterBuilder.buildFilters(this.apiFilters); } catch (FilterBuilderException e) { LOG.debug(e.getMessage()); throw new BadApiRequestException(e); } }
/** * Intercept Client request and add start timestamp. * * @param request Request to intercept * * @throws IOException if there's a problem processing the request */ @Override public void filter(ClientRequestContext request) throws IOException { appendRequestId(request.getStringHeaders().getFirst(X_REQUEST_ID_HEADER)); RequestLog.startTiming(CLIENT_TOTAL_TIMER); request.setProperty(PROPERTY_NANOS, System.nanoTime()); }
@Override public void onThrowable(Throwable t) { RequestLog.restore(logCtx); RequestLog.stopTiming(timerName); if (outstanding.decrementAndGet() == 0) { RequestLog.startTiming(RESPONSE_WORKFLOW_TIMER); } exceptionMeter.mark(); LOG.error("druid {} request failed:", serviceConfig.getNameAndUrl(), t); failure.invoke(t); } });
/** * Stop the request timer, start the response timer, and then invoke the error callback code. * * @param statusCode Http status code of the error response * @param reasonPhrase The reason for the error. Often the status code description. * @param responseBody The body of the error response */ default void dispatch(int statusCode, String reasonPhrase, String responseBody) { RequestLog.stopTiming(REQUEST_WORKFLOW_TIMER); RequestLog.startTiming(RESPONSE_WORKFLOW_TIMER); invoke(statusCode, reasonPhrase, responseBody); } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { RequestLog.startTiming(this); MultivaluedMap<String, Object> headers = responseContext.getHeaders(); String origin = requestContext.getHeaderString("origin"); if (origin == null || "".equals(origin)) { headers.add("Access-Control-Allow-Origin", "*"); } else { headers.add("Access-Control-Allow-Origin", origin); } String requestedHeaders = requestContext.getHeaderString("access-control-request-headers"); // allow all requested headers headers.add("Access-Control-Allow-Headers", requestedHeaders == null ? "" : requestedHeaders); headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS, PUT, PATCH"); headers.add("Access-Control-Allow-Credentials", "true"); RequestLog.stopTiming(this); } }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { RequestLog.startTiming(this); String path = requestContext.getUriInfo().getAbsolutePath().getPath(); if (path.startsWith("/v1/data") || path.startsWith("/data")) { // See if we have any unhealthy checks Map<String, Result> unhealthyChecks = getUnhealthy(); StringBuilder debugMsgBuilder = builderErrorResponseBody(requestContext); if (!unhealthyChecks.keySet().isEmpty()) { unhealthyChecks.forEach((key, value) -> LOG.error("Healthcheck '{}' failed: {}", key, value)); RequestLog.stopTiming(this); debugMsgBuilder.insert(0, "Service is unhealthy. At least 1 healthcheck is failing\n"); requestContext.abortWith( Response.status(Status.SERVICE_UNAVAILABLE) .entity(debugMsgBuilder.toString()) .build() ); return; } } RequestLog.stopTiming(this); }
/** * Get the timezone for the request. * * @param timeZoneId String of the TimeZone ID * @param systemTimeZone TimeZone of the system to use if there is no timeZoneId * * @return the request's TimeZone */ protected DateTimeZone generateTimeZone(String timeZoneId, DateTimeZone systemTimeZone) { try (TimedPhase timer = RequestLog.startTiming("generatingTimeZone")) { if (timeZoneId == null) { return systemTimeZone; } try { return DateTimeZone.forID(timeZoneId); } catch (IllegalArgumentException ignored) { LOG.debug(INVALID_TIME_ZONE.logFormat(timeZoneId)); throw new BadApiRequestException(INVALID_TIME_ZONE.format(timeZoneId)); } } }
/** * Intercept the Container request to add length of request and a start timestamp. * * @param request Request to intercept * * @throws IOException if there's a problem processing the request */ @Override public void filter(ContainerRequestContext request) throws IOException { appendRequestId(request.getHeaders().getFirst(X_REQUEST_ID_HEADER)); RequestLog.startTiming(TOTAL_TIMER); try (TimedPhase timer = RequestLog.startTiming(this)) { RequestLog.record(new Preface(request)); // sets PROPERTY_REQ_LEN if content-length not defined lengthOfRequestEntity(request); // store start time to later calculate elapsed time request.setProperty(PROPERTY_NANOS, System.nanoTime()); } }
/** * Accept request and reply with webapp exception and a simple string message. * * @param uriInfo Information about the URL for the request */ @GET @Timed(name = "logTimed") @Metered(name = "logMetered") @ExceptionMetered(name = "logException") @Produces(MediaType.APPLICATION_JSON) @Path("/webbug") public void getFailWithWebAppException(@Context UriInfo uriInfo) { RequestLog.startTiming(this); try { Thread.sleep(200); throw new WebApplicationException( Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Oops! Web App Exception").build() ); } catch (InterruptedException ignore) { // Do nothing } }
/** * Accept request and reply with webapp exception and a simple string message. * * @param uriInfo Information about the URL for the request */ @GET @Timed(name = "logTimed") @Metered(name = "logMetered") @ExceptionMetered(name = "logException") @Produces(MediaType.APPLICATION_JSON) @Path("/webbug") public void getFailWithWebAppException(@Context UriInfo uriInfo) { RequestLog.startTiming(this); try { Thread.sleep(200); throw new WebApplicationException( Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Oops! Web App Exception").build() ); } catch (InterruptedException ignore) { // Do nothing } }
/** * Accept request and reply with a generic runtime exception and a simple string message. * * @param uriInfo Information about the URL for the request */ @GET @Timed(name = "logTimed") @Metered(name = "logMetered") @ExceptionMetered(name = "logException") @Produces(MediaType.APPLICATION_JSON) @Path("/genericbug") public void getFailWithRuntimeException(@Context UriInfo uriInfo) { RequestLog.startTiming(this); try { Thread.sleep(200); throw new RuntimeException("Oops! Generic Exception"); } catch (InterruptedException ignore) { // Do nothing } } }
/** * Accept request and reply with a generic runtime exception and a simple string message. * * @param uriInfo Information about the URL for the request */ @GET @Timed(name = "logTimed") @Metered(name = "logMetered") @ExceptionMetered(name = "logException") @Produces(MediaType.APPLICATION_JSON) @Path("/genericbug") public void getFailWithRuntimeException(@Context UriInfo uriInfo) { RequestLog.startTiming(this); try { Thread.sleep(200); throw new RuntimeException("Oops! Generic Exception"); } catch (InterruptedException ignore) { // Do nothing } } }
/** * Accept request and reply with OK. * * @param uriInfo Information about the URL for the request * @param asyncResponse The response object to send the final response to */ @GET @Timed(name = "logTimed") @Metered(name = "logMetered") @ExceptionMetered(name = "logException") @Produces(MediaType.APPLICATION_JSON) @Path("/log") public void getSucceed(@Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { RequestLog.startTiming(this); try { Thread.sleep(200); } catch (InterruptedException ignore) { // Do nothing } RequestLog.stopTiming(this); Response response = Response.status(Response.Status.OK).build(); asyncResponse.resume(response); }