@webda/core
Version:
Expose API with Lambda
57 lines • 2.77 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { suite, test } from "@testdeck/mocha";
import * as assert from "assert";
import axios from "axios";
import { Histogram } from "prom-client";
import { WebdaTest } from "../test.js";
import { HttpContext } from "../utils/httpcontext.js";
import { PrometheusService } from "./prometheus.js";
let PrometheusTest = class PrometheusTest extends WebdaTest {
async sideServe() {
let service = new PrometheusService(this.webda, "", {
portNumber: 9090,
includeNodeMetrics: false,
includeRequestMetrics: false
});
try {
await service.resolve().init();
// Should be listen on 9090 now
let res = await axios.get("http://localhost:9090/metrics");
assert.ok(res.data.includes("webda_filequeue_messages_pending"));
await assert.rejects(() => axios.get("http://localhost:9090/metrics2"), /Request failed with status code 404/);
}
finally {
service.http?.close();
}
}
async normal() {
let ctx = await this.newContext("toto");
ctx.setHttpContext(new HttpContext("localhost", "GET", "/version"));
await this.webda.emitSync("Webda.Request", { context: ctx });
await this.webda.emitSync("Webda.Result", { context: ctx });
ctx.setHttpContext(new HttpContext("localhost", "PUT", "/version"));
await this.webda.emitSync("Webda.Request", { context: ctx });
await this.webda.emitSync("Webda.Result", { context: ctx });
await this.execute(ctx, "localhost", "GET", "/metrics");
await this.webda.emitSync("Webda.Request", { context: ctx });
await this.webda.emitSync("Webda.Result", { context: ctx });
this.webda.getGlobalParams().metrics = false;
// Fake metrics should return 0 for timer
assert.strictEqual(this.webda.getMetric(Histogram, { name: "test", help: "fake" }).startTimer()(), 0);
}
};
__decorate([
test
], PrometheusTest.prototype, "sideServe", null);
__decorate([
test
], PrometheusTest.prototype, "normal", null);
PrometheusTest = __decorate([
suite
], PrometheusTest);
//# sourceMappingURL=prometheus.spec.js.map