Verified
Status Update
Comments
ma...@gmail.com <ma...@gmail.com> #2
Proxy.8080
sy...@gmail.com <sy...@gmail.com> #3
[Description Changed]
ap...@google.com <ap...@google.com> #4
Project: gerrit
Branch: stable-3.6
commit 771df4361741688ed99a439fc3e0ba9fd4ac16d0
Author: Jacek Centkowski <geminica.programs@gmail.com>
Date: Tue Jun 20 09:19:07 2023
Modify 'sanitizeMetricName' to avoid collisions
At present there is a simple 'DropWizardMetricMaker.sanitizeMetricName'
implementation that:
* replaces the leading `/` with `_`
* reduces the repeated `/` chars to a single `/`
* removes the ending `/`
* replaces not supported chars with `_`
As a result collision between the sanitized metric names can be easily
created e.g. `foo_bar` will collide with `foo+bar`.
In order to avoid collisions keep the rules about slashes (they are
needed anyway) and:
* replace not supported chars with `_0x[HEX CODE]_` string (code is
capitalized)
* the replacement prefix `0x` is prepended with another replacement
prefix
As a result:
`foo_bar` stays `foo_bar`
`foo+bar` becomes `foo_0x2B_bar`
`foo_0x2B_bar` becomes `foo_0x_0x2B_bar`
and collision is no longer possible
The replace algorithm was inspired by the work done in If11e6576eff
(kudos to Dani).
Bug: Issue 40015585
Release-Notes: Enhance metric name sanitize function to remove collision on '_' between metrics. Gerrit core metrics remain unchanged but plugins metrics could be affected.
Change-Id: I6a5366fa0f1fd494006e2234565371d279e8a7f3
M Documentation/dev-plugins.txt
M java/com/google/gerrit/metrics/dropwizard/DropWizardMetricMaker.java
M javatests/com/google/gerrit/metrics/dropwizard/DropWizardMetricMakerTest.java
https://gerrit-review.googlesource.com/377439
Branch: stable-3.6
commit 771df4361741688ed99a439fc3e0ba9fd4ac16d0
Author: Jacek Centkowski <geminica.programs@gmail.com>
Date: Tue Jun 20 09:19:07 2023
Modify 'sanitizeMetricName' to avoid collisions
At present there is a simple 'DropWizardMetricMaker.sanitizeMetricName'
implementation that:
* replaces the leading `/` with `_`
* reduces the repeated `/` chars to a single `/`
* removes the ending `/`
* replaces not supported chars with `_`
As a result collision between the sanitized metric names can be easily
created e.g. `foo_bar` will collide with `foo+bar`.
In order to avoid collisions keep the rules about slashes (they are
needed anyway) and:
* replace not supported chars with `_0x[HEX CODE]_` string (code is
capitalized)
* the replacement prefix `0x` is prepended with another replacement
prefix
As a result:
`foo_bar` stays `foo_bar`
`foo+bar` becomes `foo_0x2B_bar`
`foo_0x2B_bar` becomes `foo_0x_0x2B_bar`
and collision is no longer possible
The replace algorithm was inspired by the work done in If11e6576eff
(kudos to Dani).
Bug:
Release-Notes: Enhance metric name sanitize function to remove collision on '_' between metrics. Gerrit core metrics remain unchanged but plugins metrics could be affected.
Change-Id: I6a5366fa0f1fd494006e2234565371d279e8a7f3
M Documentation/dev-plugins.txt
M java/com/google/gerrit/metrics/dropwizard/DropWizardMetricMaker.java
M javatests/com/google/gerrit/metrics/dropwizard/DropWizardMetricMakerTest.java
sa...@gmail.com <sa...@gmail.com> #5
Comment has been deleted.
lu...@gmail.com <lu...@gmail.com>
ap...@google.com <ap...@google.com> #6
Project: gerrit
Branch: stable-3.6
commit c14d87b01f51ea659f0e9474815a7551859a0cf0
Author: Jacek Centkowski <geminica.programs@gmail.com>
Date: Thu Jul 13 06:21:16 2023
Fix project name's based submetric names collision
At present submetric name in CallbackMetricImpl1 is a subject of simple
sanitization rule: `/` chars are replaced with `_`. This is ok for
majority submetrics (e.g. those related to JVM) but not enough for the
limited set based on the project name (e.g.
'jgit/block_cache/cache_used_per_repository').
Luckily project name is a subject of characters restriction,
nevertheless it leads to incorrect behaviour e.g. both `repo_name` and
`repo/name` end up to be santized to the same `repo_name`.
Before [1] that resulted in metrics being no longer available whereas
now it results in values being reported for wrong repository.
In order to solve it introduce a dedicated Field builder that is meant
to be used to extract value from project name (called
Field.ofProjectName).
It sanitizes (during format) the received value so that only names
that match the `[a-zA-Z0-9_-]+([a-zA-Z0-9_-]+)*` are allowed (that is a
requirement for submetric name). Not matching characters are replaced
with `_[HEX CODE]_` (code is capitalized) string. Considering that:
* `repo_name` matches the pattern and remains unchanged
* `repo/name` is sanitized to `repo_0x2F_name`
* `repo_0x2F_name` becomes `repo_0x_0x2F_name`
and collistion is avoided.
Note that only Gerrit's core metrics that are based on project name
are affected.
[1]https://gerrit-review.googlesource.com/c/gerrit/+/369415
Bug: Issue 40015585
Release-Notes: Breaking change: project based submetric name is sanitized with more rules than just changing `/` to `_`
Change-Id: I8f72aa47cb60e9716fea9e9b9a1d047256fe697d
M Documentation/metrics.txt
M java/com/google/gerrit/metrics/Field.java
M java/com/google/gerrit/metrics/proc/JGitMetricModule.java
M java/com/google/gerrit/server/project/SubmitRequirementsUtil.java
A javatests/com/google/gerrit/metrics/BUILD
A javatests/com/google/gerrit/metrics/FieldSanitizeProjectNameTest.java
M javatests/com/google/gerrit/server/logging/PerformanceLogContextTest.java
https://gerrit-review.googlesource.com/377954
Branch: stable-3.6
commit c14d87b01f51ea659f0e9474815a7551859a0cf0
Author: Jacek Centkowski <geminica.programs@gmail.com>
Date: Thu Jul 13 06:21:16 2023
Fix project name's based submetric names collision
At present submetric name in CallbackMetricImpl1 is a subject of simple
sanitization rule: `/` chars are replaced with `_`. This is ok for
majority submetrics (e.g. those related to JVM) but not enough for the
limited set based on the project name (e.g.
'jgit/block_cache/cache_used_per_repository').
Luckily project name is a subject of characters restriction,
nevertheless it leads to incorrect behaviour e.g. both `repo_name` and
`repo/name` end up to be santized to the same `repo_name`.
Before [1] that resulted in metrics being no longer available whereas
now it results in values being reported for wrong repository.
In order to solve it introduce a dedicated Field builder that is meant
to be used to extract value from project name (called
Field.ofProjectName).
It sanitizes (during format) the received value so that only names
that match the `[a-zA-Z0-9_-]+([a-zA-Z0-9_-]+)*` are allowed (that is a
requirement for submetric name). Not matching characters are replaced
with `_[HEX CODE]_` (code is capitalized) string. Considering that:
* `repo_name` matches the pattern and remains unchanged
* `repo/name` is sanitized to `repo_0x2F_name`
* `repo_0x2F_name` becomes `repo_0x_0x2F_name`
and collistion is avoided.
Note that only Gerrit's core metrics that are based on project name
are affected.
[1]
Bug:
Release-Notes: Breaking change: project based submetric name is sanitized with more rules than just changing `/` to `_`
Change-Id: I8f72aa47cb60e9716fea9e9b9a1d047256fe697d
M Documentation/metrics.txt
M java/com/google/gerrit/metrics/Field.java
M java/com/google/gerrit/metrics/proc/JGitMetricModule.java
M java/com/google/gerrit/server/project/SubmitRequirementsUtil.java
A javatests/com/google/gerrit/metrics/BUILD
A javatests/com/google/gerrit/metrics/FieldSanitizeProjectNameTest.java
M javatests/com/google/gerrit/server/logging/PerformanceLogContextTest.java
Description
*************************************************************************
*** !!!! THIS BUG TRACKER IS FOR GERRIT CODE REVIEW !!!!
*** Do not submit bugs for chrome/android and issues with your company's
*** Gerrit setup here. Those issues belong in different issue trackers.
*************************************************************************
What steps will reproduce the problem?
1. Create a repository foo/bar
2. Create a repository foo-bar
3. Install metrics-reporter-prometheus
4. create some changes for clone foo/bar, and for foo-bar in order to populate the jgit cache
5. hit the metrics reporter prometheus endpoint
curl -s -H'Authorization: Bearer token123' 'http://localhost:8080/plugins/metrics-reporter-prometheus/metrics '
What is the expected output?
Since the repository names are ambiguous this should be logged and no repository metric should be exposed.
What do you see instead?
An exception is thrown:
[2023-06-01 13:12:11,405] [HTTP-93] WARN org.eclipse.jetty.server.HttpChannel : /plugins/metrics-reporter-prometheus/metrics
java.lang.IllegalArgumentException: A metric named jgit/block_cache/cache_used_per_repository/-Users-syntonyze-ginstall-gerrit-2.16.28-git-foo-bar.git already exists
Please provide any additional information below.