Skip to content

Commit

Permalink
fix: use privte members
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jun 26, 2023
1 parent 975f01d commit 2c79839
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/stats-collector-interceptor.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Interceptor } from './interceptor.mjs';
import { Interceptor } from './interceptor.mjs';

/**
* Interceptor to collect processing time, number of
Expand All @@ -12,60 +12,66 @@ export class StatsCollectorInterceptor extends Interceptor {
return 'collect-request-stats';
}

#numberOfRequests;
#numberOfFailedRequests;;
#minRequestProcessingTime;;
#maxRequestProcessingTime;
#totalRequestProcessingTime;

reset() {
this._numberOfRequests = 0;
this._numberOfFailedRequests = 0;
this._minRequestProcessingTime = Number.MAX_VALUE;
this._maxRequestProcessingTime = 0;
this._totalRequestProcessingTime = 0;
this.#numberOfRequests = 0;
this.#numberOfFailedRequests = 0;
this.#minRequestProcessingTime = Number.MAX_VALUE;
this.#maxRequestProcessingTime = 0;
this.#totalRequestProcessingTime = 0;
}

get numberOfRequests() {
return this._numberOfRequests;
return this.#numberOfRequests;
}

get numberOfFailedRequests() {
return this._numberOfFailedRequests;
return this.#numberOfFailedRequests;
}

get maxRequestProcessingTime() {
return this._maxRequestProcessingTime;
return this.#maxRequestProcessingTime;
}

get minRequestProcessingTime() {
return this._minRequestProcessingTime;
return this.#minRequestProcessingTime;
}

get totalRequestProcessingTime() {
return this._totalRequestProcessingTime;
return this.#totalRequestProcessingTime;
}

/**
* Logs the time the requests takes
*/
async receive(endpoint,...args) {
this._numberOfRequests += 1;
this.#numberOfRequests += 1;

const start = new Date();

try {
const response = await this.connected.receive(...args);
const now = new Date();
const pt = now - start;
this._totalRequestProcessingTime += pt;
this.#totalRequestProcessingTime += pt;

if (pt > this._maxRequestProcessingTime) {
this._maxRequestProcessingTime = pt;
if (pt > this.#maxRequestProcessingTime) {
this.#maxRequestProcessingTime = pt;
}

if (pt < this._minRequestProcessingTime) {
this._minRequestProcessingTime = pt;
if (pt < this.#minRequestProcessingTime) {
this.#minRequestProcessingTime = pt;
}

endpoint.logger.debug(`took ${pt} ms for ${[...args]}`);
return response;
} catch (err) {
this._numberOfFailedRequests += 1;
this.#numberOfFailedRequests += 1;
throw err;
}
}
Expand Down

0 comments on commit 2c79839

Please sign in to comment.