UNPKG

2.99 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const prom_client_1 = require("prom-client");
13const apiMetricLabels = ["method"];
14class MonitoringKubernetesRESTClient {
15 constructor(inner, registry) {
16 this.inner = inner;
17 this.requestLatencies = new prom_client_1.Histogram({
18 name: "kubernetes_api_request_latency_milliseconds",
19 help: "Latency in milliseconds for requests to the Kubernetes API server",
20 registers: [registry],
21 labelNames: apiMetricLabels,
22 });
23 this.errorCount = new prom_client_1.Counter({
24 name: "kubernetes_api_error_count",
25 help: "Amount of errors that occurred on requests to the Kubernetes API server",
26 registers: [registry],
27 labelNames: apiMetricLabels,
28 });
29 }
30 wrap(method, fn) {
31 return __awaiter(this, void 0, void 0, function* () {
32 const timer = this.requestLatencies.startTimer({ method });
33 try {
34 return yield fn();
35 }
36 catch (err) {
37 this.errorCount.inc({ method });
38 throw err;
39 }
40 finally {
41 timer();
42 }
43 });
44 }
45 post(url, body) {
46 return this.wrap("post", () => this.inner.post(url, body));
47 }
48 put(url, body) {
49 return __awaiter(this, void 0, void 0, function* () {
50 return this.wrap("put", () => this.inner.put(url, body));
51 });
52 }
53 delete(url, opts, queryParams, body) {
54 return __awaiter(this, void 0, void 0, function* () {
55 return this.wrap("delete", () => this.inner.delete(url, opts, queryParams, body));
56 });
57 }
58 get(url, opts) {
59 return __awaiter(this, void 0, void 0, function* () {
60 return this.wrap("get", () => this.inner.get(url, opts));
61 });
62 }
63 patch(url, body, patchKind) {
64 return this.wrap("patch", () => this.inner.patch(url, body, patchKind));
65 }
66 watch(url, onUpdate, onError, opts) {
67 return this.wrap("watch", () => this.inner.watch(url, onUpdate, onError, opts));
68 }
69}
70exports.MonitoringKubernetesRESTClient = MonitoringKubernetesRESTClient;
71//# sourceMappingURL=client_monitoring.js.map
\No newline at end of file