|
|
|
@ -2,34 +2,18 @@
|
|
|
|
|
|
|
|
|
|
const { PubSub } = require('@google-cloud/pubsub');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PubSubMetricsBackend
|
|
|
|
|
*/
|
|
|
|
|
class PubSubMetricsBackend {
|
|
|
|
|
module.exports = class PubSubMetricsBackend {
|
|
|
|
|
static build () {
|
|
|
|
|
if (!global.environment.pubSubMetrics || !global.environment.pubSubMetrics.enabled) {
|
|
|
|
|
return new PubSubMetricsBackend(undefined, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pubsub = PubSubMetricsBackend.createPubSub();
|
|
|
|
|
const { project_id: projectId, credentials: keyFilename } = global.environment.pubSubMetrics;
|
|
|
|
|
const pubsub = new PubSub({ projectId, keyFilename });
|
|
|
|
|
|
|
|
|
|
return new PubSubMetricsBackend(pubsub, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static createPubSub () {
|
|
|
|
|
const projectId = global.environment.pubSubMetrics.project_id;
|
|
|
|
|
const credentials = global.environment.pubSubMetrics.credentials;
|
|
|
|
|
const config = {};
|
|
|
|
|
|
|
|
|
|
if (projectId) {
|
|
|
|
|
config.projectId = projectId;
|
|
|
|
|
}
|
|
|
|
|
if (credentials) {
|
|
|
|
|
config.keyFilename = credentials;
|
|
|
|
|
}
|
|
|
|
|
return new PubSub(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor (pubSub, enabled) {
|
|
|
|
|
this.pubsub = pubSub;
|
|
|
|
|
this.enabled = enabled;
|
|
|
|
@ -62,5 +46,3 @@ class PubSubMetricsBackend {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = PubSubMetricsBackend;
|
|
|
|
|