1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/src/lib/middleware
Gastón Fournier e8e1d6e9f0
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:

![image](https://github.com/Unleash/unleash/assets/455064/0d8f1f40-8b5b-49d4-8a88-70b523e9be09)

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
..
api-token-middleware.test.ts
api-token-middleware.ts feat: allow api token middleware to fetch from db (#6344) 2024-02-27 16:08:44 +01:00
authorization-middleware.ts
catch-all-error-handler.ts
conditional-middleware.ts
content_type_checker.test.ts
content_type_checker.ts
cors-origin-middleware.test.ts
cors-origin-middleware.ts
demo-authentication.ts
index.ts
no-authentication.test.ts
no-authentication.ts fix: Allow AuthType None to use valid API tokens (#6247) 2024-02-16 08:24:56 +00:00
oss-authentication.test.ts
oss-authentication.ts
pat-middleware.test.ts chore: add types to pat middleware (#5951) 2024-01-18 14:36:42 +01:00
pat-middleware.ts chore: add types to pat middleware (#5951) 2024-01-18 14:36:42 +01:00
rbac-middleware.test.ts
rbac-middleware.ts
request-logger.ts
response-time-metrics.test.ts fix: path metric labels (#6400) 2024-03-05 15:25:06 +01:00
response-time-metrics.ts fix: path metric labels (#6400) 2024-03-05 15:25:06 +01:00
secure-headers.ts
session-db.ts
unless-middleware.ts