Skip to content

metrics(dm): ignore binlog gap for non-running tasks - #12766

Open
expxiaoli wants to merge 6 commits into
pingcap:masterfrom
expxiaoli:fix_12765_evaluate
Open

metrics(dm): ignore binlog gap for non-running tasks#12766
expxiaoli wants to merge 6 commits into
pingcap:masterfrom
expxiaoli:fix_12765_evaluate

Conversation

@expxiaoli

@expxiaoli expxiaoli commented Jul 27, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: ref #12765

DM_binlog_file_gap_between_master_syncer evaluates paused and stopped tasks. These tasks can continue exposing master and syncer binlog metrics and trigger misleading critical alerts even though replication is intentionally not running.

What is changed and how it works?

  • Join the binlog gap expression with dm_worker_task_state == 2, so the alert only evaluates Running tasks.
  • Keep the expression stored in the alert labels consistent with the rule expression.
  • Add Prometheus rule tests to verify that Running tasks trigger the alert and Paused tasks are ignored.

Check List

Tests

  • Unit test
cd dm/metrics/alertmanager
promtool check rules dm_worker.rules.yml
promtool test rules dm_worker.rules.test.yml
git diff --check

Questions

Will it cause performance regression or break compatibility?

No. This change only affects alert evaluation and does not change DM runtime behavior. Paused and stopped tasks will no longer trigger this alert.

Do you need to update user documentation, design documentation or monitoring documentation?

No. The alert rule and its tests are updated directly.

Release note

Fix the DM master-to-syncer binlog gap alert to ignore tasks that are not running.

Summary by CodeRabbit

  • Bug Fixes

    • Improved binlog gap alert accuracy by triggering it only when the worker task is actively running and the master/syncer positions differ.
  • Tests

    • Added coverage to verify the alert expression, labels, and evaluation duration remain correctly configured.

Join the master-to-syncer binlog gap alert with worker task state so paused or stopped tasks do not raise misleading alerts.
@ti-chi-bot ti-chi-bot Bot added first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. area/dm Issues or PRs related to DM. labels Jul 27, 2026
@pingcap-cla-assistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ti-chi-bot ti-chi-bot Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f49d2db6-30c4-4b17-9a8b-bfdac8b45b3d

📥 Commits

Reviewing files that changed from the base of the PR and between 4042afd and a10624e.

📒 Files selected for processing (1)
  • dm/metrics/alertmanager/dm_worker_rules_test.go
💤 Files with no reviewable changes (1)
  • dm/metrics/alertmanager/dm_worker_rules_test.go

📝 Walkthrough

Walkthrough

The binlog gap alert now requires a running DM worker task. A Go test loads the YAML rule and validates its expression, label expression, and duration.

Changes

DM worker alert behavior

Layer / File(s) Summary
Running-task alert predicate
dm/metrics/alertmanager/dm_worker.rules.yml
The alert requires the master-to-syncer binlog gap and dm_worker_task_state == 2. The labels.expr value matches the updated expression.
Alert rule validation
dm/metrics/alertmanager/dm_worker_rules_test.go
The test maps the YAML structure, locates the alert, and verifies its expression, label expression, and 10m duration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

I’m a rabbit guarding the queue,
Checking task state before alerts break through.
Binlog gaps must now run with care,
YAML tests verify the rule is there.
Hop, hop—consistent expressions everywhere!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the alert change to ignore binlog gaps for non-running tasks.
Description check ✅ Passed The description includes the issue reference, problem, implementation details, tests, compatibility assessment, documentation assessment, and release note.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Run the alert rule regression check as part of the normal DM Go unit tests without downloading an external promtool binary.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dm/metrics/alertmanager/dm_worker_rules_test.go`:
- Around line 44-50: Extend TestBinlogFileGapAlertRuleRequiresRunningTask beyond
metadata checks by evaluating dm_worker.rules.yml with representative running
and paused task samples. Assert that the alert fires for running tasks and does
not fire for paused tasks, while preserving the existing expression, label, and
duration assertions; alternatively, restore the prior promtool coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2e426df-7cff-4741-9df4-527956731a71

📥 Commits

Reviewing files that changed from the base of the PR and between 9b4d4c6 and 20b429e.

📒 Files selected for processing (1)
  • dm/metrics/alertmanager/dm_worker_rules_test.go

Comment thread dm/metrics/alertmanager/dm_worker_rules_test.go
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 30, 2026
@expxiaoli

Copy link
Copy Markdown
Author

/retest-required

@D3Hunter D3Hunter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Total findings: 2
  • Inline comments: 2
  • Summary-only findings (no inline anchor): 0
Findings (highest risk first)

⚠️ [Major] (1)

  1. Test-only PromQL coverage changes repository-wide production dependencies (dm/metrics/alertmanager/dm_worker_rules_test.go:21; go.mod:11; go.mod:56; go.mod:82; pkg/util/memory.go:34; cdc/sink/dmlsink/mq/dmlproducer/pulsar_dml_producer.go:99; cdc/sink/ddlsink/mq/ddlproducer/pulsar_ddl_producer.go:121; cdc/sink/dmlsink/txn/mysql/mysql.go:158)

🟡 [Minor] (1)

  1. One-second wall-clock query deadline makes the rule test load-sensitive (dm/metrics/alertmanager/dm_worker_rules_test.go:55)

"testing"
"time"

"github.com/prometheus/prometheus/promql"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [Major] Test-only PromQL coverage changes repository-wide production dependencies

Why
The new alert-rule test imports the full Prometheus PromQL engine from the root module, which also upgrades dependencies used by production TiFlow code outside DM. Go's module selection is repository-wide rather than test-only, so production binaries will compile against automemlimit v0.5.0 instead of v0.2.4 and golang-lru v0.6.0 instead of v0.5.1. Those releases change cgroup v1/hybrid/no-limit detection and move LRU eviction callbacks outside the cache lock, making a monitoring-only fix alter unrelated runtime behavior.

Scope
dm/metrics/alertmanager/dm_worker_rules_test.go:21; go.mod:11; go.mod:56; go.mod:82; pkg/util/memory.go:34; cdc/sink/dmlsink/mq/dmlproducer/pulsar_dml_producer.go:99; cdc/sink/ddlsink/mq/ddlproducer/pulsar_ddl_producer.go:121; cdc/sink/dmlsink/txn/mysql/mysql.go:158

Risk if unchanged
DM and TiCDC binaries can regress in memory-limit selection on cgroup v1 or hybrid hosts and in eviction or close concurrency for Pulsar producers, prepared statements, and other sink caches. These behavior changes would ship as part of a two-line alert fix even though the new validation exercises only PromQL, expanding the compatibility surface and making failures difficult to attribute.

Evidence
The only new Prometheus import is the test import on this line, while the root go.mod changes 27 requirement lines, adds roughly 20 other module entries, and go.sum changes 384 lines. Production code calls memlimit.FromCgroup from pkg/util/memory.go, whose result controls the redo applier memory cap, and several cdc/sink packages use the upgraded LRU library. No cgroup-mode, redo memory-limit, Pulsar eviction, prepared-statement eviction, or concurrency test is changed in this PR.

Change request
Please keep the production dependency graph unchanged by running the rule test through isolated Prometheus tooling, such as the existing promtool rule-test format or a dedicated test module. If the runtime dependency upgrades are intentional, split them into a dedicated change and add focused coverage for cgroup v1, v2, hybrid, and no-limit detection as well as the affected LRU eviction and sink-cache concurrency paths.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll remove PromQL evaluation and keep lightweight YAML assertions. I won’t add promtool tests because downloading promtool adds over a minute to test execution.


engine := promql.NewEngine(promql.EngineOpts{
MaxSamples: 10000,
Timeout: time.Second,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [Minor] One-second wall-clock query deadline makes the rule test load-sensitive

Why
The tested alert expression has no timing semantics, but the engine is configured with a one-second real-time deadline. PromQL applies this setting through context.WithTimeout during query execution, so a constrained or race-enabled CI worker can fail the test because of host speed rather than an incorrect rule.

Scope
dm/metrics/alertmanager/dm_worker_rules_test.go:55

Risk if unchanged
The new regression test can fail intermittently under CPU contention, reducing confidence in the alert-rule signal and creating non-reproducible CI failures.

Evidence
EngineOpts.Timeout is set to time.Second; the upstream PromQL test setup in the selected v0.50.1 dependency uses 10-100 second safety timeouts for comparable engine-backed tests. The fixture itself is deterministic and does not require a one-second behavioral boundary.

Change request
Please use a generous safety timeout consistent with the upstream PromQL tests so this case fails on expression behavior, not machine scheduling speed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PromQL evaluation and one-second timeout will be removed, so this issue no longer applies.

@D3Hunter D3Hunter Jul 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not the right place to write tests, and the test seems not that necessary

@D3Hunter D3Hunter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm

Keep the alert rule test lightweight and avoid changing production dependencies for test-only PromQL evaluation.
@ti-chi-bot

ti-chi-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gmhdbjd for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 31, 2026
} `yaml:"groups"`
}

func TestBinlogFileGapAlertRuleRequiresRunningTask(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test test anything except that the yaml contains xxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dm Issues or PRs related to DM. do-not-merge/needs-triage-completed first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants