Add parameter to optionally strip deploy path.#639
Merged
fstab merged 2 commits intoprometheus:masterfrom Jul 31, 2021
Merged
Conversation
Closes prometheus#631. Signed-off-by: Lapo Luchini <lapo@lapo.it>
fstab
requested changes
Mar 19, 2021
Member
There was a problem hiding this comment.
Thanks a lot or the PR. Here are a few minor comments:
Please update the class JavaDoc for MetricsFilter. Add the new option with its default to the example:
<!-- strip-context-path is optional, defaults to false -->
<init-param>
<param-name>strip-context-path</param-name>
<param-value>false</param-value>
</init-param>...and add an explanation of the strip-context-path option to the text above the example.
Additionally, please also update the Servlet Filter section in README.md.
There should be a test for the new option in MetricsFilterTest. With copy-and-paste from init() it could look something like this
@Test
public void testStripContextPath() throws Exception {
String metricName = "foo";
FilterConfig cfg = mock(FilterConfig.class);
when(cfg.getInitParameter(MetricsFilter.METRIC_NAME_PARAM)).thenReturn(metricName);
when(cfg.getInitParameter(MetricsFilter.PATH_COMPONENT_PARAM)).thenReturn("0");
when(cfg.getInitParameter(MetricsFilter.STRIP_CONTEXT_PATH_PARAM)).thenReturn("true");
f.init(cfg);
assertTrue(f.stripContextPath);
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getRequestURI()).thenReturn("/foo/bar/baz/bang");
when(req.getContextPath()).thenReturn("/foo/bar");
when(req.getMethod()).thenReturn(HttpMethods.GET);
HttpServletResponse res = mock(HttpServletResponse.class);
FilterChain c = mock(FilterChain.class);
f.doFilter(req, res, c);
verify(c).doFilter(req, res);
final Double sampleValue = CollectorRegistry.defaultRegistry.getSampleValue(metricName + "_count", new String[]{"path", "method"}, new String[]{"/baz/bang", HttpMethods.GET});
assertNotNull(sampleValue);
assertEquals(1, sampleValue, 0.0001);
}
simpleclient_servlet/src/main/java/io/prometheus/client/filter/MetricsFilter.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Lapo Luchini <lapo@lapo.it>
Contributor
Author
|
@fstab let me know if anything more should be changed. |
Member
|
Thanks a lot @lapo-luchini, and sorry that it took so long to merge this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #631.