Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom tags for MVC metrics #572

Merged
merged 12 commits into from Mar 1, 2021
Merged

Added custom tags for MVC metrics #572

merged 12 commits into from Mar 1, 2021

Conversation

denalex
Copy link
Contributor

@denalex denalex commented Feb 26, 2021

PXF is now capable of applying custom tags to metrics reported by Spring MVC. These tags are: user, segment, profile, server and will be applied to metrics such as http.server.requests.

However, due to a problem with Prometheus integration (micrometer-metrics/micrometer#2399), these tags have to be applied to all endpoints, so the actuator endpoints that receive calls not from Greenplum, will have these tags applied with the values unknown.

public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) {
// add tags only if enabled and the request is for PXF service endpoints (not actuator ones)
if (!customTagsEnabled || StringUtils.isBlank(request.getHeader("X-GP-USER"))) {
return EMPTY_TAGS;
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just Tags.empty() which is probably already an object that was built once, no?


@Override
public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) {
return new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

did you try with long requests tags ? maybe there is no issue if we mark our controller as long request?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I think our requests are long requests, and we should probably mark them as such, and we should probably implement this method instead. Both read and write are considered long requests according to the documentation. All other requests (actuator, health) won't have the headers anyway, so nothing to add there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't yet understand the difference, I can't believe the only difference would be some arbitrary duration boundary, need more research there.

@@ -51,11 +53,6 @@
@Mock
private RequestContext mockContext;

@BeforeAll
public static void init() {
System.setProperty("pxf.logdir", "/tmp");
Copy link
Contributor

Choose a reason for hiding this comment

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

yay! did you want to default pxf.logdir to /tmp as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only defaulted for my tests, I can rebase and remove this altogether and default to /tmp in application.properties

/**
* Bean name of PXF's {@link TaskExecutor}.
*/
public static final String PXF_RESPONSE_STREAM_TASK_EXECUTOR = "pxfResponseStreamTaskExecutor";
private static final Logger LOG = LoggerFactory.getLogger(PxfConfiguration.class);
private static final Tags EMPTY_TAGS = Tags.empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

@denalex denalex changed the title Added custom tags for MVC metrics (turned off by default) Added custom tags for MVC metrics Feb 26, 2021

private Tags addTag(String tag, String value, Tags tags, String defaultValue) {
value = StringUtils.defaultIfBlank(value, defaultValue);
if (StringUtils.isNotBlank(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this check is no longer necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, yes, thank you for the catch, now I can remove the private method !


@Override
public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) {
return new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

can we return Tags.empty() here, if we are not going to use it?

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

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

it looks good, but there seems there's a unit test failing in CI

@denalex denalex merged commit 76c4554 into master Mar 1, 2021
@denalex denalex deleted the pxf-metrics branch March 1, 2021 17:37
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.

None yet

3 participants