From 733f3fc0977563d75cebfa65c6bc956719e3f211 Mon Sep 17 00:00:00 2001 From: Ivo Augusto Wanderley de Paiva <40743787+ivomastre@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:57:45 -0300 Subject: [PATCH] fix: eslint errors --- .eslintrc | 2 ++ lib/http/routers/FunctionsRouter.js | 8 +++---- lib/http/routes.js | 2 +- lib/support/config.js | 2 +- lib/support/opentelemetry.js | 36 ++++++++++++++--------------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.eslintrc b/.eslintrc index bef4b19..a562dfb 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,5 @@ extends: airbnb rules: no-param-reassign: [error, { props: false }] + no-unused-vars: [2, {args: after-used, argsIgnorePattern: "_"}] + new-cap: 0 diff --git a/lib/http/routers/FunctionsRouter.js b/lib/http/routers/FunctionsRouter.js index 818f553..f1f4bb5 100644 --- a/lib/http/routers/FunctionsRouter.js +++ b/lib/http/routers/FunctionsRouter.js @@ -17,7 +17,7 @@ const SchemaResponse = require('../SchemaResponse'); const router = new Router(); const { bodyParserLimit } = require('../../support/config'); const { reportError } = require('../../support/tracing'); -const { RecordOtelError } = require('../../support/opentelemetry') +const { RecordOtelError } = require('../../support/opentelemetry'); function codeFileName(namespace, codeId) { return `${namespace}/${codeId}.js`; @@ -195,7 +195,7 @@ router.delete('/:namespace/:id', async (req, res, next) => { }); -router.all('/:namespace/:id/run', bodyParser.json({ limit: bodyParserLimit }), async (req, res, next) => { +router.all('/:namespace/:id/run', bodyParser.json({ limit: bodyParserLimit }), async (req, res, _) => { const { namespace, id } = req.params; const memoryStorage = req.app.get('memoryStorage'); const sandbox = req.app.get('sandbox'); @@ -277,7 +277,7 @@ router.all('/:namespace/:id/run', bodyParser.json({ limit: bodyParserLimit }), a code: code.code, }); errTracker.notify(err); - RecordOtelError(err) + RecordOtelError(err); } }); @@ -336,7 +336,7 @@ router.put('/pipeline', bodyParser.json({ limit: bodyParserLimit }), async (req, res.json(result.body); } catch (err) { reportError(span, err); - RecordOtelError(err) + RecordOtelError(err); const status = err.statusCode || 500; metric.observePipelineRun(status); res.status(status).json({ error: err.message }); diff --git a/lib/http/routes.js b/lib/http/routes.js index da8fae5..f0255c7 100644 --- a/lib/http/routes.js +++ b/lib/http/routes.js @@ -33,7 +33,7 @@ morgan.token('response-sectime', (req, res) => { return secs.toFixed(3); }); const app = express(); -const traceEngine = config.trace.engine +const traceEngine = config.trace.engine; app.use(morgan(config.log.morganFormat)); app.use(expressOpentracing.default({ tracer })); diff --git a/lib/support/config.js b/lib/support/config.js index d7bb50f..2c01d74 100644 --- a/lib/support/config.js +++ b/lib/support/config.js @@ -11,7 +11,7 @@ const DEFAULT_GLOBAL_MODULES = [ ]; module.exports = { - host: process.env.HOSTNAME || "localhost", + host: process.env.HOSTNAME || 'localhost', port: ConfigDiscovery.getInt('PORT', 8100), metricsPort: ConfigDiscovery.getInt('METRICS_PORT', 8101), useNodeCluster: ConfigDiscovery.getBool('USE_NODE_CLUSTER', true), diff --git a/lib/support/opentelemetry.js b/lib/support/opentelemetry.js index d76884e..40c9b80 100644 --- a/lib/support/opentelemetry.js +++ b/lib/support/opentelemetry.js @@ -4,26 +4,26 @@ const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-expre const { registerInstrumentations } = require('@opentelemetry/instrumentation'); const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector-grpc'); const { NodeTracerProvider } = require('@opentelemetry/node'); -const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis') -const config = require('./config') - +const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis'); +const config = require('./config'); const opentelemetry = require('@opentelemetry/api'); + const OtelConfig = config.trace.otel; -const HOST = config.host +const HOST = config.host; const collectorOptions = { - serviceName: OtelConfig.service, - url: `${OtelConfig.collector.host}:${OtelConfig.collector.port}`, - concurrencyLimit: 10 -} + serviceName: OtelConfig.service, + url: `${OtelConfig.collector.host}:${OtelConfig.collector.port}`, + concurrencyLimit: 10, +}; const provider = new NodeTracerProvider(); provider.resource = provider.resource.merge({ attributes: { - "service.instance.id": HOST - } -}) + 'service.instance.id': HOST, + }, +}); const exporter = new CollectorTraceExporter(collectorOptions); provider.addSpanProcessor(new BatchSpanProcessor(exporter, { @@ -39,11 +39,11 @@ registerInstrumentations({ span.updateName(`${attrs['http.method']} ${attrs['http.target']}`); span.setAttribute('functions.route', attrs['http.route']); span.setAttribute('functions.url', attrs['http.url']); - }, + }, ignoreOutgoingUrls: [/.*\/agent_listener/, /.*\/sampling/], - ignoreIncomingPaths: [/.*\/healthcheck/, /.*\/metrics/, /.*\/sampling/] + ignoreIncomingPaths: [/.*\/healthcheck/, /.*\/metrics/, /.*\/sampling/], }), - new ExpressInstrumentation() + new ExpressInstrumentation(), ], }); @@ -63,10 +63,10 @@ function FinalizeSpanMiddleware(req, res, next) { } function RecordOtelError(err) { - const span = tracer.startSpan('Exception Throwed') - span.recordException(err.stack) - span.setStatus({code: opentelemetry.SpanStatusCode.ERROR }) - span.end() + const span = tracer.startSpan('Exception Throwed'); + span.recordException(err.stack); + span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR }); + span.end(); } module.exports = { StartSpanMiddleware, FinalizeSpanMiddleware, RecordOtelError };