1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.MonitoringKubernetesRESTClient = void 0;
|
13 | const prom_client_1 = require("prom-client");
|
14 | const apiMetricLabels = ["method"];
|
15 | class MonitoringKubernetesRESTClient {
|
16 | constructor(inner, registry) {
|
17 | this.inner = inner;
|
18 | this.requestLatencies = new prom_client_1.Histogram({
|
19 | name: "kubernetes_api_request_latency_milliseconds",
|
20 | help: "Latency in milliseconds for requests to the Kubernetes API server",
|
21 | registers: [registry],
|
22 | labelNames: apiMetricLabels,
|
23 | });
|
24 | this.errorCount = new prom_client_1.Counter({
|
25 | name: "kubernetes_api_error_count",
|
26 | help: "Amount of errors that occurred on requests to the Kubernetes API server",
|
27 | registers: [registry],
|
28 | labelNames: apiMetricLabels,
|
29 | });
|
30 | }
|
31 | wrap(method, fn) {
|
32 | return __awaiter(this, void 0, void 0, function* () {
|
33 | const timer = this.requestLatencies.startTimer({ method });
|
34 | try {
|
35 | return yield fn();
|
36 | }
|
37 | catch (err) {
|
38 | this.errorCount.inc({ method });
|
39 | throw err;
|
40 | }
|
41 | finally {
|
42 | timer();
|
43 | }
|
44 | });
|
45 | }
|
46 | post(url, body) {
|
47 | return this.wrap("post", () => this.inner.post(url, body));
|
48 | }
|
49 | put(url, body) {
|
50 | return __awaiter(this, void 0, void 0, function* () {
|
51 | return this.wrap("put", () => this.inner.put(url, body));
|
52 | });
|
53 | }
|
54 | delete(url, opts, queryParams, body) {
|
55 | return __awaiter(this, void 0, void 0, function* () {
|
56 | return this.wrap("delete", () => this.inner.delete(url, opts, queryParams, body));
|
57 | });
|
58 | }
|
59 | get(url, opts) {
|
60 | return __awaiter(this, void 0, void 0, function* () {
|
61 | return this.wrap("get", () => this.inner.get(url, opts));
|
62 | });
|
63 | }
|
64 | patch(url, body, patchKind) {
|
65 | return this.wrap("patch", () => this.inner.patch(url, body, patchKind));
|
66 | }
|
67 | watch(url, onUpdate, onError, opts) {
|
68 | return this.wrap("watch", () => this.inner.watch(url, onUpdate, onError, opts));
|
69 | }
|
70 | }
|
71 | exports.MonitoringKubernetesRESTClient = MonitoringKubernetesRESTClient;
|
72 |
|
\ | No newline at end of file |