Revert "chore: disabled metrics endpoint"

This reverts commit 833a964337.
This commit is contained in:
hatskier
2022-07-07 17:59:09 +02:00
parent 833a964337
commit 71efa599d4
3 changed files with 52 additions and 1 deletions

View File

@@ -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
View 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",
});
}));
};

View 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);
});
});