Simplified metrics middleware and backend
This commit is contained in:
@@ -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,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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user