Skip to content

Commit

Permalink
Merge pull request #426 from ybonnefond/fix-425
Browse files Browse the repository at this point in the history
Invalid values for error count metrics
  • Loading branch information
pragmaticivan authored May 5, 2023
2 parents adfb651 + 7b13c0b commit 5ba01ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class AppController {
|| http.server.request.size | http_server_request_size | Size of incoming bytes. | Histogram |
|| http.server.response.size | http_server_response_size | Size of outgoing bytes. | Histogram |
|| http.server.response.success.count | http_server_response_success_count_total | Total number of all successful responses. | Counter |
|| http.server.response.error.count | http_server_response_error_count_total | Total number of all response errors'. | Counter |
|| http.server.response.error.count | http_server_response_error_count_total | Total number of server error responses. | Counter |
|| http.client.request.error.count | http_client_request_error_count_total | Total number of client error requests. | Counter |

## Prometheus Metrics
Expand Down
2 changes: 0 additions & 2 deletions src/middleware/api-metrics.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ export class ApiMetricsMiddleware implements NestMiddleware {
this.httpServerResponseSuccessCount.add(1);
break;
case 'client_error':
this.httpServerResponseErrorCount.add(1);
this.httpClientRequestErrorCount.add(1);
break;
case 'server_error':
this.httpServerResponseErrorCount.add(1);
this.httpClientRequestErrorCount.add(1);
break;
}

Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/middleware/api-metrics.middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ describe('Api Metrics Middleware', () => {
}).compile();

app = testingModule.createNestApplication();
app.useLogger(false);

await app.init();

const agent = request(app.getHttpServer());
await agent.get('/example/4/invalid-route?foo=bar');
await agent.get('/example/internal-error');

// Workaround for delay of metrics going to prometheus
await new Promise(resolve => setTimeout(resolve, 200));
Expand Down Expand Up @@ -286,11 +288,13 @@ describe('Api Metrics Middleware', () => {
}).compile();

app = testingModule.createNestApplication<NestFastifyApplication>(new FastifyAdapter());
app.useLogger(false);

await app.init();
await app.getHttpAdapter().getInstance().ready();

const agent = request(app.getHttpServer());
await agent.get('/example/4/invalid-route?foo=bar');
await agent.get('/example/internal-error');

// Workaround for delay of metrics going to prometheus
await new Promise(resolve => setTimeout(resolve, 200));
Expand Down

0 comments on commit 5ba01ad

Please sign in to comment.