TestMetricTxnAborts is racy: baseline fetchMetrics is not retried while the assertion is

オープン 初心者向け
#9,811 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 10 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
go
領域
testing-qa

調査の方向性

dgraph/cmd/alpha/metrics_test.go の TestMetricTxnAborts から始め、その baseline fetchMetrics 呼び出しを retryableFetchMetrics と比較します。関連する TestMetricTxnCommits と TestMetricTxnDiscards のケースについても、同じパターンになっているか確認します。メトリクスのベースラインが非同期エクスポートを許容し、影響を受けるテストがメトリクス欠落による race なしでパスすれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Stale
Summary

TestMetricTxnAborts reads its baseline metric value with an unretried fetchMetrics, while the assertion that follows uses retryableFetchMetrics. Prometheus metric export is asynchronous, so the baseline read can land before dgraph_txn_aborts_total has been published and the test fails with a message that reads like a missing metric rather than a race.

The code

dgraph/cmd/alpha/metrics_test.go:

func TestMetricTxnAborts(t *testing.T) {
	metricName := "dgraph_txn_aborts_total"
	...
	require.NoError(t, commitWithTs(mr1, false))
	require.Error(t, commitWithTs(mr2, false))

	metrics := fetchMetrics(t, metricName)          // <-- not retried

	... second round of mutations ...

	require.NoError(t, retryableFetchMetrics(t, map[string]int{
		metricName: metrics[metricName] + 1,        // <-- retried
	}))
}

The asymmetry looks unintentional: the same value is fetched twice, once without tolerance for propagation delay and once with.

Note also that dgraph_txn_aborts_total does not exist on the /metrics endpoint until the first abort is actually exported, so on a fresh cluster the baseline read is the most likely of the two to race — it is the one that has to wait for the counter to appear at all, not merely to increment.

Observed failure
--- FAIL: TestMetricTxnAborts (0.02s)
    metrics_test.go:153: the required metric 'dgraph_txn_aborts_total' was not found

Line 153 is inside fetchMetrics, reached from the unretried call. It passes on re-run, which is consistent with a propagation race rather than a functional problem. The preceding require.Error(t, commitWithTs(mr2, false)) passes, so the aborting commit did happen.

Seen once in CI on a fork of this repo; green on re-run of the same commit.

Suggested fix

Use the retrying variant for the baseline too, so the test tolerates propagation in both reads:

require.NoError(t, retryableFetchMetrics(t, map[string]int{metricName: 1}))
metrics := fetchMetrics(t, metricName)

Or have fetchMetrics treat "metric absent" as retryable when the caller is establishing a baseline. Either way the intent is that the test waits for the counter to exist before reading it.

TestMetricTxnCommits and TestMetricTxnDiscards have the same shape and are presumably exposed to the same race, though we have only observed the aborts variant failing.

I'm happy to open a PR for this if it's welcome.

主要言語
Go
スター
21.8k
フォーク
1.6k
平均マージ
11日 7時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dgraph-io/dgraph のほかの issue

dgraph-io/dgraph の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。