diff --git a/cloudrun-malware-scanner/logger.js b/cloudrun-malware-scanner/logger.js index cd85fb1..6c1674d 100644 --- a/cloudrun-malware-scanner/logger.js +++ b/cloudrun-malware-scanner/logger.js @@ -24,8 +24,8 @@ const pkgJson = require('./package.json'); const loggingBunyan = new LoggingBunyan({ redirectToStdout: true, projectId: process.env.PROJECT_ID, - logName: "malware-scanner", - useMessageField: false + logName: 'malware-scanner', + useMessageField: false, }); exports.logger = bunyan.createLogger({ diff --git a/cloudrun-malware-scanner/metrics.js b/cloudrun-malware-scanner/metrics.js index d2a578e..8239807 100644 --- a/cloudrun-malware-scanner/metrics.js +++ b/cloudrun-malware-scanner/metrics.js @@ -98,21 +98,21 @@ function writeScanCompletedMetric_(measure, sourceBucket, destinationBucket, /** * Writes metrics when a CVD Mirror Update occurs. - * + * * @param {boolean} success * @param {boolean} isUpdated */ - function writeCvdMirrorUpdatedMetric(success, isUpdated) { +function writeCvdMirrorUpdatedMetric(success, isUpdated) { const tags = new TagMap(); tags.set(TAGS.cloudRunRevision, {value: process.env.K_REVISION}); - tags.set(TAGS.cvdUpdateStatus, - {value: ( + tags.set(TAGS.cvdUpdateStatus, + {value: ( success ? ( - isUpdated ? "SUCCESS_UPDATED" : "SUCCESS_NO_UPDATES" ) - : "FAILURE" )}); + isUpdated ? 'SUCCESS_UPDATED' : 'SUCCESS_NO_UPDATES' ) : + 'FAILURE' )}); globalStats.record( - [{ measure: METRICS.cvdUpdates, value: 1}], - tags); + [{measure: METRICS.cvdUpdates, value: 1}], + tags); } /** @@ -134,8 +134,8 @@ async function initMetrics(projectId) { TAGS.clamVersion, TAGS.cloudRunRevision, TAGS.sourceBucket, - TAGS.destinationBucket - ] + TAGS.destinationBucket, + ]; METRICS.cleanFiles = globalStats.createMeasureInt64( METRIC_TYPE_ROOT + 'clean-files', MeasureUnit.UNIT, @@ -183,7 +183,8 @@ async function initMetrics(projectId) { 'The scan duration in milliseconds'); const scanDurationView = globalStats.createView( METRICS.scanDuration.name, METRICS.scanDuration, - AggregationType.DISTRIBUTION, fileScanTags, 'Duration spent scanning files', + AggregationType.DISTRIBUTION, fileScanTags, + 'Duration spent scanning files', // Bucket Boundaries in ms [ 0, @@ -203,12 +204,12 @@ async function initMetrics(projectId) { globalStats.registerView(scanDurationView); METRICS.cvdUpdates = globalStats.createMeasureInt64( - METRIC_TYPE_ROOT + 'cvd-mirror-updates', MeasureUnit.UNIT, - 'Number of CVD mirror Update Checks performed'); + METRIC_TYPE_ROOT + 'cvd-mirror-updates', MeasureUnit.UNIT, + 'Number of CVD mirror Update Checks performed'); const cvdUpdatesView = globalStats.createView( METRICS.cvdUpdates.name, METRICS.cvdUpdates, - AggregationType.COUNT, + AggregationType.COUNT, [TAGS.cloudRunRevision, TAGS.cvdUpdateStatus], 'Number of CVD mirror update checks performed with their status'); globalStats.registerView(cvdUpdatesView); diff --git a/cloudrun-malware-scanner/server.js b/cloudrun-malware-scanner/server.js index d28168d..b1bb401 100644 --- a/cloudrun-malware-scanner/server.js +++ b/cloudrun-malware-scanner/server.js @@ -17,7 +17,6 @@ const clamd = require('clamdjs'); const express = require('express'); const {Storage} = require('@google-cloud/storage'); -const {ApiError} = require('@google-cloud/common'); const {GoogleAuth} = require('google-auth-library'); const {logger} = require('./logger.js'); const pkgJson = require('./package.json'); @@ -327,7 +326,7 @@ async function moveProcessedFile(filename, isClean, config) { */ async function readAndVerifyConfig(configFile) { logger.info(`Using configuration file: ${configFile}`); - + try { const config = require(configFile); delete config.comments; @@ -443,10 +442,10 @@ async function run() { await metrics.init(projectId); let configFile; - if(process.argv.length >= 3) { + if (process.argv.length >= 3) { configFile = process.argv[2]; } else { - configFile = "./config.json" + configFile = './config.json'; } await readAndVerifyConfig(configFile); process.exit(1);