Skip to content

Commit

Permalink
tweaks to turn off geo lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakprabhakara committed Jun 16, 2023
1 parent 0ff0b28 commit 9f94060
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deploy/Dockerfile-slim
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions kustomize/base/cron-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/_processor/persistence/geoip.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
23 changes: 12 additions & 11 deletions src/_processor/workers/updateGeoData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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(",");

Expand All @@ -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,
]);
}

0 comments on commit 9f94060

Please sign in to comment.