From 6f4829e817b421be1dc8eb10a24d44f768369f7e Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 14 Aug 2020 00:41:21 +0200 Subject: [PATCH] [misc] fix module importing --- libraries/metrics/event_loop.js | 2 +- libraries/metrics/http.js | 2 +- libraries/metrics/{metrics.js => index.js} | 0 libraries/metrics/memory.js | 4 ++-- libraries/metrics/mongodb.js | 2 +- libraries/metrics/open_sockets.js | 4 ++-- libraries/metrics/test/unit/js/event_loop.js | 2 +- libraries/metrics/test/unit/js/timeAsyncMethodTests.js | 2 +- libraries/metrics/timeAsyncMethod.js | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) rename libraries/metrics/{metrics.js => index.js} (100%) diff --git a/libraries/metrics/event_loop.js b/libraries/metrics/event_loop.js index 58b0c732d2..5c4159ecb4 100644 --- a/libraries/metrics/event_loop.js +++ b/libraries/metrics/event_loop.js @@ -9,7 +9,7 @@ module.exports = (EventLoopMonitor = { monitor(logger, interval, log_threshold) { if (interval == null) { interval = 1000; } if (log_threshold == null) { log_threshold = 100; } - const Metrics = require("./metrics"); + const Metrics = require("./index"); // check for logger on startup to avoid exceptions later if undefined if ((logger == null)) { throw new Error("logger is undefined"); } // monitor delay in setInterval to detect event loop blocking diff --git a/libraries/metrics/http.js b/libraries/metrics/http.js index 34fde3c247..26db4b5507 100644 --- a/libraries/metrics/http.js +++ b/libraries/metrics/http.js @@ -11,7 +11,7 @@ const yn = require("yn"); const STACKDRIVER_LOGGING = yn(process.env['STACKDRIVER_LOGGING']); module.exports.monitor = logger => (function(req, res, next) { - const Metrics = require("./metrics"); + const Metrics = require("./index"); const startTime = process.hrtime(); const { end diff --git a/libraries/metrics/metrics.js b/libraries/metrics/index.js similarity index 100% rename from libraries/metrics/metrics.js rename to libraries/metrics/index.js diff --git a/libraries/metrics/memory.js b/libraries/metrics/memory.js index a068cad71d..2bcb7917d0 100644 --- a/libraries/metrics/memory.js +++ b/libraries/metrics/memory.js @@ -73,13 +73,13 @@ module.exports = (MemoryMonitor = { monitor(logger) { const interval = setInterval(() => MemoryMonitor.Check(logger) , oneMinute); - const Metrics = require("./metrics"); + const Metrics = require("./index"); return Metrics.registerDestructor(() => clearInterval(interval)); }, Check(logger) { let mem; - const Metrics = require("./metrics"); + const Metrics = require("./index"); const memBeforeGc = (mem = inMegaBytes(process.memoryUsage())); Metrics.gauge("memory.rss", mem.rss); Metrics.gauge("memory.heaptotal", mem.heapTotal); diff --git a/libraries/metrics/mongodb.js b/libraries/metrics/mongodb.js index edec01e421..230a8a4628 100644 --- a/libraries/metrics/mongodb.js +++ b/libraries/metrics/mongodb.js @@ -21,7 +21,7 @@ module.exports = { mongodbCore = require(v2_path); } catch (error1) {} - const Metrics = require("./metrics"); + const Metrics = require("./index"); const monitorMethod = function(base, method, type) { let _method; diff --git a/libraries/metrics/open_sockets.js b/libraries/metrics/open_sockets.js index 3232a8a851..fc7a11ec45 100644 --- a/libraries/metrics/open_sockets.js +++ b/libraries/metrics/open_sockets.js @@ -19,13 +19,13 @@ module.exports = (OpenSocketsMonitor = { monitor(logger) { const interval = setInterval(() => OpenSocketsMonitor.gaugeOpenSockets() , 5 * seconds); - const Metrics = require("./metrics"); + const Metrics = require("./index"); return Metrics.registerDestructor(() => clearInterval(interval)); }, gaugeOpenSockets() { let agents, hostname, url; - const Metrics = require("./metrics"); + const Metrics = require("./index"); const object = require('http').globalAgent.sockets; for (url in object) { agents = object[url]; diff --git a/libraries/metrics/test/unit/js/event_loop.js b/libraries/metrics/test/unit/js/event_loop.js index 7135287486..1791c0e216 100644 --- a/libraries/metrics/test/unit/js/event_loop.js +++ b/libraries/metrics/test/unit/js/event_loop.js @@ -24,7 +24,7 @@ describe('event_loop', function() { warn: sinon.stub() }; return this.event_loop = SandboxedModule.require(modulePath, { requires: { - './metrics': this.metrics + './index': this.metrics } } ); diff --git a/libraries/metrics/test/unit/js/timeAsyncMethodTests.js b/libraries/metrics/test/unit/js/timeAsyncMethodTests.js index 36bdb02cfa..de252acae4 100644 --- a/libraries/metrics/test/unit/js/timeAsyncMethodTests.js +++ b/libraries/metrics/test/unit/js/timeAsyncMethodTests.js @@ -25,7 +25,7 @@ describe('timeAsyncMethod', function() { inc: sinon.stub() }; this.timeAsyncMethod = SandboxedModule.require(modulePath, { requires: { - './metrics': this.metrics + './index': this.metrics } } ); diff --git a/libraries/metrics/timeAsyncMethod.js b/libraries/metrics/timeAsyncMethod.js index ddb2149859..b096cc6851 100644 --- a/libraries/metrics/timeAsyncMethod.js +++ b/libraries/metrics/timeAsyncMethod.js @@ -9,7 +9,7 @@ module.exports = function(obj, methodName, prefix, logger) { let modifedMethodName; - const metrics = require('./metrics'); + const metrics = require('./index'); if (typeof obj[methodName] !== 'function') { throw new Error(`[Metrics] expected object property '${methodName}' to be a function`);