Avoid to use "pubsub" for the name of modules, middlewares, variables, etc..
This commit is contained in:
parent
4e3ef96374
commit
70f0b6ea50
@ -21,7 +21,7 @@ const OverviewsMetadataBackend = require('../backends/overviews-metadata');
|
||||
const FilterStatsApi = require('../backends/filter-stats');
|
||||
const TablesExtentBackend = require('../backends/tables-extent');
|
||||
const ClusterBackend = require('../backends/cluster');
|
||||
const PubSubMetricsBackend = require('../backends/pubsub-metrics');
|
||||
const PubSubMetricsBackend = require('../backends/metrics');
|
||||
|
||||
const LayergroupAffectedTablesCache = require('../cache/layergroup-affected-tables');
|
||||
const SurrogateKeysCache = require('../cache/surrogate-keys-cache');
|
||||
|
@ -23,7 +23,7 @@ const mapError = require('../middlewares/map-error');
|
||||
const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider');
|
||||
const rateLimit = require('../middlewares/rate-limit');
|
||||
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
||||
const metrics = require('../middlewares/pubsub-metrics');
|
||||
const metrics = require('../middlewares/metrics');
|
||||
|
||||
module.exports = class AnonymousMapController {
|
||||
/**
|
||||
|
@ -12,7 +12,7 @@ const lastModifiedHeader = require('../middlewares/last-modified-header');
|
||||
const checkStaticImageFormat = require('../middlewares/check-static-image-format');
|
||||
const rateLimit = require('../middlewares/rate-limit');
|
||||
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
||||
const metrics = require('../middlewares/pubsub-metrics');
|
||||
const metrics = require('../middlewares/metrics');
|
||||
|
||||
const DEFAULT_ZOOM_CENTER = {
|
||||
zoom: 1,
|
||||
|
@ -3,9 +3,9 @@
|
||||
const EVENT_VERSION = '1';
|
||||
const MAX_LENGTH = 100;
|
||||
|
||||
module.exports = function pubSubMetrics ({ enabled, metricsBackend, logger, tags }) {
|
||||
module.exports = function metrics ({ enabled, metricsBackend, logger, tags }) {
|
||||
if (!enabled) {
|
||||
return function pubSubMetricsDisabledMiddleware (req, res, next) {
|
||||
return function metricsDisabledMiddleware (req, res, next) {
|
||||
next();
|
||||
};
|
||||
}
|
||||
@ -14,13 +14,13 @@ module.exports = function pubSubMetrics ({ enabled, metricsBackend, logger, tags
|
||||
throw new Error('Missing required "event" parameter to report metrics');
|
||||
}
|
||||
|
||||
return function pubSubMetricsMiddleware (req, res, next) {
|
||||
return function metricsMiddleware (req, res, next) {
|
||||
res.on('finish', () => {
|
||||
const { event, attributes } = getEventData(req, res, tags);
|
||||
|
||||
metricsBackend.send(event, attributes)
|
||||
.then(() => logger.debug(`PubSubTracker: event '${event}' published succesfully`))
|
||||
.catch((error) => logger.error(`ERROR: pubsub middleware failed to publish event '${event}': ${error.message}`));
|
||||
.then(() => logger.debug(`Event "${event}" published succesfully`))
|
||||
.catch((error) => logger.error(`Failed to publish event "${event}": ${error.message}`));
|
||||
});
|
||||
|
||||
return next();
|
@ -21,7 +21,7 @@ const NamedMapMapConfigProvider = require('../../models/mapconfig/provider/named
|
||||
const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider');
|
||||
const rateLimit = require('../middlewares/rate-limit');
|
||||
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
||||
const metrics = require('../middlewares/pubsub-metrics');
|
||||
const metrics = require('../middlewares/metrics');
|
||||
|
||||
module.exports = class NamedMapController {
|
||||
/**
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
const { PubSub } = require('@google-cloud/pubsub');
|
||||
|
||||
module.exports = class PubSubMetricsBackend {
|
||||
module.exports = class MetricsBackend {
|
||||
constructor (options = {}) {
|
||||
const { project_id: projectId, credentials: keyFilename, topic } = options;
|
||||
|
||||
this._pubsub = new PubSub({ projectId, keyFilename });
|
||||
this._metricsClient = new PubSub({ projectId, keyFilename });
|
||||
this._topicName = topic;
|
||||
}
|
||||
|
||||
send (event, attributes) {
|
||||
const data = Buffer.from(event);
|
||||
return this._pubsub.topic(this._topicName).publish(data, attributes);
|
||||
return this._metricsClient.topic(this._topicName).publish(data, attributes);
|
||||
}
|
||||
};
|
@ -2,7 +2,7 @@
|
||||
|
||||
const assert = require('assert');
|
||||
const TestClient = require('../support/test-client');
|
||||
const PubSubMetricsBackend = require('../../lib/backends/pubsub-metrics');
|
||||
const MetricsBackend = require('../../lib/backends/metrics');
|
||||
const apikey = 1234;
|
||||
const mapConfig = {
|
||||
version: '1.8.0',
|
||||
@ -37,11 +37,11 @@ function templateBuilder ({ name }) {
|
||||
};
|
||||
};
|
||||
|
||||
describe('pubsub metrics middleware', function () {
|
||||
describe('metrics middleware', function () {
|
||||
beforeEach(function () {
|
||||
this.originalPubSubMetricsBackendSendMethod = PubSubMetricsBackend.prototype.send;
|
||||
this.originalMetricsBackendSendMethod = MetricsBackend.prototype.send;
|
||||
this.pubSubMetricsBackendSendMethodCalled = false;
|
||||
PubSubMetricsBackend.prototype.send = (event, attributes) => {
|
||||
MetricsBackend.prototype.send = (event, attributes) => {
|
||||
this.pubSubMetricsBackendSendMethodCalled = true;
|
||||
this.pubSubMetricsBackendSendMethodCalledWith = { event, attributes };
|
||||
return Promise.resolve();
|
||||
@ -49,7 +49,7 @@ describe('pubsub metrics middleware', function () {
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
PubSubMetricsBackend.prototype.send = this.originalPubSubMetricsBackendSendMethod;
|
||||
MetricsBackend.prototype.send = this.originalMetricsBackendSendMethod;
|
||||
});
|
||||
|
||||
it('should not send event if not enabled', function (done) {
|
Loading…
Reference in New Issue
Block a user