id: bigtable-row-write-freshness-sentinel
namespace: company.team
description: |
Read the most recent cell version written under a Bigtable row key
prefix, classify it FRESH, STALE, or NO_MATCHING_ROW, and alert Slack
when a writer (device, sensor, or ingestion pipeline) has stopped
updating a row it should be writing to continuously.
triggers:
- id: periodic_freshness_check
type: io.kestra.plugin.core.trigger.Schedule
description: "Checks every 15 minutes - a writer that has stalled on a
continuously-updated row key is usually worth catching well before a full
day passes. Shipped disabled; enable it once gcp_project_id,
bigtable_instance_id, and bigtable_table_id point at a real table and a
manual run has been verified."
cron: "*/15 * * * *"
disabled: true
inputs:
gcp_project_id: "<your-gcp-project-id>"
bigtable_instance_id: "my-instance"
bigtable_table_id: "sensor-readings"
row_key_prefix: "device-42#"
max_staleness_minutes: 30
bigtable_emulator_host: ""
inputs:
- id: gcp_project_id
type: STRING
displayName: "GCP Project ID"
defaults: "<your-gcp-project-id>"
description: "GCP project containing the Bigtable instance. Must be replaced
with a real project ID for production use - ignored entirely when
bigtable_emulator_host is set."
- id: bigtable_instance_id
type: STRING
displayName: "Bigtable Instance ID"
defaults: "my-instance"
description: "Bigtable instance ID, matching
io.kestra.plugin.gcp.bigtable.ReadRows's own documented example."
- id: bigtable_table_id
type: STRING
displayName: "Bigtable Table ID"
defaults: "sensor-readings"
description: "Table audited for write freshness, matching the plugin's own
documented example table name."
- id: row_key_prefix
type: STRING
displayName: "Row Key Prefix"
defaults: "device-42#"
description: "Row key prefix passed to ReadRows's own rowKeyPrefix property.
Must narrow to exactly one row for the freshness check below to be
meaningful - see Pitfalls."
- id: max_staleness_minutes
type: INT
displayName: "Max Acceptable Staleness (minutes)"
defaults: 30
description: "Above this many minutes since the row's most recent cell
timestamp, the result is classified STALE."
- id: bigtable_emulator_host
type: STRING
displayName: "Bigtable Emulator Host (local testing)"
defaults: ""
description: "host:port of a local Bigtable emulator, passed straight to
io.kestra.plugin.gcp.bigtable.ReadRows's own emulatorHost property. When
set, the task connects with no credentials at all (verified from the
plugin's own source). Leave empty for production use against real
Bigtable."
tasks:
- id: probe_latest_row
type: io.kestra.plugin.gcp.bigtable.ReadRows
description: "fetchType FETCH_ONE returns the single row with the
lexicographically smallest key matching row_key_prefix. Within that row,
Cloud Bigtable's own documented behavior returns cell versions
newest-first, so row.cells[0] is always the most recently written cell
regardless of how many versions exist."
projectId: "{{ inputs.gcp_project_id }}"
serviceAccount: "{{ secret('GCP_SERVICE_ACCOUNT_JSON') }}"
instanceId: "{{ inputs.bigtable_instance_id }}"
tableId: "{{ inputs.bigtable_table_id }}"
rowKeyPrefix: "{{ inputs.row_key_prefix }}"
emulatorHost: "{{ inputs.bigtable_emulator_host }}"
fetchType: FETCH_ONE
- id: evaluate_row_presence
type: io.kestra.plugin.core.flow.If
description: "NO_MATCHING_ROW when row_key_prefix matched nothing at all. Uses
rowCount > 0 and null check so a null row map cannot falsely evaluate as
defined and crash on cells[0]."
condition: "{{ outputs.probe_latest_row.rowCount > 0 and
outputs.probe_latest_row.row is not null }}"
then:
- id: evaluate_staleness
type: io.kestra.plugin.core.flow.If
description: "STALE when the most recent cell's timestamp is older than
max_staleness_minutes. Bigtable cell timestamps are documented as
microseconds since the Unix epoch, not milliseconds, hence the
division by 1,000,000 before converting to a date with jq's todate.
Both sides are compared as UTC ISO-8601 strings rather than raw epoch
math, since no verified Kestra Pebble filter returns the current time
as epoch microseconds or milliseconds - the same technique used in
this repository's Jenkins stuck-build-watchdog blueprint for an
analogous epoch-to-date comparison."
condition: "{{ (outputs.probe_latest_row.row.cells[0].timestamp | jq('. /
1000000 | todate') | first) < (now() | dateAdd(0 -
inputs.max_staleness_minutes, 'MINUTES') |
date(\"yyyy-MM-dd'T'HH:mm:ss'Z'\", timeZone='UTC')) }}"
then:
- id: alert_stale_row
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Always alert on STALE so an on-call engineer sees the stalled
writer without querying Bigtable by hand."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Bigtable row freshness sentinel: STALE. Row key prefix " ~ inputs.row_key_prefix ~ " in table " ~ inputs.bigtable_table_id ~ " last wrote a cell at " ~ (outputs.probe_latest_row.row.cells[0].timestamp | jq('. / 1000000 | todate') | first) ~ " UTC, past the " ~ inputs.max_staleness_minutes ~ " minute threshold. Execution " ~ execution.id ~ "."
} | toJson }}
else:
- id: log_row_fresh
type: io.kestra.plugin.core.log.Log
message: "FRESH: row key prefix {{ inputs.row_key_prefix }} last wrote a cell at
{{ outputs.probe_latest_row.row.cells[0].timestamp | jq('. /
1000000 | todate') | first }} UTC, within the {{
inputs.max_staleness_minutes }} minute threshold."
else:
- id: alert_no_matching_row
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "NO_MATCHING_ROW means row_key_prefix matched zero rows - the
writer may have never started, the row may have been deleted, or
row_key_prefix may be misconfigured. Alerted rather than only logged,
since this is a harder failure than a merely stale row."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Bigtable row freshness sentinel: NO_MATCHING_ROW. No row under prefix " ~ inputs.row_key_prefix ~ " in table " ~ inputs.bigtable_table_id ~ " was found at all. Execution " ~ execution.id ~ "."
} | toJson }}
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: "Final status line for every run, independent of which branch fired."
message: "Freshness audit complete for prefix {{ inputs.row_key_prefix }} in {{
inputs.bigtable_table_id }}. row_found={{
outputs.probe_latest_row.rowCount > 0 }}."
errors:
- id: alert_execution_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Alert when the flow itself fails outside the handled branches, for
example an unreachable Bigtable instance/emulator, a table that does not
exist, or invalid credentials."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Bigtable row freshness sentinel FAILED in execution " ~ execution.id ~ " for prefix " ~ inputs.row_key_prefix ~ " in table " ~ inputs.bigtable_table_id ~ ". The read did not complete; investigate before trusting the last known FRESH/STALE/NO_MATCHING_ROW status."
} | toJson }}