From 3f47646a17a385c2894460b711eaba1484e3c932 Mon Sep 17 00:00:00 2001 From: Aaron van Meerten Date: Tue, 26 Sep 2023 11:48:47 -0500 Subject: [PATCH] feature: endpoint to expose group metrics --- src/app.ts | 8 ++++++++ src/handlers.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/app.ts b/src/app.ts index bcc51f7..54d4639 100644 --- a/src/app.ts +++ b/src/app.ts @@ -467,6 +467,14 @@ app.get('/groups/:name/instance-audit', async (req, res, next) => { } }); +app.get('/groups/:name/group-metrics', async (req, res, next) => { + try { + await h.getGroupMetrics(req, res); + } catch (err) { + next(err); + } +}); + app.get('/groups/:name/group-audit', async (req, res, next) => { try { await h.getGroupAudit(req, res); diff --git a/src/handlers.ts b/src/handlers.ts index c38f70b..fde082f 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -417,6 +417,32 @@ class Handlers { res.send({ audit }); } + async getGroupMetrics(req: Request, res: Response): Promise { + const groupName = req.params.name; + const ctx = req.context; + const group = await this.instanceGroupManager.getInstanceGroup(groupName); + + if (!group) { + res.sendStatus(404); + return; + } + + const maxPeriodCount = Math.max( + group.scalingOptions.scaleUpPeriodsCount, + group.scalingOptions.scaleDownPeriodsCount, + ); + + const metrics = await this.instanceTracker.getMetricInventoryPerPeriod( + ctx, + groupName, + maxPeriodCount, + group.scalingOptions.scalePeriod, + ); + + res.status(200); + res.send({ metrics }); + } + async resetInstanceGroups(req: Request, res: Response): Promise { req.context.logger.info('Resetting instance groups'); const ctx = req.context;