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

Simplified prom route when using default express route #113

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kennsippell
Copy link


let app, config;

describe('when using express framework (default route)', function() {
Copy link
Author

@kennsippell kennsippell Jun 28, 2023

Choose a reason for hiding this comment

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

I made a new test server in this PR because the default route (wildcard '*') assumes a paradigm where requests get handled by routes which don't call next().

In the existing tests, routes always call next() and the test logic relies on this for the error cases.

Open to ideas on how to better integrate this with existing tests.

@@ -57,6 +57,11 @@ class ExpressMiddleware {
route = route ? route + req.route.path : req.route.path;
}

// #112 - aggregated express default route
Copy link
Author

@kennsippell kennsippell Jun 28, 2023

Choose a reason for hiding this comment

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

There are three cases we need to worry about the default route.

  1. Routine route assignment (ln65)
  2. Appending when includeQueryParams is true (ln76)
  3. Nest.js case is actually setting route to :0* (ln82)

Because this affected so many branches, I opted for a short-circuit. Alternatives and suggestions welcome.

Copy link
Collaborator

Choose a reason for hiding this comment

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

as it seems we're missing support * in general.
according to express documentation

This route path will match abcd, abxcd, abRANDOMcd, ab123cd, and so on.

app.get('/ab*cd', (req, res) => {
  res.send('ab*cd')
})

and also regex support, which we can ignore for now.

shouldn't we support all routes with * instead?
the main issue here is that we'd need to also support * with request params. i.e

app.get('/ab*cd/:id', (req, res) => {
  res.send('ab*cd')
})

this isn't a must for now, but would have been a more complete solution.

lmk what you think.

Copy link
Author

@kennsippell kennsippell Jul 6, 2023

Choose a reason for hiding this comment

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

I'd be interested to pursue the general solution. If somebody has an answer to this question, I'll have a better understanding of the requirements and can take a stab at it. Without that, I'm worried I'm going to break something.

I'll install Nest and play around if I don't heard back.

@kennsippell
Copy link
Author

Before merge, let me test this on some production data and confirm this is really what we want & need :) I'll send an update on this shortly.

@kennsippell
Copy link
Author

Tested today and the data is much much cleaner. Also found #114.

@kobik
Copy link
Collaborator

kobik commented Mar 27, 2024

sorry for the very late response.

is this still relevant?

@kennsippell
Copy link
Author

kennsippell commented Mar 27, 2024

@kobik This is still relevant for our project. We are running in production with issues patched. Would be great to somehow get these into an official release.

@kobik
Copy link
Collaborator

kobik commented Mar 27, 2024

OK, let's drive this forward @kennsippell.

After going over the discussion we had on the change, I'd like to be able to support * in general if you don't mind.
As I answered to your question about why the request parameters are mutated, it is because otherwise we could have high cardinality due to the path parameters, i.e. calling /users/:id with thousands of users.

Ofc I agree that the code shouldn't mutate the original request params, yet we need to make sure that we don't use the request params values for our metrics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants