id: starrocks-materialized-view-refresh-and-drift-guard
namespace: company.data
concurrency:
limit: 1
behavior: CANCEL
description: Audit StarRocks asynchronous materialized views across schemas,
detect failed refreshes and inactive states, alert on Slack, pause for
operator approval, and trigger targeted refreshes with post-remediation
verification.
inputs:
- id: jdbc_url
type: STRING
description: JDBC connection URL for the StarRocks Frontend (FE) query port
(default 9030).
defaults: "jdbc:mysql://starrocks-fe:9030/"
- id: database_name
type: STRING
description: Target StarRocks database schema containing the asynchronous
materialized views to audit.
defaults: "analytics"
- id: slack_channel
type: STRING
description: Slack notification channel for incident alerts and triage notifications.
defaults: "#data-ops"
- id: dry_run
type: BOOL
description: When true, audits degraded materialized views without issuing
state-modifying ALTER or REFRESH statements.
defaults: false
tasks:
- id: load_previous_state
type: io.kestra.plugin.core.kv.Get
description: Load previous materialized view health snapshot from Kestra KV store.
key: "starrocks_mv_state_{{ inputs.database_name }}"
allowFailure: true
- id: probe_materialized_views
type: io.kestra.plugin.jdbc.mysql.Query
description: Query StarRocks system catalog for operational status of all
materialized views in the schema.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: FETCH
sql: |
SELECT
TABLE_SCHEMA AS db_name,
TABLE_NAME AS mv_name,
REFRESH_TYPE AS refresh_type,
IS_ACTIVE AS is_active,
LAST_REFRESH_STATE AS last_refresh_state,
LAST_REFRESH_START_TIME AS last_refresh_start_time,
LAST_REFRESH_FINISHED_TIME AS last_refresh_finished_time,
LAST_REFRESH_ERROR_MESSAGE AS last_refresh_error_message,
ROWS AS row_count
FROM information_schema.materialized_views
WHERE TABLE_SCHEMA = '{{ inputs.database_name }}'
ORDER BY mv_name;
- id: evaluate_health_and_drift
type: io.kestra.plugin.transform.jsonata.TransformValue
description: Cross-reference catalog records to isolate failed refreshes and
inactive views.
from: |
{
"rows": {{ (outputs.probe_materialized_views.rows ?? []) | toJson }}
}
expression: |
(
$mvs := rows;
$failed := [$mvs[last_refresh_state = 'FAIL'].(mv_name)];
$inactive := [$mvs[is_active = '0' or is_active = false or is_active = 'false'].(mv_name)];
$allDegraded := [$distinct($append($failed, $inactive))];
{
"failed_views": $failed,
"inactive_views": $inactive,
"all_degraded_views": $allDegraded,
"total_views": $count($mvs),
"failed_count": $count($failed),
"inactive_count": $count($inactive),
"degraded_count": $count($allDegraded),
"has_alerts": $count($allDegraded) > 0
}
)
- id: check_alerts
type: io.kestra.plugin.core.flow.If
description: Skip all subsequent alert and remediation steps if all materialized
views are healthy.
condition: "{{ outputs.evaluate_health_and_drift.value.has_alerts }}"
then:
- id: send_slack_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch high-visibility alert to Slack with degraded view details
and execution triage link.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: >-
{{ {"channel": inputs.slack_channel, "text": ":rotating_light:
*StarRocks Materialized View Alert* - `" ~ inputs.database_name ~
"`\n• *Failed Refreshes* (" ~
outputs.evaluate_health_and_drift.value.failed_count ~ "): " ~
(outputs.evaluate_health_and_drift.value.failed_views | join(', ')) ~
"\n• *Inactive Views* (" ~
outputs.evaluate_health_and_drift.value.inactive_count ~ "): " ~
(outputs.evaluate_health_and_drift.value.inactive_views | join(', '))
~ "\nReview failure logs and choose remediation action: " ~
(kestra.url ?? 'http://localhost:8080') ~ "/ui/executions/" ~
execution.id} | toJson }}
- id: await_operator_decision
type: io.kestra.plugin.core.flow.Pause
description: >
Halt execution and wait for an operator to resume from the Kestra UI.
Select a remediation action: refresh_failed_async (issue REFRESH on
failed views), activate_and_refresh (ALTER ACTIVE then REFRESH
inactive views), force_full_refresh (REFRESH COMPLETE on all degraded
views), or acknowledge_and_skip (close without modifying StarRocks).
pauseDuration: PT4H
behavior: CANCEL
onResume:
- id: remediation_action
type: SELECT
displayName: Remediation action
values:
- refresh_failed_async
- activate_and_refresh
- force_full_refresh
- acknowledge_and_skip
defaults: acknowledge_and_skip
- id: operator_notes
type: STRING
displayName: Operator notes
defaults: "Reviewed degraded views via Kestra UI"
- id: check_dry_run
type: io.kestra.plugin.core.flow.If
description: Check if dry_run mode is active before executing remediation
statements.
condition: "{{ inputs.dry_run == false }}"
then:
- id: remediate_materialized_views
type: io.kestra.plugin.core.flow.Switch
description: Execute the remediation action selected by the operator on resume.
value: "{{ outputs.await_operator_decision.onResume.remediation_action ??
'acknowledge_and_skip' }}"
cases:
refresh_failed_async:
- id: loop_refresh_failed
type: io.kestra.plugin.core.flow.Loop
description: Issue REFRESH MATERIALIZED VIEW for each failed view.
values: "{{ outputs.evaluate_health_and_drift.value.failed_views | toJson }}"
tasks:
- id: refresh_single_mv
type: io.kestra.plugin.jdbc.mysql.Query
description: Trigger asynchronous refresh of the failed materialized view.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: NONE
sql: "REFRESH MATERIALIZED VIEW `{{ inputs.database_name }}`.`{{ item.value
}}`;"
activate_and_refresh:
- id: loop_activate_and_refresh
type: io.kestra.plugin.core.flow.Loop
description: Activate inactive views and issue asynchronous refresh commands.
values: "{{ outputs.evaluate_health_and_drift.value.inactive_views | toJson }}"
tasks:
- id: set_mv_active
type: io.kestra.plugin.jdbc.mysql.Query
description: Re-enable active state on the inactive materialized view.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: NONE
sql: "ALTER MATERIALIZED VIEW `{{ inputs.database_name }}`.`{{ item.value }}`
ACTIVE;"
- id: refresh_activated_mv
type: io.kestra.plugin.jdbc.mysql.Query
description: Refresh the re-activated materialized view.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: NONE
sql: "REFRESH MATERIALIZED VIEW `{{ inputs.database_name }}`.`{{ item.value
}}`;"
force_full_refresh:
- id: loop_force_full_refresh
type: io.kestra.plugin.core.flow.Loop
description: Issue REFRESH MATERIALIZED VIEW COMPLETE to force full
recomputation.
values: "{{ outputs.evaluate_health_and_drift.value.all_degraded_views | toJson
}}"
tasks:
- id: full_refresh_mv
type: io.kestra.plugin.jdbc.mysql.Query
description: Force complete full refresh of the materialized view.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: NONE
sql: "REFRESH MATERIALIZED VIEW `{{ inputs.database_name }}`.`{{ item.value }}`
COMPLETE;"
defaults:
- id: log_acknowledged
type: io.kestra.plugin.core.log.Log
message: "Operator acknowledged degraded views without state modification.
Notes: {{
outputs.await_operator_decision.onResume.operator_notes }}"
- id: check_verify_needed
type: io.kestra.plugin.core.flow.If
description: Re-read materialized view states if active remediation was
attempted.
condition: "{{ (outputs.await_operator_decision.onResume.remediation_action ??
'acknowledge_and_skip') != 'acknowledge_and_skip' }}"
then:
- id: wait_for_refresh_settlement
type: io.kestra.plugin.core.flow.LoopUntil
description: Poll StarRocks until asynchronous refreshes finish running or the
timeout window elapses.
condition: "{{ (outputs.poll_unsettled_views.rows ?? []) | length == 0 }}"
checkFrequency:
interval: PT10S
maxDuration: PT2M
failOnMaxReached: false
tasks:
- id: poll_unsettled_views
type: io.kestra.plugin.jdbc.mysql.Query
description: Check if any materialized view refresh is still active or queued.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: FETCH
sql: |
SELECT
TABLE_NAME AS mv_name,
LAST_REFRESH_STATE AS last_refresh_state
FROM information_schema.materialized_views
WHERE TABLE_SCHEMA = '{{ inputs.database_name }}'
AND LAST_REFRESH_STATE IN ('PENDING', 'RUNNING');
- id: verify_post_remediation
type: io.kestra.plugin.jdbc.mysql.Query
description: Re-query StarRocks system catalog to verify final operational
states across all remediated views.
url: "{{ inputs.jdbc_url }}"
username: "{{ secret('STARROCKS_USERNAME') }}"
password: "{{ secret('STARROCKS_PASSWORD') }}"
fetchType: FETCH
sql: |
SELECT
TABLE_SCHEMA AS db_name,
TABLE_NAME AS mv_name,
REFRESH_TYPE AS refresh_type,
IS_ACTIVE AS is_active,
LAST_REFRESH_STATE AS last_refresh_state,
LAST_REFRESH_START_TIME AS last_refresh_start_time,
LAST_REFRESH_FINISHED_TIME AS last_refresh_finished_time,
LAST_REFRESH_ERROR_MESSAGE AS last_refresh_error_message
FROM information_schema.materialized_views
WHERE TABLE_SCHEMA = '{{ inputs.database_name }}'
AND (LAST_REFRESH_STATE IN ('FAIL', 'PENDING', 'RUNNING') OR IS_ACTIVE = 0 OR IS_ACTIVE = '0');
- id: check_post_remediation_status
type: io.kestra.plugin.core.flow.If
description: Alert on Slack if any materialized view remains failed, inactive,
or unresolved after remediation.
condition: "{{ (outputs.verify_post_remediation.rows ?? []) | length > 0 }}"
then:
- id: alert_unresolved_views
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch alert to Slack for materialized views that could not be
automatically resolved.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: >-
{{ {"channel": inputs.slack_channel, "text": ":warning:
*StarRocks Materialized View Remediation Incomplete* - `"
~ inputs.database_name ~ "`\n• *Unresolved Views* (" ~
((outputs.verify_post_remediation.rows ?? []) | length) ~
"): " ~ (outputs.verify_post_remediation.rows |
jq('.[].mv_name') | join(', ')) ~ "\nViews remain in
failed, inactive, or unresolved (PENDING/RUNNING) state
after remediation. Check execution logs: " ~ (kestra.url
?? 'http://localhost:8080') ~ "/ui/executions/" ~
execution.id} | toJson }}
else:
- id: log_remediation_verified
type: io.kestra.plugin.core.log.Log
message: "Post-remediation verification successful: all materialized views in
schema '{{ inputs.database_name }}' have settled into
active, healthy states."
else:
- id: log_dry_run_skip
type: io.kestra.plugin.core.log.Log
message: "Dry run enabled: skipping StarRocks ALTER and REFRESH remediation
statements for degraded views: {{
outputs.evaluate_health_and_drift.value.all_degraded_views |
join(', ') }}"
- id: save_health_state
type: io.kestra.plugin.core.kv.Set
description: Persist the current health and degradation summary into Kestra KV store.
key: "starrocks_mv_state_{{ inputs.database_name }}"
value: "{{ outputs.evaluate_health_and_drift.value | toJson }}"
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alert on-call immediately if the flow fails due to StarRocks
connectivity or credential errors.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: >-
{{ {"channel": inputs.slack_channel, "text": ":x: *StarRocks Materialized
View Guard Execution Failed*\nExecution ID: `" ~ execution.id ~
"`\nDatabase: `" ~ inputs.database_name ~ "`\nError: StarRocks FE query
failed or timed out. Check execution logs."} | toJson }}
triggers:
- id: scheduled_poll
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/30 * * * *"
disabled: true