Class DriftAnalyzer

java.lang.Object
org.mockserver.mock.drift.DriftAnalyzer

public class DriftAnalyzer extends Object
Compares a real forwarded response against a matching stub expectation's configured response and emits DriftRecords for any structural discrepancies (status code, headers, JSON schema).
  • Constructor Details

    • DriftAnalyzer

      public DriftAnalyzer(DriftStore store)
  • Method Details

    • setSemanticExtension

      public void setSemanticExtension(SemanticDriftExtension extension)
      Set the optional semantic drift extension. When non-null and available, structural drift records are enriched with LLM-classified severity.
    • setResponseTimeThresholdMs

      public void setResponseTimeThresholdMs(long thresholdMs)
      Set the p95 response time threshold (in milliseconds) above which a PERFORMANCE drift record is emitted. Zero or negative disables.
    • getInstance

      public static DriftAnalyzer getInstance()
    • analyse

      public void analyse(Expectation expectation, HttpResponse realResponse)
      Analyse the real forwarded response against the expectation's stub response. If the expectation's action is not an HttpResponse (e.g. it is a forward action), this method is a no-op.
      Parameters:
      expectation - the matched expectation (may be null)
      realResponse - the response received from the upstream service (may be null)
    • checkPerformanceDrift

      public void checkPerformanceDrift(String expectationId, long responseTimeMs, long now)
      Check whether the p95 response time for the given expectation exceeds the configured threshold, and if so emit a PERFORMANCE drift record.
      Parameters:
      expectationId - the expectation to check
      responseTimeMs - the response time just observed (already recorded in PercentileTracker)
      now - the current epoch time in milliseconds