id: wiremock-unmatched-request-and-journal-sentinel
namespace: company.team
description: |
Polls standalone WireMock admin endpoints on a schedule to detect unmatched
request contract drift from downstream services, monitors in-memory request
journal growth against capacity thresholds, dispatches Slack alerts, and
provides safe, non-destructive journal pruning to prevent JVM heap exhaustion.
triggers:
- id: periodic_journal_audit
type: io.kestra.plugin.core.trigger.Schedule
description: "Periodically audits WireMock request journals to detect API
contract drift and memory exhaustion risks. Shipped disabled by default;
enable once wiremock_host and wiremock_port point to a running WireMock
standalone instance."
cron: "*/15 * * * *"
disabled: true
inputs:
wiremock_host: "localhost"
wiremock_port: 8080
max_journal_capacity: 1000
auto_reset_journal: "false"
dry_run: "true"
inputs:
- id: wiremock_host
type: STRING
displayName: "WireMock Host"
defaults: "localhost"
description: "Hostname or IP address of the WireMock standalone instance."
- id: wiremock_port
type: INT
displayName: "WireMock Admin Port"
defaults: 8080
description: "HTTP port exposed by the WireMock standalone server for its admin
API (default: 8080)."
- id: max_journal_capacity
type: INT
displayName: "Max Journal Request Capacity"
defaults: 1000
description: "Maximum allowable recorded requests in the WireMock in-memory
journal before flagging capacity saturation risk."
- id: auto_reset_journal
type: STRING
displayName: "Auto Reset Journal"
defaults: "false"
description: "When set to 'true' and dry_run is 'false', automatically purges
the request log journal via DELETE /__admin/requests to reclaim memory
without removing stub mappings."
- id: dry_run
type: STRING
displayName: "Dry Run Mode"
defaults: "true"
description: "When set to 'true', suppresses active journal reset mutations and
logs dry-run audit messages instead."
tasks:
- id: probe_unmatched_requests
type: io.kestra.plugin.core.http.Request
description: "Queries WireMock Admin API for requests that did not match any
configured stub mapping, indicating contract drift or client
misconfiguration."
uri: "http://{{ inputs.wiremock_host }}:{{ inputs.wiremock_port
}}/__admin/requests/unmatched"
method: GET
headers:
Accept: "application/json"
options:
allowFailed: true
- id: probe_request_count
type: io.kestra.plugin.core.http.Request
description: "Fetches total recorded request count from WireMock in-memory
journal to assess memory consumption against capacity thresholds."
uri: "http://{{ inputs.wiremock_host }}:{{ inputs.wiremock_port
}}/__admin/requests/count"
method: GET
headers:
Accept: "application/json"
options:
allowFailed: true
- id: classify_journal_status
type: io.kestra.plugin.core.flow.Switch
description: "Evaluates probe results to classify state into
CONTRACT_DRIFT_DETECTED, JOURNAL_QUOTA_EXCEEDED, or HEALTHY."
value: >-
{% if (fromJson(outputs.probe_unmatched_requests.body).requests ?? []) |
length > 0 %} CONTRACT_DRIFT_DETECTED {% elif
(fromJson(outputs.probe_request_count.body).count ?? 0) >=
inputs.max_journal_capacity %} JOURNAL_QUOTA_EXCEEDED {% else %} HEALTHY
{% endif %}
cases:
CONTRACT_DRIFT_DETECTED:
- id: alert_contract_drift
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Dispatches critical Slack alert when client requests fail to match
any registered WireMock stub."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#api-alerts",
"text": ":warning: *WireMock API Contract Drift Detected*",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":warning: *WireMock API Contract Drift Detected*\n*Host:* `{{ inputs.wiremock_host }}:{{ inputs.wiremock_port }}`\n*Unmatched Requests:* `{{ (fromJson(outputs.probe_unmatched_requests.body).requests ?? []) | length }}`\n*Impact:* Downstream microservices or test suites are calling endpoints without valid stub mappings."
}
}
]
}
- id: evaluate_remediation_on_drift
type: io.kestra.plugin.core.flow.If
description: "Evaluates safety gate before resetting request journal following
contract drift alert."
condition: "{{ inputs.auto_reset_journal == 'true' and inputs.dry_run == 'false'
}}"
then:
- id: purge_journal_on_drift
type: io.kestra.plugin.core.http.Request
description: "Issues DELETE /__admin/requests to flush recorded request log
while strictly preserving all active stub definitions."
uri: "http://{{ inputs.wiremock_host }}:{{ inputs.wiremock_port
}}/__admin/requests"
method: DELETE
- id: log_purge_drift
type: io.kestra.plugin.core.log.Log
message: "WireMock request journal purged successfully following contract drift
alert."
else:
- id: log_dry_run_drift
type: io.kestra.plugin.core.log.Log
message: "Dry-run active or auto_reset_journal disabled: WireMock request
journal preserved for root cause triage."
JOURNAL_QUOTA_EXCEEDED:
- id: alert_journal_quota
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Dispatches warning Slack alert when recorded request journal
exceeds capacity threshold."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#api-alerts",
"text": ":chart_with_upwards_trend: *WireMock Journal Capacity Quota Exceeded*",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":chart_with_upwards_trend: *WireMock Journal Capacity Quota Exceeded*\n*Host:* `{{ inputs.wiremock_host }}:{{ inputs.wiremock_port }}`\n*Current Depth:* `{{ fromJson(outputs.probe_request_count.body).count ?? 0 }}` requests (Threshold: `{{ inputs.max_journal_capacity }}`)\n*Impact:* Unbounded in-memory request journaling threatens JVM heap exhaustion."
}
}
]
}
- id: evaluate_remediation_on_quota
type: io.kestra.plugin.core.flow.If
description: "Evaluates safety gate before resetting request journal following
capacity breach."
condition: "{{ inputs.auto_reset_journal == 'true' and inputs.dry_run == 'false'
}}"
then:
- id: purge_journal_on_quota
type: io.kestra.plugin.core.http.Request
description: "Issues DELETE /__admin/requests to flush accumulated request logs
and reclaim JVM heap memory."
uri: "http://{{ inputs.wiremock_host }}:{{ inputs.wiremock_port
}}/__admin/requests"
method: DELETE
- id: log_purge_quota
type: io.kestra.plugin.core.log.Log
message: "WireMock request journal purged successfully to enforce capacity
quota."
else:
- id: log_dry_run_quota
type: io.kestra.plugin.core.log.Log
message: "Dry-run active or auto_reset_journal disabled: request journal
preserved."
HEALTHY:
- id: log_healthy_state
type: io.kestra.plugin.core.log.Log
message: "WireMock journal healthy on {{ inputs.wiremock_host }}:{{
inputs.wiremock_port }}: 0 unmatched requests, {{
fromJson(outputs.probe_request_count.body).count ?? 0 }} total
recorded requests."
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: "Records audit completion timestamp, target instance, and final
journal depth for compliance lineage."
message: "WireMock sentinel audit completed for {{ inputs.wiremock_host }}:{{
inputs.wiremock_port }}."
errors:
- id: alert_sentinel_probe_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Dispatches out-of-band alert if WireMock admin API is unreachable
or returns an HTTP error."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#api-alerts",
"text": ":rotating_light: *WireMock Sentinel Probe Failure*",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":rotating_light: *WireMock Sentinel Probe Failure*\nFailed to probe WireMock Admin API at `http://{{ inputs.wiremock_host }}:{{ inputs.wiremock_port }}`. The standalone container may be down, network unreachable, or port misconfigured."
}
}
]
}