@aurox/telemetry
Advanced tools
Comparing version 0.1.2 to 0.2.0
import { BeaconSubsystem, BeaconSubsystemOptions } from './BeaconSubsystem'; | ||
import { TelemetryService } from '../service'; | ||
export interface SetupBeaconOptions { | ||
@@ -6,3 +7,2 @@ healthResponse?: 'yaml' | 'json'; | ||
gracefulShutDownTimeout?: number; | ||
port?: number; | ||
paths?: { | ||
@@ -25,2 +25,2 @@ health?: string; | ||
} | ||
export declare function setupBeacon(options?: SetupBeaconOptions): Beacon; | ||
export declare function setupBeacon(service: TelemetryService, options?: SetupBeaconOptions): Beacon; |
@@ -8,6 +8,5 @@ "use strict"; | ||
const js_yaml_1 = (0, tslib_1.__importDefault)(require("js-yaml")); | ||
const koa_1 = (0, tslib_1.__importDefault)(require("koa")); | ||
const config_1 = require("../config"); | ||
const BeaconSubsystem_1 = require("./BeaconSubsystem"); | ||
function setupBeacon(options) { | ||
function setupBeacon(service, options) { | ||
if (config_1.beaconDisabled) { | ||
@@ -19,3 +18,2 @@ return { setReady: noop_1.default, setNotReady: noop_1.default, registerSubsystem: (name) => new BeaconSubsystem_1.BeaconSubsystem(name) }; | ||
const gracefulShutDownTimeout = options?.gracefulShutDownTimeout ?? 5 * 1000; | ||
const port = options?.port ?? config_1.beaconPort; | ||
const healthPath = options?.paths?.health ?? '/healthz'; | ||
@@ -46,3 +44,2 @@ const livenessPath = options?.paths?.liveness ?? '/livez'; | ||
} | ||
const app = new koa_1.default(); | ||
const router = new router_1.default(); | ||
@@ -93,6 +90,4 @@ router.get(healthPath, ctx => { | ||
}); | ||
app.use(router.routes()).use(router.allowedMethods()); | ||
app.listen(port, () => { | ||
console.info(`Beacon initialized on port ${port} paths: GET ${healthPath} GET ${livenessPath} GET ${readinessPath}`); | ||
}); | ||
service.server.use(router.routes()).use(router.allowedMethods()); | ||
console.info(`Beacon setup on paths: GET ${healthPath} GET ${livenessPath} GET ${readinessPath}`); | ||
async function handleShutdown() { | ||
@@ -99,0 +94,0 @@ shuttingDown = true; |
@@ -0,4 +1,5 @@ | ||
export declare const servicePort: number; | ||
export declare const beaconDisabled: boolean; | ||
export declare const beaconPort: number; | ||
export declare const metricsDisabled: boolean; | ||
export declare const loggerFormat: string; | ||
export declare const loggerSeverity: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loggerSeverity = exports.loggerFormat = exports.beaconPort = exports.beaconDisabled = void 0; | ||
exports.loggerSeverity = exports.loggerFormat = exports.metricsDisabled = exports.beaconDisabled = exports.servicePort = void 0; | ||
function numericWithDefault(stringValue, defaultValue) { | ||
@@ -11,6 +11,7 @@ if (!stringValue) { | ||
} | ||
exports.servicePort = numericWithDefault(process.env.AUROX_TELEMETRY_SERVICE_PORT, 8080); | ||
exports.beaconDisabled = String(process.env.AUROX_TELEMETRY_BEACON_DISABLED).trim().toLowerCase() === 'true'; | ||
exports.beaconPort = numericWithDefault(process.env.AUROX_TELEMETRY_BEACON_PORT, 8080); | ||
exports.metricsDisabled = String(process.env.AUROX_TELEMETRY_METRICS_DISABLED).trim().toLowerCase() === 'true'; | ||
exports.loggerFormat = String(process.env.AUROX_TELEMETRY_LOGGER_FORMAT || 'json'); | ||
exports.loggerSeverity = String(process.env.AUROX_TELEMETRY_LOGGER_SEVERITY || 'INFO'); | ||
//# sourceMappingURL=config.js.map |
{ | ||
"name": "@aurox/telemetry", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A universal solution for logging, tracing, metrics, health-checks and more", | ||
@@ -29,2 +29,3 @@ "main": "dist/index.js", | ||
"lodash": "^4.17.21", | ||
"prom-client": "^13.2.0", | ||
"source-map-support": "^0.5.19", | ||
@@ -31,0 +32,0 @@ "tslib": "^2.3.1" |
@@ -5,9 +5,18 @@ ## Aurox Telemetry | ||
### Service | ||
* `AUROX_TELEMETRY_SERVICE_PORT`: The port the telemetry service uses to respond to health check, metrics, etc... requests. Default: `8080`. | ||
### Beacon | ||
Setups an http server to serve health-check endpoints such as `/health`, `/live` and `/ready`. | ||
Setups health-check endpoints such as `/health`, `/live` and `/ready` on the telemetry service. | ||
* `AUROX_TELEMETRY_BEACON_DISABLED`: Disables the beacon when set to `true`, this forces the beacon to be disabled. | ||
* `AUROX_TELEMETRY_BEACON_PORT`: The port the beacon uses to respond to health check requests. Default: `8080`. | ||
### Metrics | ||
Setups prometheus metrics endpoint `/metrics` on the telemetry service. | ||
* `AUROX_TELEMETRY_METRICS_DISABLED`: Disables the metrics when set to `true`, this forces the metrics to be disabled. | ||
### Logger | ||
@@ -14,0 +23,0 @@ |
import Router from '@koa/router'; | ||
import noop from 'lodash/noop'; | ||
import yaml from 'js-yaml'; | ||
import Koa from 'koa'; | ||
import { beaconDisabled, beaconPort } from '../config'; | ||
import { beaconDisabled } from '../config'; | ||
import { BeaconSubsystem, BeaconSubsystemOptions, BeaconSubsystemReport } from './BeaconSubsystem'; | ||
import { TelemetryService } from '../service'; | ||
@@ -14,3 +14,2 @@ export interface SetupBeaconOptions { | ||
gracefulShutDownTimeout?: number; | ||
port?: number; | ||
paths?: { health?: string; liveness?: string; readiness?: string }; | ||
@@ -31,3 +30,3 @@ messages?: { | ||
export function setupBeacon(options?: SetupBeaconOptions): Beacon { | ||
export function setupBeacon(service: TelemetryService, options?: SetupBeaconOptions): Beacon { | ||
if (beaconDisabled) { | ||
@@ -41,4 +40,2 @@ return { setReady: noop, setNotReady: noop, registerSubsystem: (name: string) => new BeaconSubsystem(name) }; | ||
const port = options?.port ?? beaconPort; | ||
const healthPath = options?.paths?.health ?? '/healthz'; | ||
@@ -79,3 +76,2 @@ const livenessPath = options?.paths?.liveness ?? '/livez'; | ||
const app = new Koa(); | ||
const router = new Router(); | ||
@@ -127,7 +123,5 @@ | ||
app.use(router.routes()).use(router.allowedMethods()); | ||
service.server.use(router.routes()).use(router.allowedMethods()); | ||
app.listen(port, () => { | ||
console.info(`Beacon initialized on port ${port} paths: GET ${healthPath} GET ${livenessPath} GET ${readinessPath}`); | ||
}); | ||
console.info(`Beacon setup on paths: GET ${healthPath} GET ${livenessPath} GET ${readinessPath}`); | ||
@@ -134,0 +128,0 @@ async function handleShutdown() { |
@@ -11,6 +11,9 @@ function numericWithDefault(stringValue: string | undefined, defaultValue: number) { | ||
export const servicePort = numericWithDefault(process.env.AUROX_TELEMETRY_SERVICE_PORT, 8080); | ||
export const beaconDisabled = String(process.env.AUROX_TELEMETRY_BEACON_DISABLED).trim().toLowerCase() === 'true'; | ||
export const beaconPort = numericWithDefault(process.env.AUROX_TELEMETRY_BEACON_PORT, 8080); | ||
export const metricsDisabled = String(process.env.AUROX_TELEMETRY_METRICS_DISABLED).trim().toLowerCase() === 'true'; | ||
export const loggerFormat = String(process.env.AUROX_TELEMETRY_LOGGER_FORMAT || 'json'); | ||
export const loggerSeverity = String(process.env.AUROX_TELEMETRY_LOGGER_SEVERITY || 'INFO'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82066
78
1461
28
14
+ Addedprom-client@^13.2.0
+ Added@types/express-serve-static-core@5.0.2(transitive)
+ Addedbintrees@1.0.2(transitive)
+ Addedprom-client@13.2.0(transitive)
+ Addedtdigest@0.1.2(transitive)
- Removed@types/express-serve-static-core@5.0.1(transitive)