Simplified metrics middleware and backend

This commit is contained in:
Daniel García Aubert
2020-04-27 12:46:27 +02:00
parent 6a2333be64
commit e90c196598
5 changed files with 18 additions and 32 deletions
+5 -2
View File
@@ -187,7 +187,7 @@ module.exports = class ApiRouter {
this.mapRouter = new MapRouter({ collaborators });
this.templateRouter = new TemplateRouter({ collaborators });
this.metadataBackend = metadataBackend;
this.pubSubMetricsBackend = PubSubMetricsBackend.build();
this.pubSubMetricsBackend = new PubSubMetricsBackend(this.serverOptions.pubSubMetrics);
}
route (app, routes) {
@@ -220,7 +220,10 @@ module.exports = class ApiRouter {
apiRouter.use(sendResponse());
apiRouter.use(syntaxError());
apiRouter.use(errorMiddleware());
apiRouter.use(pubSubMetrics(this.pubSubMetricsBackend));
apiRouter.use(pubSubMetrics({
enabled: this.serverOptions.pubSubMetrics.enabled,
metricsBackend: this.pubSubMetricsBackend
}));
paths.forEach(path => app.use(path, apiRouter));
});
+3 -3
View File
@@ -3,8 +3,8 @@
const EVENT_VERSION = '1';
const MAX_LENGTH = 100;
function pubSubMetrics (pubSubMetricsBackend) {
if (!pubSubMetricsBackend.isEnabled()) {
function pubSubMetrics ({ enabled, metricsBackend }) {
if (!enabled) {
return function pubSubMetricsDisabledMiddleware (req, res, next) {
next();
};
@@ -15,7 +15,7 @@ function pubSubMetrics (pubSubMetricsBackend) {
const { event, attributes } = getEventData(req, res);
if (event) {
pubSubMetricsBackend.sendEvent(event, attributes);
metricsBackend.send(event, attributes);
}
});