Skip to content

Commit

Permalink
remove redis param in redisCount
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Nov 20, 2024
1 parent d8e4d4d commit 0b75fe6
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 73 deletions.
1 change: 0 additions & 1 deletion dev/backfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async function scanApi() {
// unretryable steam error
// if (err?.result?.status === 2) {
// nextSeqNum += 1;
// redisCount(redis, 'skip_seq_num');
// // continue with next seq num
// continue;
// } else {
Expand Down
3 changes: 1 addition & 2 deletions dev/legacyArchive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import crypto from 'crypto';
import cassandra from '../store/cassandra';
import redis from '../store/redis';
import config from '../config';
import db from '../store/db';
import { deserialize, redisCount } from '../util/utility';
Expand Down Expand Up @@ -90,7 +89,7 @@ async function doArchiveFromLegacy(matchId: number) {
JSON.stringify({ ...match, players: match.players || playerMatches }),
);
const result = await matchArchive.archivePut(matchId.toString(), blob);
redisCount(redis, 'match_archive_write');
redisCount('match_archive_write');
if (result) {
// Mark the match archived
await db.raw(
Expand Down
3 changes: 1 addition & 2 deletions routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Router } from 'express';
import { FilterType, filterDeps } from '../util/filter';
import spec from './spec';
import db from '../store/db';
import redis from '../store/redis';
import { alwaysCols } from './playerFields';
import { queryParamToArray, redisCount } from '../util/utility';

Expand Down Expand Up @@ -50,7 +49,7 @@ api.use('/players/:account_id/:info?', async (req, res, cb) => {
const isSelf =
Number(req.user?.account_id) === Number(req.params.account_id);
if (isSelf) {
redisCount(redis, 'self_profile_view');
redisCount('self_profile_view');
}
const isPrivate =
Boolean(privacy.rows[0]?.fh_unavailable) &&
Expand Down
2 changes: 1 addition & 1 deletion routes/keyManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ keys
Number(req.user?.account_id) >
threshold.account_id - Number(config.API_KEY_GEN_THRESHOLD);
if (fail) {
redisCount(redis, 'gen_api_key_invalid');
redisCount('gen_api_key_invalid');
return res.sendStatus(400).json({ error: 'Failed validation' });
}
}
Expand Down
10 changes: 5 additions & 5 deletions routes/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ Without a key, you can make 2,000 free calls per day at a rate limit of 60 reque
config.NODE_ENV !== 'development' &&
(await redis.get('fh_queue:' + playerId))
) {
redisCount(redis, 'fullhistory_skip');
redisCount('fullhistory_skip');
return res.json({ length: 0 });
}
const length = await addJob({
Expand Down Expand Up @@ -1517,12 +1517,12 @@ Without a key, you can make 2,000 free calls per day at a rate limit of 60 reque
// We validated the ID in middleware
const matchId = req.params.match_id;
// Count this request
redisCount(redis, 'request');
redisCountDistinct(redis, 'distinct_request', matchId);
redisCount('request');
redisCountDistinct('distinct_request', matchId);
let priority = 1;
if (req.query.api_key) {
priority = 1;
redisCount(redis, 'request_api_key');
redisCount('request_api_key');
redis.zincrby(
'request_usage_count',
1,
Expand All @@ -1537,7 +1537,7 @@ Without a key, you can make 2,000 free calls per day at a rate limit of 60 reque
if (req.headers.origin === config.UI_HOST) {
// Give UI requests priority
priority = 0;
redisCount(redis, 'request_ui');
redisCount('request_ui');
}
if (
req.user?.account_id &&
Expand Down
4 changes: 2 additions & 2 deletions store/buildMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function buildMatch(
const key = `match:${matchId}`;
const reply = await redis.get(key);
if (reply) {
redisCount(redis, 'match_cache_hit');
redisCount('match_cache_hit');
return JSON.parse(reply);
}

Expand All @@ -114,7 +114,7 @@ async function buildMatch(
return null;
}
match.od_data = odData;
redisCount(redis, 'build_match');
redisCount('build_match');
let playersMatchData: (Player | ParsedPlayer)[] = match.players;
// Get names, last login for players from DB
playersMatchData = await Promise.all(
Expand Down
6 changes: 2 additions & 4 deletions store/getApiData.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import config from '../config';
import { generateJob, getSteamAPIData, redisCount } from '../util/utility';
import { redisCount } from '../util/utility';
import { Archive } from './archive';
import cassandra from './cassandra';
import { insertMatch } from './insert';
import { getPGroup, type ApiMatch } from './pgroup';
import redis from './redis';

const blobArchive = config.ENABLE_BLOB_ARCHIVE ? new Archive('blob') : null;
/**
Expand All @@ -23,7 +21,7 @@ export async function readApiData(matchId: number, noBlobStore?: boolean): Promi
if (!data && blobArchive && !noBlobStore) {
const archive = await blobArchive.archiveGet(`${matchId}_api`);
if (archive) {
redisCount(redis, 'blob_archive_read');
redisCount('blob_archive_read');
}
data = archive ? JSON.parse(archive.toString()) as ApiMatch : undefined;
}
Expand Down
3 changes: 1 addition & 2 deletions store/getArchivedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import config from '../config';
import { redisCount } from '../util/utility';
import { Archive } from './archive';
import db from './db';
import redis from './redis';

const matchArchive = config.ENABLE_MATCH_ARCHIVE ? new Archive('match') : null;
const playerArchive = config.ENABLE_PLAYER_ARCHIVE ? new Archive('player') : null;
Expand Down Expand Up @@ -50,7 +49,7 @@ export async function tryReadArchivedMatch(
? JSON.parse(blob.toString())
: null;
if (result) {
redisCount(redis, 'match_archive_read');
redisCount('match_archive_read');
return result;
}
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions store/getGcData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function saveGcData(
throw new Error('invalid data');
}
// Count successful calls
redisCount(redis, 'retriever');
redisCount('retriever');
redis.hincrby('retrieverSuccessSteamIDs', steamid, 1);
redis.expireat(
'retrieverSuccessSteamIDs',
Expand Down Expand Up @@ -194,7 +194,7 @@ export async function getOrFetchGcData(
// Check if we have gcdata cached
const saved = await readGcData(matchId);
if (saved) {
redisCount(redis, 'regcdata');
redisCount('regcdata');
if (config.DISABLE_REGCDATA) {
// If high load, we can disable refetching gcdata
return { data: saved, error: null };
Expand Down
5 changes: 1 addition & 4 deletions store/getMeta.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import ProtoBuf from 'protobufjs';
import axios from 'axios';
import fs from 'fs';
import { exec } from 'child_process';
import { promisify } from 'util';
import redis from './redis';
import { buildReplayUrl, redisCount } from '../util/utility';
import { readGcData } from './getGcData';
const execPromise = promisify(exec);
Expand Down Expand Up @@ -32,7 +29,7 @@ export async function getMeta(matchId: number) {
const message = await getMetaFromUrl(url);
if (message) {
// Count the number of meta parses
redisCount(redis, 'meta_parse');
redisCount('meta_parse');
}
// Return the info, it may be null if we failed at any step or meta isn't available
return message;
Expand Down
3 changes: 1 addition & 2 deletions store/getParsedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Archive } from './archive';
import cassandra from './cassandra';
import db from './db';
import { insertMatch } from './insert';
import redis from './redis';
import axios from 'axios';

const blobArchive = config.ENABLE_BLOB_ARCHIVE ? new Archive('blob') : null;
Expand Down Expand Up @@ -108,7 +107,7 @@ export async function getOrFetchParseData(
}> {
const saved = await readParseData(matchId);
if (saved) {
redisCount(redis, 'reparse');
redisCount('reparse');
if (config.DISABLE_REPARSE) {
// If high load, we can disable parsing already parsed matches
return { data: saved, skipped: true, error: null };
Expand Down
9 changes: 3 additions & 6 deletions store/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,29 +454,26 @@ export async function insertMatch(
}] [ended: ${moment.unix(endedAt ?? 0).fromNow()}] ${match.match_id}`;
redis.publish(options.type, message);
if (options.type === 'parsed') {
redisCount(redis, 'parser');
redisCount('parser');
}
if (options.origin === 'scanner' && options.type === 'api') {
redisCount(redis, 'added_match');
redisCount('added_match');
match.players
.filter((p) => p.account_id)
.forEach(async (p) => {
if (p.account_id) {
redisCountDistinct(
redis,
'distinct_match_player',
p.account_id.toString(),
);
const visitTime = Number(await redis.zscore('visitors', p.account_id.toString()));
if (visitTime) {
redisCountDistinct(
redis,
'distinct_match_player_user',
p.account_id.toString(),
);
if (visitTime > Number(moment().subtract(30, 'day').format('X'))) {
redisCountDistinct(
redis,
'distinct_match_player_recent_user',
p.account_id.toString(),
);
Expand Down Expand Up @@ -634,7 +631,7 @@ export async function insertMatch(
if (!doParse) {
return null;
}
redisCount(redis, 'auto_parse');
redisCount('auto_parse');
let priority = 5;
if (isProLeague) {
priority = -1;
Expand Down
18 changes: 9 additions & 9 deletions store/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function getPlayerMatchesWithMetadata(
// User disabled public match history from Dota, so don't return matches
return [[], null];
}
redisCount(redis, 'player_matches');
redisCount('player_matches');
const columns = await getCassandraColumns('player_caches');
const sanitizedProject = queryObj.project.filter((f: string) => columns[f]);
const projection = queryObj.projectAll ? ['*'] : sanitizedProject;
Expand All @@ -250,7 +250,7 @@ export async function getPlayerMatchesWithMetadata(
? await readCachedPlayerMatches(accountId, projection)
: undefined;
if (cache?.length) {
redisCountDistinct(redis, 'distinct_player_cache', accountId.toString());
redisCountDistinct('distinct_player_cache', accountId.toString());
await redis.zadd('player_matches_visit', moment().format('X'), accountId);
// Keep some number of recent players visited for auto-cache
await redis.zremrangebyrank('player_matches_visit', '0', '-50001');
Expand Down Expand Up @@ -345,11 +345,11 @@ async function readCachedPlayerMatches(
);
const result = rows[0]?.blob;
if (result) {
redisCount(redis, 'player_cache_hit');
redisCount('player_cache_hit');
if (
await isAutoCachePlayer(redis, accountId)
) {
redisCount(redis, 'auto_player_cache_hit');
redisCount('auto_player_cache_hit');
}
const output = JSON.parse(gunzipSync(result).toString());
// Remove columns not asked for
Expand All @@ -367,17 +367,17 @@ async function readCachedPlayerMatches(
'NX',
);
if (!lock) {
redisCount(redis, 'player_cache_wait');
redisCount('player_cache_wait');
// console.log('[PLAYERCACHE] waiting for lock on %s', accountId);
// Couldn't acquire the lock, wait and try again
await new Promise((resolve) => setTimeout(resolve, 1000));
return readCachedPlayerMatches(accountId, project);
}
redisCount(redis, 'player_cache_miss');
redisCount('player_cache_miss');
if (
await isAutoCachePlayer(redis, accountId)
) {
redisCount(redis, 'auto_player_cache_miss');
redisCount('auto_player_cache_miss');
}
const result = await populateCache(accountId, project);
// Release the lock
Expand All @@ -403,7 +403,7 @@ export async function populateCache(
// all.length,
// zip.length,
// );
redisCount(redis, 'player_cache_write');
redisCount('player_cache_write');
await cassandra.execute(
`INSERT INTO player_temp(account_id, blob) VALUES(?, ?) USING TTL ?`,
[accountId, zip, Number(config.PLAYER_CACHE_SECONDS)],
Expand Down Expand Up @@ -722,7 +722,7 @@ export async function getMatchDataFromBlobWithMetadata(
if (!archived && !api) {
// Use this event to count the number of failed requests
// Could be due to missing data or invalid ID--need to analyze
redisCount(redis, 'steam_api_backfill');
redisCount('steam_api_backfill');
return [null, null];
}

Expand Down
4 changes: 1 addition & 3 deletions svc/autocache.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
// Processes a queue of auto player cache requests
import { populateCache } from '../store/queries';
import { runQueue } from '../store/queue';
import redis from '../store/redis';
import { redisCount, redisCountDistinct } from '../util/utility';

async function processCache(job: CacheJob) {
const accountId = job;
console.log(accountId);
redisCountDistinct(
redis,
'distinct_auto_player_cache',
accountId,
);
redisCount(redis, 'auto_player_cache');
redisCount('auto_player_cache');
// Don't need to await this since it's just caching
populateCache(Number(accountId), ['match_id']);
}
Expand Down
7 changes: 3 additions & 4 deletions svc/fullhistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
eachLimitPromise,
} from '../util/utility';
import db from '../store/db';
import redis from '../store/redis';
import { runQueue } from '../store/queue';
import { getPlayerMatches } from '../store/queries';
import { insertMatch } from '../store/insert';
Expand All @@ -23,9 +22,9 @@ async function updatePlayer(player: FullHistoryJob) {
.where({
account_id: player.account_id,
});
redisCount(redis, 'fullhistory');
redisCount('fullhistory');
if (!player.long_history) {
redisCount(redis, 'fullhistory_short');
redisCount('fullhistory_short');
}
}

Expand Down Expand Up @@ -119,7 +118,7 @@ async function processFullHistory(job: FullHistoryJob) {
delete match_ids[matchId];
}
if (Object.keys(match_ids).length > 0) {
redisCount(redis, 'fullhistory_op');
redisCount('fullhistory_op');
}
// make api_details requests for matches
const promiseFuncs = Object.keys(match_ids).map(
Expand Down
3 changes: 1 addition & 2 deletions svc/mmr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Processes a queue of requests to update MMR/rank medal for players
import { runQueue } from '../store/queue';
import db from '../store/db';
import redis from '../store/redis';
import { insertPlayerRating } from '../store/insert';
import config from '../config';
import {
Expand All @@ -18,7 +17,7 @@ async function processMmr(job: MmrJob) {
const { data } = await axios.get(url, {
timeout: 5000,
});
redisCount(redis, 'retriever_player');
redisCount('retriever_player');

// Update player's Dota Plus status if changed
const player = {
Expand Down
Loading

0 comments on commit 0b75fe6

Please sign in to comment.