Skip to content

Commit

Permalink
rotor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Dec 19, 2023
1 parent 899d89e commit 23888b1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions libs/core-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"juava": "workspace:*",
"lodash": "^4.17.21",
"mongodb": "^5.9.2",
"node-cache": "^5.1.2",
"@mongodb-js/zstd": "^1.2.0",
"ioredis": "^5.3.2",
"posthog-node": "^2.4.0",
Expand Down
4 changes: 2 additions & 2 deletions libs/core-functions/src/functions/lib/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MongoCreatedCollections = new Set<string>();
export function mongoAnonymousEventsStore(): AnonymousEventsStore {
return {
async addEvent(collectionName: string, anonymousId: string, event: AnalyticsServerEvent, ttlDays: number) {
const mongo = await mongodb.waitInit();
const mongo = mongodb();
await ensureMongoCollection(mongo, collectionName, ttlDays);
const res = await mongo
.db()
Expand All @@ -44,7 +44,7 @@ export function mongoAnonymousEventsStore(): AnonymousEventsStore {
},

async evictEvents(collectionName: string, anonymousId: string) {
const mongo = await mongodb.waitInit();
const mongo = mongodb();
// to ensure query consistency between find and delete query - limit them to the same time window
const maxObjectId = new ObjectId(Math.floor(new Date().getTime() / 1000).toString(16) + "0000000000000000");
// load anonymous events from user_recognition collection
Expand Down
14 changes: 14 additions & 0 deletions libs/core-functions/src/functions/lib/ua.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { UserAgent } from "@jitsu/protocols/functions";
import omit from "lodash/omit";
import uaParser from "@amplitude/ua-parser-js";
import NodeCache from "node-cache";

const BotUAKeywords = ["bot", "spider", "headless", "crawler", "uptimia"];
const uaCacheTTL = 60 * 10; // 10 min;
const uaCache = new NodeCache({ stdTTL: uaCacheTTL, checkperiod: 60, maxKeys: 10000 });

export function parseUserAgent(userAgent?: string): UserAgent {
if (!userAgent) {
return {} as UserAgent;
}
const cached = uaCache.get(userAgent);
if (cached) {
uaCache.ttl(userAgent, uaCacheTTL);
return cached as UserAgent;
}
const uas = userAgent || "";
const ua = omit(uaParser(uas), "ua") as UserAgent;
const lower = uas.toLowerCase();
ua.bot = BotUAKeywords.some(keyword => lower.includes(keyword));
if (ua.device) {
ua.device.type = ua.device.type || "desktop";
}
try {
uaCache.set(userAgent, ua);
} catch (e) {}
return ua;
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions services/rotor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FunctionsHandler, FunctionsHandlerMulti } from "./http/functions";
import { initMaxMindClient } from "./lib/maxmind";
import { rotorMessageHandler } from "./lib/message-handler";
import { redis } from "@jitsu-internal/console/lib/server/redis";
import { redisLogger } from "./lib/redis-logger";

export const log = getLog("rotor");

Expand Down Expand Up @@ -57,6 +58,7 @@ async function main() {
Prometheus.collectDefaultMetrics();
await mongodb.waitInit();
await redis.waitInit();
await redisLogger.waitInit();
rotor
.start()
.then(chMetrics => {
Expand Down
2 changes: 1 addition & 1 deletion services/rotor/src/lib/message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function rotorMessageHandler(
? createMultiStore(newStore, oldStore)
: oldStore;

const rl = await redisLogger.waitInit();
const rl = redisLogger();

const connectionData = connection.options as any;

Expand Down

1 comment on commit 23888b1

@vercel
Copy link

@vercel vercel bot commented on 23888b1 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

new-jitsu – ./webapps/console

ag.ru
logu.au
ozon.ru
sse.ere
erxes.io
baidu.dom
sambla.se
bobsec.com
sambla.com
agro4u.life
bluetick.ai
protontv.eu
t.quenti.io
alicesec.com
d.askloan.tw
dev.aclis.io
docs.dh19.de
docs.dh19.eu
joseviso.com
mydomain.dom
t.democo.dev
t.shoppub.io
t2.jitsu.com
timeplus.com
zoopsign.com
*.d.jitsu.com
beta.mitzu.io
d.versatus.io
data.light.so
data.loudy.co
data.schej.it
dog.jitsu.com
imusician.app
imusician.pro
jitsu.logu.au
jitsu.www1.ru
t.thequack.ai
thinkr.com.br
use.jitsu.com
usepolygon.io
www.sambla.se
ajewellers.com
data.uselog.io
gpt.whatfa.com
sidetrekai.com
t.papermark.io
t.saasmonk.app
use2.jitsu.com
www.kellen.top
*.dataspecc.com
events.mitzu.io
dataqa.investing.com
dev.blazingboost.com
j.israeladvocate.org
mercury.stagehub.com
store.sidetrekai.com
teslahenry.github.io
data.hogarlylabs.tech
data.your-company.com
event.clickncruise.hu
event.clickncruise.ro
test-domain.jitsu.com
test.bigfootproof.com
teste.fazcomex.com.br
analytics.dev.knekt.io
loraboutiquedental.com
notion.twelftree.co.uk
dev-portal.zoopsign.com
event.tradejobsnz.co.nz
investing-poc.jitsu.dev
savvy-replay.jitsu.tech
data.analytics-smart.com
data.handelsregister.app
event.clickncruise.co.uk
jt.fairhopeweb.github.io
savvy-replay2.jitsu.tech
savvy-replay3.jitsu.tech
savvy-replay4.jitsu.tech
track.alquimiaweb.com.br
track.pressance-group.jp
track.uniquecafes.com.br
colectha.agenciavoolu.com
kolectha.agenciavoolu.com
lp.loraboutiquedental.com
stage-portal.zoopsign.com
new-jitsu-jitsu.vercel.app
lodercom-colectha.voolu.shop
warehouse1.trendstyle.com.au
d0.livingdesignsfurniture.com
ingest-load-testing.jitsu.dev
jitsu.precisaosistemas.com.br
analytics.inspiresolutions.app
betteruptime-monitoring.jitsu.dev
canvas.livingdesignsfurniture.com
analytics.dev.inspiresolutions.app
cl9vt45z50001znkunc6v8fmm.d.jitsu.com
clm2jikrm00002v6r5l6niws3.d.jitsu.com
new-jitsu-git-newjitsu-jitsu.vercel.app
3000-rajaraodv-customerdemo-nmpsqwflswt.ws-us102.gitpod.io
new.jitsu.dev

Please sign in to comment.