id: weaviate-class-population-canary-gate
namespace: company.team
description: |
Run a Weaviate GraphQL Aggregate meta count query against a class and
alert Slack when the object count drops below a minimum threshold. A
class that silently loses objects (a bad delete, a stalled ingest
pipeline, a wiped collection) still answers queries normally - this
canary is the check that would otherwise only surface as "why is RAG
returning nothing" days later.
triggers:
- id: periodic_population_check
type: io.kestra.plugin.core.trigger.Schedule
description: Check every 30 minutes - a bad delete or a stalled ingest pipeline
can drain a class well before a daily check would catch it. Shipped
disabled; enable it once weaviate_url/class_name point at a real instance
and a manual run has been verified.
cron: "*/30 * * * *"
disabled: true
inputs:
- id: weaviate_url
type: STRING
displayName: "Weaviate URL"
defaults: "http://localhost:8081"
description: Weaviate endpoint, scheme and host with port. The count is read
from its /v1/graphql REST endpoint.
- id: anonymous
type: BOOL
displayName: "Anonymous Access"
defaults: false
description: Set true for a Weaviate instance with anonymous access. When false
the request sends WEAVIATE_API_KEY as a bearer token.
- id: class_name
type: STRING
displayName: "Weaviate Class Name"
defaults: "Article"
description: Class (collection) audited via the GraphQL Aggregate meta count query.
- id: min_object_count
type: INT
displayName: "Minimum Object Count"
defaults: 1
description: Below this count, class_name counts as AT_RISK. Default of 1 makes
this an always-populated canary; raise it to catch a partial data loss on
a class that should always hold many more objects than that.
tasks:
- id: check_class_population
type: io.kestra.plugin.core.http.Request
description: "Runs { Aggregate { <class_name> { meta { count } } } } against
Weaviate's /v1/graphql endpoint. The Weaviate plugin's Query task
(plugin-weaviate 2.0+) lists and searches objects but does not run
aggregations, so the exact count comes from the REST API, as the plugin's
upgrade guide recommends. The count lands at
data.Aggregate.<class_name>[0].meta.count in the response body."
uri: "{{ inputs.weaviate_url }}/v1/graphql"
method: POST
contentType: application/json
headers:
Authorization: "{{ inputs.anonymous ? '' : 'Bearer ' ~ secret('WEAVIATE_API_KEY') }}"
body: |
{"query": "{ Aggregate { {{ inputs.class_name }} { meta { count } } } }"}
- id: fail_on_query_error
type: io.kestra.plugin.core.execution.Fail
description: Weaviate answers a GraphQL error (for example an undefined
class_name) with HTTP 200 and an error list instead of a count. Fail here
so that case reaches the errors block instead of reading as zero objects.
condition: "{{ fromJson(outputs.check_class_population.body) | jq('(.errors //
.error) != null') | first }}"
errorMessage: "Aggregate query on {{ inputs.class_name }} returned an error: {{
fromJson(outputs.check_class_population.body) | jq('(.errors //
.error)[0].message') | first }}"
- id: evaluate_population
type: io.kestra.plugin.core.flow.If
description: AT_RISK when the Aggregate count is below min_object_count,
including the all-the-way-to-zero case of a fully emptied class.
condition: "{{ (fromJson(outputs.check_class_population.body) |
jq('.data.Aggregate[] | .[0].meta.count') | first) >=
inputs.min_object_count }}"
then:
- id: log_population_healthy
type: io.kestra.plugin.core.log.Log
message: "HEALTHY: {{ inputs.class_name }} has {{
(fromJson(outputs.check_class_population.body) | jq('.data.Aggregate[]
| .[0].meta.count') | first) }} object(s), at or above the {{
inputs.min_object_count }} minimum."
else:
- id: alert_population_at_risk
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "There is no remediation task to run here by design: the Weaviate
plugin exposes BatchCreate, Delete, Query, and SchemaCreate - nothing
to reindex, restore, or backfill lost vector objects, so this branch
only ever alerts."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Weaviate population canary: AT_RISK. {{ inputs.class_name }} has {{ (fromJson(outputs.check_class_population.body) | jq('.data.Aggregate[] | .[0].meta.count') | first) }} object(s), below the {{ inputs.min_object_count }} minimum. Execution {{ execution.id }}."
}
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: Final status line for every run, independent of which branch fired,
so the execution history always shows the headline numbers.
message: "Population audit complete for {{ inputs.class_name }}. count={{
(fromJson(outputs.check_class_population.body) | jq('.data.Aggregate[] |
.[0].meta.count') | first) }}. minimum={{ inputs.min_object_count }}."
errors:
- id: alert_execution_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alert when the flow itself fails outright - an unreachable Weaviate
instance, a bad API key, or class_name not existing at all (the Aggregate
query errors on an undefined class rather than returning a zero count, and
fail_on_query_error turns that into a failure). This case is effectively
UNREACHABLE and must not read as "no risk" just because
evaluate_population never ran.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Weaviate population canary FAILED in execution {{ execution.id }} for class {{ inputs.class_name }}. The Aggregate query did not complete - the class may not exist, or the instance may be unreachable; investigate before trusting the last known population count."
}