2021-03-11 22:51:58 +01:00
|
|
|
import { BackstageController } from './backstage';
|
2021-04-16 15:29:23 +02:00
|
|
|
import ResetPasswordController from './auth/reset-password-controller';
|
2022-06-23 09:40:25 +02:00
|
|
|
import { SimplePasswordProvider } from './auth/simple-password-provider';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { IUnleashConfig, IUnleashServices } from '../types';
|
2022-06-03 11:50:58 +02:00
|
|
|
import LogoutController from './logout';
|
2022-09-26 09:58:58 +02:00
|
|
|
import rateLimit from 'express-rate-limit';
|
fix: path metric labels (#6400)
## About the changes
Some of our metrics are not labeled correctly, one example is
`<base-path>/api/frontend/client/metrics` is labeled as
`/client/metrics`. We can see that in internal-backstage/prometheus:

This issue affects all endpoints that fail to validate the request body.
Also, endpoints that are rejected by the authorization-middleware or the
api-token-middleware are reported as `(hidden)`.
To gain more insights on our api usage but being protective of metrics
cardinality we're prefixing `(hidden)` with some well known base urls:
https://github.com/Unleash/unleash/pull/6400/files#diff-1ed998ca46ffc97c9c0d5d400bfd982dbffdb3004b78a230a8a38e7644eee9b6R17-R33
## How to reproduce:
Make an invalid call to metrics (e.g. stop set to null), then check
/internal-backstage/prometheus and find the 400 error. Expected to be at
`path="/api/client/metrics"` but will have `path=""`:
```shell
curl -H"Authorization: *:development.unleash-insecure-client-api-token" -H'Content-type: application/json' localhost:4242/api/client/metrics -d '{
"appName": "bash-test",
"instanceId": "application-name-dacb1234",
"environment": "development",
"bucket": {
"start": "2023-07-27T11:23:44Z",
"stop": null,
"toggles": {
"myCoolToggle": {
"yes": 25,
"no": 42,
"variants": {
"blue": 6,
"green": 15,
"red": 46
}
},
"myOtherToggle": {
"yes": 0,
"no": 100
}
}
}
}'
```
2024-03-05 15:25:06 +01:00
|
|
|
import Controller from './controller';
|
|
|
|
import { AdminApi } from './admin-api';
|
|
|
|
import ClientApi from './client-api';
|
2016-06-18 21:53:18 +02:00
|
|
|
|
2022-06-20 12:22:41 +02:00
|
|
|
import { HealthCheckController } from './health-check';
|
2024-03-11 17:30:46 +01:00
|
|
|
import FrontendAPIController from '../features/frontend-api/frontend-api-controller';
|
2022-09-01 15:26:26 +02:00
|
|
|
import EdgeController from './edge-api';
|
2022-09-30 13:01:32 +02:00
|
|
|
import { PublicInviteController } from './public-invite';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { Db } from '../db/db';
|
2023-03-03 13:09:28 +01:00
|
|
|
import { minutesToMilliseconds } from 'date-fns';
|
2022-08-16 15:33:33 +02:00
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
class IndexRouter extends Controller {
|
2023-02-16 08:08:51 +01:00
|
|
|
constructor(config: IUnleashConfig, services: IUnleashServices, db: Db) {
|
2021-03-11 22:51:58 +01:00
|
|
|
super(config);
|
2022-08-26 15:16:29 +02:00
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
this.use('/health', new HealthCheckController(config, services).router);
|
2022-09-30 13:01:32 +02:00
|
|
|
this.use(
|
|
|
|
'/invite',
|
|
|
|
new PublicInviteController(config, services).router,
|
|
|
|
);
|
2021-02-16 14:30:08 +01:00
|
|
|
this.use('/internal-backstage', new BackstageController(config).router);
|
2022-09-23 14:19:17 +02:00
|
|
|
this.use('/logout', new LogoutController(config, services).router);
|
2022-09-26 09:58:58 +02:00
|
|
|
this.useWithMiddleware(
|
2021-04-09 13:46:53 +02:00
|
|
|
'/auth/simple',
|
|
|
|
new SimplePasswordProvider(config, services).router,
|
2022-09-26 09:58:58 +02:00
|
|
|
rateLimit({
|
2023-03-03 13:09:28 +01:00
|
|
|
windowMs: minutesToMilliseconds(1),
|
2023-10-26 09:20:29 +02:00
|
|
|
max: config.rateLimiting.simpleLoginMaxPerMinute,
|
2023-08-03 12:47:19 +02:00
|
|
|
validate: false,
|
2022-09-26 09:58:58 +02:00
|
|
|
standardHeaders: true,
|
|
|
|
legacyHeaders: false,
|
|
|
|
}),
|
2021-04-09 13:46:53 +02:00
|
|
|
);
|
2021-04-16 15:29:23 +02:00
|
|
|
this.use(
|
|
|
|
'/auth/reset',
|
|
|
|
new ResetPasswordController(config, services).router,
|
|
|
|
);
|
2022-09-16 09:54:27 +02:00
|
|
|
|
2023-02-16 08:08:51 +01:00
|
|
|
this.use('/api/admin', new AdminApi(config, services, db).router);
|
2022-08-16 15:33:33 +02:00
|
|
|
this.use('/api/client', new ClientApi(config, services).router);
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2022-08-26 15:16:29 +02:00
|
|
|
this.use(
|
|
|
|
'/api/frontend',
|
2024-02-20 11:27:21 +01:00
|
|
|
new FrontendAPIController(config, services).router,
|
2022-08-26 15:16:29 +02:00
|
|
|
);
|
2022-09-01 15:26:26 +02:00
|
|
|
|
|
|
|
this.use('/edge', new EdgeController(config, services).router);
|
2017-09-07 21:42:21 +02:00
|
|
|
}
|
2018-11-24 12:58:30 +01:00
|
|
|
}
|
2016-11-09 22:31:49 +01:00
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
export default IndexRouter;
|
|
|
|
|
2018-11-24 12:58:30 +01:00
|
|
|
module.exports = IndexRouter;
|