UNPKG

@mittwald/kubernetes

Version:

Kubernetes client library

72 lines 3.04 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MonitoringKubernetesRESTClient = void 0; const prom_client_1 = require("prom-client"); const apiMetricLabels = ["method"]; class MonitoringKubernetesRESTClient { constructor(inner, registry) { this.inner = inner; this.requestLatencies = new prom_client_1.Histogram({ name: "kubernetes_api_request_latency_milliseconds", help: "Latency in milliseconds for requests to the Kubernetes API server", registers: [registry], labelNames: apiMetricLabels, }); this.errorCount = new prom_client_1.Counter({ name: "kubernetes_api_error_count", help: "Amount of errors that occurred on requests to the Kubernetes API server", registers: [registry], labelNames: apiMetricLabels, }); } wrap(method, fn) { return __awaiter(this, void 0, void 0, function* () { const timer = this.requestLatencies.startTimer({ method }); try { return yield fn(); } catch (err) { this.errorCount.inc({ method }); throw err; } finally { timer(); } }); } post(url, body) { return this.wrap("post", () => this.inner.post(url, body)); } put(url, body) { return __awaiter(this, void 0, void 0, function* () { return this.wrap("put", () => this.inner.put(url, body)); }); } delete(url, opts, queryParams, body) { return __awaiter(this, void 0, void 0, function* () { return this.wrap("delete", () => this.inner.delete(url, opts, queryParams, body)); }); } get(url, opts) { return __awaiter(this, void 0, void 0, function* () { return this.wrap("get", () => this.inner.get(url, opts)); }); } patch(url, body, patchKind) { return this.wrap("patch", () => this.inner.patch(url, body, patchKind)); } watch(url, onUpdate, onError, opts) { return this.wrap("watch", () => this.inner.watch(url, onUpdate, onError, opts)); } } exports.MonitoringKubernetesRESTClient = MonitoringKubernetesRESTClient; //# sourceMappingURL=client_monitoring.js.map