@mdf.js/service-registry
Version:
MMS - API - Service Registry
83 lines • 3.17 kB
TypeScript
/**
* Copyright 2024 Mytra Control S.L. All rights reserved.
*
* Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
* or at https://opensource.org/licenses/MIT.
*/
import { Layer } from '@mdf.js/core';
import { Links } from '@mdf.js/crash';
import { Registry } from 'prom-client';
import { ObservabilityOptions } from './types';
/**
* Manages the lifecycle and configuration of an Express application dedicated to observability.
* This includes setting up middleware, routing, and server configuration.
* It also supports dynamic registration of services and links for enhanced observability.
*/
export declare class ObservabilityAppManager {
private readonly registry;
/** Express app */
private _app;
/** Registries router */
private _router;
/** Links offered by application */
private _links;
/** HTTP server */
private _server?;
/** Options for the observability service */
private readonly _options;
/**
* Create an instance of observability service
* @param options - observability options
* @param registry - registry to be used for endpoints metrics
*/
constructor(options: ObservabilityOptions, registry: Registry);
/** Indicates whether the server has been initialized. */
get isBuild(): boolean;
/** Starts the server if it has been built. */
start(): Promise<void>;
/** Stops the server if it is running. */
stop(): Promise<void>;
/** Constructs the server with the configured options. */
build(): void;
/** Resets the server to its initial state. */
unbuilt(): void;
/** @returns The links offered by this service */
get links(): Links;
/** Registers a new service with the observability app. */
register(service: Layer.App.Service | Layer.App.Service[]): void;
/** Get the base url whew the observability is served */
private get baseURL();
/** Get the api version */
private get apiVersion();
/** Add a new link to the observability */
private addLinks;
/** Add a new router to the observability */
private addRouter;
/**
* Create an express app that offer all the services routes
* @param router - router to be used
* @param registry - registry to be used for endpoints metrics
* @param apiVersion - api version to be used
* @param defaultLinks - default links to be used
*/
private primaryApp;
/** Create an express app that redirect all the request to the master */
private workerApp;
/** Get if the current process is a worker */
private get isWorker();
/** Get if the current process is working in cluster mode */
private get isClusterMode();
/**
* Check if the port is in the range of valid ports
* @param port - port to be used
* @param defaultPort - default port to be used
* @returns The port to be used
*/
private checkPortInRange;
/**
* Get the port to be used by the service based on the configuration
* @returns The port to be used
*/
private getPort;
}
//# sourceMappingURL=ObservabilityAppManager.d.ts.map