Class ValidationMetrics

java.lang.Object
ch.nexsol.gateway.validation.ValidationMetrics

public class ValidationMetrics extends Object
Counts what the validation filter sees, as plain Micrometer meters: the host application exports them to Prometheus, OpenTelemetry or anything else it already configures a registry for.

Every tag is drawn from a bounded set — the operations of a contract, the routes of the gateway, a fixed outcome — so the number of series stays proportional to the size of the configuration. The violations themselves are never tagged: they belong in the audit trail and the logs, not in a metric whose cardinality they would blow up.

A gateway with no MeterRegistry bean gets a no-op instance, so the filter works the same without the actuator on the classpath.

  • Field Details

    • VALIDATIONS

      public static final String VALIDATIONS
      Counter of the validated messages, tagged by direction, route, operation and outcome.
      See Also:
    • BODIES_SKIPPED

      public static final String BODIES_SKIPPED
      Counter of the bodies that were forwarded without being validated, tagged by the reason.
      See Also:
    • CONTRACTS_UNAVAILABLE

      public static final String CONTRACTS_UNAVAILABLE
      Counter of the exchanges forwarded without validation because their contract could not be read.
      See Also:
  • Constructor Details

    • ValidationMetrics

      public ValidationMetrics(io.micrometer.core.instrument.MeterRegistry registry)
      Creates the meters.
      Parameters:
      registry - the registry the meters are published to, or null to record nothing
  • Method Details

    • validated

      public void validated(String direction, String routeId, String operation, ValidationMode mode, boolean valid)
      Counts one validated message.
      Parameters:
      direction - request or response
      routeId - the route that handled the exchange
      operation - the contract operation, as METHOD /template
      mode - the mode the direction was validated in
      valid - whether the message honoured the contract
    • bodySkipped

      public void bodySkipped(String direction, String routeId, ValidationMetrics.SkipReason reason)
      Counts one body that was forwarded without being validated.
      Parameters:
      direction - request or response
      routeId - the route that handled the exchange
      reason - why the body was not validated
    • contractUnavailable

      public void contractUnavailable(String location)
      Counts one exchange forwarded because its contract could not be read.
      Parameters:
      location - the contract location