mirror of
https://github.com/alexgo-io/redstone-cache-layer.git
synced 2026-01-12 16:53:15 +08:00
Revert "chore: disabled metrics endpoint"
This reverts commit 833a964337.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import express from "express";
|
||||
import { prices } from "./prices";
|
||||
import { packages } from "./packages";
|
||||
import { metrics } from "./metrics";
|
||||
import { errors } from "./errors";
|
||||
import { configs } from "./configs";
|
||||
import { providers } from "./providers";
|
||||
import { enableLiteMode } from "../config";
|
||||
|
||||
export const getRouter = () => {
|
||||
const router = express.Router();
|
||||
const router = express.Router();
|
||||
|
||||
prices(router);
|
||||
packages(router);
|
||||
@@ -15,6 +16,7 @@ export const getRouter = () => {
|
||||
providers(router);
|
||||
|
||||
if (!enableLiteMode) {
|
||||
metrics(router);
|
||||
errors(router);
|
||||
}
|
||||
|
||||
|
||||
20
routes/metrics.ts
Normal file
20
routes/metrics.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Router } from "express";
|
||||
import asyncHandler from "express-async-handler";
|
||||
import { saveMetric } from "../helpers/cloudwatch";
|
||||
|
||||
export const metrics = (router: Router) => {
|
||||
|
||||
/**
|
||||
* This endpoint is used for saving metric values in AWS Cloudwatch.
|
||||
* Thanks to them we can analyse redstone-node performance and build
|
||||
* nice charts
|
||||
*/
|
||||
router.post("/metrics", asyncHandler(async (req, res) => {
|
||||
const { label, value } = req.body;
|
||||
await saveMetric({ label, value });
|
||||
|
||||
return res.json({
|
||||
msg: "Metric saved",
|
||||
});
|
||||
}));
|
||||
};
|
||||
29
test/routes/metrics.test.ts
Normal file
29
test/routes/metrics.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
process.env.LIGHT_MODE = "false";
|
||||
import request from "supertest";
|
||||
import { app } from "../../app";
|
||||
import { connect, closeDatabase } from "../helpers/test-db";
|
||||
import * as cloudwatch from "../../helpers/cloudwatch";
|
||||
|
||||
describe("Testing metrics route", () => {
|
||||
beforeAll(async () => await connect());
|
||||
afterAll(async () => await closeDatabase());
|
||||
|
||||
const testMetricValue = {
|
||||
label: "test-metric",
|
||||
value: 42,
|
||||
};
|
||||
|
||||
test("Should post a test metric", async () => {
|
||||
// Given
|
||||
const spy = jest.spyOn(cloudwatch, "saveMetric");
|
||||
|
||||
// When
|
||||
await request(app)
|
||||
.post("/metrics")
|
||||
.send(testMetricValue)
|
||||
.expect(200);
|
||||
|
||||
// Then
|
||||
expect(spy).toHaveBeenCalledWith(testMetricValue);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user