From e99071d4f7b4a311b142b50d0a4a041f3f3c8fc5 Mon Sep 17 00:00:00 2001 From: jmoguilevsky Date: Fri, 16 Apr 2021 16:58:06 -0300 Subject: [PATCH] set gamma to 0.0003 and parametrize it (#82) --- graph-service/package.json | 3 ++- graph-service/src/ewma-utilities/ewma.test.ts | 4 ++-- graph-service/src/ewma-utilities/ewma.ts | 6 +++--- graph-service/src/middlewares.ts | 6 +++--- graph-service/src/testing_tools/process_topologies.ts | 2 +- graph-service/src/testing_tools/requests.http | 4 ++-- metrics-processor/src/ewma.ts | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/graph-service/package.json b/graph-service/package.json index d976502..c4bdc92 100644 --- a/graph-service/package.json +++ b/graph-service/package.json @@ -11,7 +11,8 @@ "start:prod": "node ./build/app.js", "test:local": "NEO4J_HOST=neo4j://neo4j:7687 npm run test", "test": "npm run build-helpers && npm run build && npm run test:unit", - "test:unit": "jest --forceExit --detectOpenHandles --coverage --verbose" + "test:unit": "jest --forceExit --detectOpenHandles --coverage --verbose", + "test:watch": "jest --watch" }, "author": "", "license": "BSD-3-Clause", diff --git a/graph-service/src/ewma-utilities/ewma.test.ts b/graph-service/src/ewma-utilities/ewma.test.ts index 28d5adc..4ff9bc6 100644 --- a/graph-service/src/ewma-utilities/ewma.test.ts +++ b/graph-service/src/ewma-utilities/ewma.test.ts @@ -33,8 +33,8 @@ describe("EWMA helpers", () => { // tslint:disable-next-line:prefer-for-of for (let index = 0; index < values.length; index++) { - lastEWMA = EWMA(values[index], lastEWMA); - lastEWMASquare = EWMA(Math.pow(values[index], 2), lastEWMASquare); + lastEWMA = EWMA(values[index], lastEWMA, 0.1); + lastEWMASquare = EWMA(Math.pow(values[index], 2), lastEWMASquare, 0.1); } result = EWMAStdDeviation(lastEWMASquare, lastEWMA); diff --git a/graph-service/src/ewma-utilities/ewma.ts b/graph-service/src/ewma-utilities/ewma.ts index f4f2e85..89af46e 100644 --- a/graph-service/src/ewma-utilities/ewma.ts +++ b/graph-service/src/ewma-utilities/ewma.ts @@ -1,4 +1,4 @@ -export const GAMMA = 0.1; +export const GAMMA = 0.0003; /** * Calculates the EWMA at a time T, given the EWMA value at time T - 1 and the measure at time T @@ -7,8 +7,8 @@ export const GAMMA = 0.1; * @param Yt - Measure at time T * @param previousEWMA - EWMA at time T - 1 */ -export function EWMA(Yt: number, previousEWMA: number): number { - return GAMMA * Yt + previousEWMA * (1 - GAMMA); +export function EWMA(Yt: number, previousEWMA: number, gamma: number = GAMMA): number { + return gamma * Yt + previousEWMA * (1 - gamma); } /** diff --git a/graph-service/src/middlewares.ts b/graph-service/src/middlewares.ts index 5c8a06b..8cc78e9 100644 --- a/graph-service/src/middlewares.ts +++ b/graph-service/src/middlewares.ts @@ -3,14 +3,14 @@ import { logger } from "helpers"; // tslint:disable-next-line: typedef export function logging(req, res, next) { - logger.debug(`${coerceReqTrace(req)} => ${coerceReqDetails(req)}`); + // logger.debug(`${coerceReqTrace(req)} => ${coerceReqDetails(req)}`); req._startTime = Date.now(); const originalSend = res.send; res.send = (body: any): express.Response => { if (res.statusCode < 400) { const duration = Date.now() - res.req._startTime; - logger.debug(`${coerceReqTrace(res.req)} <= ${res.statusCode} after ${duration}ms with ${toJSON(body)}`); + // logger.debug(`${coerceReqTrace(res.req)} <= ${res.statusCode} after ${duration}ms with ${toJSON(body)}`); } return originalSend.call(res, body); }; @@ -22,7 +22,7 @@ export function logging(req, res, next) { export function globalErrorHandling(err, req, res, _) { const status = err.status || 500; - logger.error(`${coerceReqTrace(req)} ${err.stack}`); + // logger.error(`${coerceReqTrace(req)} ${err.stack}`); res.status(status).json({ status, diff --git a/graph-service/src/testing_tools/process_topologies.ts b/graph-service/src/testing_tools/process_topologies.ts index 8d3a695..85da0a8 100644 --- a/graph-service/src/testing_tools/process_topologies.ts +++ b/graph-service/src/testing_tools/process_topologies.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import graphService = require("./service"); +import graphService = require("../service"); import fs = require("fs"); import { util } from "prettier"; import { inspect } from "util"; diff --git a/graph-service/src/testing_tools/requests.http b/graph-service/src/testing_tools/requests.http index 6b2e230..809bc50 100644 --- a/graph-service/src/testing_tools/requests.http +++ b/graph-service/src/testing_tools/requests.http @@ -92,8 +92,8 @@ PATCH {{base}}/graph/components/status Content-Type: application/json { - "component": "J", - "status": "CONFIRMED" + "component": "B", + "status": "NORMAL" } ### diff --git a/metrics-processor/src/ewma.ts b/metrics-processor/src/ewma.ts index 0d5acfb..d819ea2 100644 --- a/metrics-processor/src/ewma.ts +++ b/metrics-processor/src/ewma.ts @@ -1,4 +1,4 @@ -export const GAMMA = 0.3; +export const GAMMA = 0.0003; /** * Calculates the EWMA at a time T, given the EWMA value at time T - 1 and the measure at time T