From 9f9406037be4d6b4a73f6b36c5650c940631a349 Mon Sep 17 00:00:00 2001 From: Deepak Prabhakara Date: Fri, 16 Jun 2023 23:07:55 +0100 Subject: [PATCH] tweaks to turn off geo lookup --- deploy/Dockerfile-slim | 2 +- kustomize/base/cron-deployment.yaml | 5 +++++ src/_processor/persistence/geoip.ts | 3 ++- src/_processor/workers/updateGeoData.ts | 23 ++++++++++++----------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/deploy/Dockerfile-slim b/deploy/Dockerfile-slim index 226aa07ca..88bf47e7e 100644 --- a/deploy/Dockerfile-slim +++ b/deploy/Dockerfile-slim @@ -1,7 +1,7 @@ # # # # Cron build # -ARG NODEJS_IMAGE=node:18.15.0-alpine3.17 +ARG NODEJS_IMAGE=node:18.16-alpine3.17 ARG ALPINE_IMAGE=alpine:3.17 FROM --platform=${BUILDPLATFORM:-linux/amd64} $ALPINE_IMAGE as cron diff --git a/kustomize/base/cron-deployment.yaml b/kustomize/base/cron-deployment.yaml index daa0ff45c..ce211c117 100644 --- a/kustomize/base/cron-deployment.yaml +++ b/kustomize/base/cron-deployment.yaml @@ -35,6 +35,11 @@ spec: secretKeyRef: key: NSQD_HTTP_PORT name: auditlog + - name: RETRACED_DISABLE_GEOSYNC + valueFrom: + secretKeyRef: + key: RETRACED_DISABLE_GEOSYNC + name: auditlog resources: requests: cpu: 10m diff --git a/src/_processor/persistence/geoip.ts b/src/_processor/persistence/geoip.ts index d8945b3af..3e2fce1c6 100644 --- a/src/_processor/persistence/geoip.ts +++ b/src/_processor/persistence/geoip.ts @@ -1,10 +1,11 @@ import getPgPool from "../persistence/pg"; +import config from "../../config"; const pgPool = getPgPool(); export default function getLocationByIP(ipAddress) { return new Promise((resolve, reject) => { - if (!ipAddress) { + if (!ipAddress || config.RETRACED_DISABLE_GEOSYNC) { resolve(undefined); return; } diff --git a/src/_processor/workers/updateGeoData.ts b/src/_processor/workers/updateGeoData.ts index 80a43d382..ba47e7052 100644 --- a/src/_processor/workers/updateGeoData.ts +++ b/src/_processor/workers/updateGeoData.ts @@ -25,6 +25,11 @@ const ipv4FilePath = path.join(config.TMPDIR || "/tmp", ipv4FileName); const ipv6FilePath = path.join(config.TMPDIR || "/tmp", ipv6FileName); export default async function updateGeoData() { + if (config.RETRACED_DISABLE_GEOSYNC || !config.MAXMIND_GEOLITE2_LICENSE_KEY) { + logger.info("UpdateGeoData: GeoIP sync disabled"); + return; + } + // Use cached files if less than a day old. const downloadsNeeded = await Promise.all([ downloadNeeded(locFilePath), @@ -99,10 +104,7 @@ async function download() { async function write(pathname, stream) { return new Promise((resolve, reject) => { - stream - .pipe(fs.createWriteStream(pathname)) - .on("error", reject) - .on("finish", resolve); + stream.pipe(fs.createWriteStream(pathname)).on("error", reject).on("finish", resolve); }); } @@ -235,9 +237,9 @@ async function translateIPBlockData(csvReadStream, locations, date) { const valuesString = queuedValues .map((v, i) => { const offset = i * 8; - return `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${ - offset + 4 - }, $${offset + 5}, $${offset + 6}, $${offset + 7}, $${offset + 8})`; + return `($${offset + 1}, $${offset + 2}, $${offset + 3}, $${offset + 4}, $${offset + 5}, $${ + offset + 6 + }, $${offset + 7}, $${offset + 8})`; }) .join(","); @@ -253,8 +255,7 @@ async function translateIPBlockData(csvReadStream, locations, date) { // Delete geoip records not synced within two days of date. (If the job is // running at midnight some records from this batch could be 1 day old.) async function clean(date) { - await pgPool.query( - `delete from geoip where synced is null or synced < ($1::date - interval '2 days')`, - [date] - ); + await pgPool.query(`delete from geoip where synced is null or synced < ($1::date - interval '2 days')`, [ + date, + ]); }