All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.config.middleware.experimental-active-request-count-middleware.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExperimentalActiveRequestCountLoggingMiddleware = void 0;
const experimental_metrics_middleware_1 = require("./impl/experimental-metrics-middleware");
class ExperimentalActiveRequestCountLoggingMiddlewareRequestHandler extends experimental_metrics_middleware_1.ExperimentalMetricsMiddlewareRequestHandler {
    constructor(parent, logger, context) {
        super(parent, logger, context);
    }
    recordMetrics() {
        this.parent.decrementActiveRequestCount();
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    emitMetrics(metrics) {
        return Promise.resolve();
    }
}
/**
 * This middleware enables a periodic task to emit the active request count every second as a JSON
 *
 * See `advanced.ts` in the examples directory for an example of how to set up
 * your {Configuration} to enable this middleware.
 */
class ExperimentalActiveRequestCountLoggingMiddleware extends experimental_metrics_middleware_1.ExperimentalMetricsMiddleware {
    constructor(loggerFactory) {
        super(loggerFactory, (p, l, c) => new ExperimentalActiveRequestCountLoggingMiddlewareRequestHandler(p, l, c));
        this.isLoggingStarted = false;
        this.metricsLogInterval = 1000;
        // this is typed as any because JS returns a number for intervalId but
        // TS returns a NodeJS.Timeout.
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.intervalId = null; // Store the interval ID
    }
    init() {
        if (!this.isLoggingStarted) {
            this.isLoggingStarted = true;
            this.startLogging();
        }
    }
    startLogging() {
        this.intervalId = setInterval(() => {
            const metrics = {
                activeRequestCount: this.activeRequestCount(),
                timestamp: Date.now(),
            };
            this.logger.info(JSON.stringify(metrics));
        }, this.metricsLogInterval);
    }
    close() {
        if (this.intervalId !== null) {
            this.logger.debug('Stopping active request count metrics logging.');
            // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
            clearInterval(this.intervalId);
            this.intervalId = null;
            this.isLoggingStarted = false;
            this.logger.debug('Active request count metrics logging stopped.');
        }
    }
}
exports.ExperimentalActiveRequestC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