Skip to content

PMM-15198 Indexstats fix.#1321

Open
JiriCtvrtka wants to merge 13 commits into
mainfrom
PMM-15198-indexstats
Open

PMM-15198 Indexstats fix.#1321
JiriCtvrtka wants to merge 13 commits into
mainfrom
PMM-15198-indexstats

Conversation

@JiriCtvrtka

@JiriCtvrtka JiriCtvrtka commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

PMM-15198

Adds a shard label to indexstats metrics. When scraping through mongos, $indexStats returns one document per shard for the same index, so without the label the collector emitted duplicate series (same name and labels) and the per-scrape registry rejected them.

Also raises the go test timeout from 30s to 1m in the Makefile. The 30s limit applies to the whole exporter package, whose integration suite takes ~29s in CI under -race with coverage instrumentation (recent successful runs: 29.250s and 28.698s). With under a second of headroom, any runner jitter makes the test binary panic with test timed out after 30s, blaming whatever test happens to be running at that moment — see https://github.com/percona/mongodb_exporter/actions/runs/30005948435/job/89201852367 for an example. Individual tests remain bounded by their own context timeouts, so genuine hangs are still caught quickly.

@JiriCtvrtka

Copy link
Copy Markdown
Contributor Author

@copilot review

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@copilot review

Reviewed the current PR changes in the indexstats area; I don’t see additional actionable fixes to apply right now. I also re-ran targeted tests for the updated helper logic (TestIndexStatsLabels, TestIndexStatsLabelsWithoutShard, TestSanitize) and they pass.

@JiriCtvrtka

Copy link
Copy Markdown
Contributor Author

@copilot review

@JiriCtvrtka
JiriCtvrtka marked this pull request as ready for review July 22, 2026 08:54
@JiriCtvrtka
JiriCtvrtka requested a review from a team as a code owner July 22, 2026 08:54
@JiriCtvrtka
JiriCtvrtka requested review from 4nte, ademidoff and maxkondr and removed request for a team July 22, 2026 08:54

@ademidoff ademidoff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few minor suggestions, nothing blocking.

labels["database"] = database
labels["collection"] = collection
labels["key_name"] = indexName
if shard, ok := metric["shard"].(string); ok && shard != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: the empty-string guard makes indexstats behave differently from collstats, which adds the label on ok alone (collstats_collector.go:151). Either the guard matters — then collstats should get it too — or it can't happen and it's dead code here. Since it's a two-line change under the same ticket, consider applying the same guard to collstats in this PR.

Context: label dimensions must be consistent per metric name within a single scrape, so if a mongos ever returned shard: "" for some documents but real names for others, dropping the label on only those series would make the whole mongodb_indexstats_* family fail to gather. Theoretical, but worth keeping the two collectors aligned.

@JiriCtvrtka JiriCtvrtka Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Applied your primary suggestion: kept the && shard != "" guard in indexstats and added the same guard to collstats (collstats_collector.go:151), so both collectors now behave identically.

Comment thread exporter/indexstats_collector_test.go Outdated
"key_name": "_id_",
"shard": "shard-1",
}, second)
assert.NotEqual(t, first, second)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: this assertion is redundant — the two exact-map assertions above already guarantee first != second.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment thread exporter/indexstats_collector_test.go Outdated
"testdb",
"orders",
"_id_",
bson.M{"shard": ""},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This only covers shard: "". The more common real case is the field being entirely absent (any non-mongos node) — consider adding a bson.M{} input as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added test case.

@JiriCtvrtka

Copy link
Copy Markdown
Contributor Author

@copilot review

}
}

func setShardLabel(labels map[string]string, metrics bson.M) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Although PMM-15198 primarily targets indexstats, collstats uses the same optional shard label and was updated to keep both collectors consistent. Since collstats reuses the labels map across results, an empty or absent shard could otherwise retain the previous shard value and mislabel metrics. The added tests cover both cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants