Yan-Daojiang has uploaded this change for review. (
http://gerrit.cloudera.org:8080/24789
Change subject: [metrics] Avoid string allocations in metric filter matching
......................................................................
[metrics] Avoid string allocations in metric filter matching
Metric filtering (the ?types=/?ids=/?attributes=/?metrics= query
parameters on the /metrics and /metrics_prometheus endpoints) is
implemented via MatchName(), a case-insensitive substring match. The
previous implementation allocated two uppercased std::string copies on
every single comparison. Because the metric-name filter runs once per
metric per entity per filter term, a scrape of a cluster with many
tablets could trigger hundreds of thousands of short-lived heap
allocations per request.
This patch rewrites MatchName() to perform the case-insensitive
substring search in place with std::search() and ascii_toupper(),
allocating nothing. The attribute-value filter is also switched from
MatchNameInList() with a single-element initializer list to a direct
MatchName() call, removing a per-attribute temporary std::vector.
The change is behavior-preserving: an empty pattern still matches
everything (mirroring string::find("")), and matching remains a
case-insensitive ASCII substring test. A new TestFilterMatchNameSemantics
covers exact/substring/mixed-case/multi-term/empty-pattern metric-name
matching and case-insensitive attribute-value matching.
Change-Id: Id283467cd9e1b6ea992f7acbe9b5f9e3ae6693d8
---
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
2 files changed, 101 insertions(+), 10 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/89/24789/1
--
To view, visit http://gerrit.cloudera.org:8080/24789
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id283467cd9e1b6ea992f7acbe9b5f9e3ae6693d8
Gerrit-Change-Number: 24789
Gerrit-PatchSet: 1
Gerrit-Owner: Yan-Daojiang <[email protected]>