Interface PerfHook


public interface PerfHook
Hook interface for performance testing integration (e.g., Gatling).

Implementations receive HTTP request timing events and can report them to external performance testing frameworks.

The event lifecycle:

  1. getPerfEventName(io.karatelabs.http.HttpRequest, io.karatelabs.core.ScenarioRuntime) is called before HTTP request to get the name
  2. HTTP request executes with timing captured
  3. reportPerfEvent(io.karatelabs.core.PerfEvent) is called with the completed event

Events are "held" until the next HTTP request or scenario end, so that assertion failures after an HTTP request can be attributed to that request.

  • Method Details

    • getPerfEventName

      String getPerfEventName(HttpRequest request, ScenarioRuntime runtime)
      Get the name for a performance event based on the HTTP request.

      This is called before the request executes. The implementation can use URI patterns or custom logic to determine the name that will appear in performance reports.

      Parameters:
      request - the HTTP request about to be executed
      runtime - the scenario runtime context
      Returns:
      the name for this request in performance reports, or null to skip reporting
    • reportPerfEvent

      void reportPerfEvent(PerfEvent event)
      Report a completed performance event.

      Called after HTTP request completion (possibly with failure info added later). The event includes timing, status code, and any failure message.

      Parameters:
      event - the completed performance event
    • submit

      default void submit(Runnable task)
      Submit a task for execution in the performance framework's execution model.

      For Gatling, this ensures tasks run within Gatling's scheduler. Default implementation runs synchronously.

      Parameters:
      task - the task to execute
    • afterFeature

      default void afterFeature(FeatureResult result)
      Called after a feature completes execution.

      Allows the performance framework to perform cleanup or final reporting.

      Parameters:
      result - the feature execution result
    • pause

      default void pause(Number millis)
      Pause execution for the specified duration.

      For Gatling integration, this uses Gatling's non-blocking pause mechanism rather than Thread.sleep(), which is important for virtual user scaling.

      Parameters:
      millis - the pause duration in milliseconds