Alexey Serbin has submitted this change and it was merged. (
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
Reviewed-on: http://gerrit.cloudera.org:8080/24789
Reviewed-by: Marton Greber <[email protected]>
Tested-by: Marton Greber <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
---
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
2 files changed, 101 insertions(+), 10 deletions(-)
Approvals:
Marton Greber: Looks good to me, approved; Verified
Alexey Serbin: Looks good to me, approved
--
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: merged
Gerrit-Change-Id: Id283467cd9e1b6ea992f7acbe9b5f9e3ae6693d8
Gerrit-Change-Number: 24789
Gerrit-PatchSet: 2
Gerrit-Owner: Yan-Daojiang <[email protected]>
Gerrit-Reviewer: Alexey Serbin <[email protected]>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Marton Greber <[email protected]>
Gerrit-Reviewer: Yan-Daojiang <[email protected]>