@rine-kit/pubg-sync 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ const DURATION_BUCKETS_MS = [10, 50, 100, 250, 500, 1_000, 5_000, 30_000];
2
+ const ALERT_CODES = [
3
+ { code: 'public_sync_queue_snapshot_unavailable', severity: 'critical' },
4
+ { code: 'public_sync_queue_lag_high', severity: 'warning' },
5
+ { code: 'public_sync_queue_expired_lease', severity: 'warning' },
6
+ { code: 'public_sync_team_failures', severity: 'warning' },
7
+ { code: 'public_sync_worker_rss_high', severity: 'warning' },
8
+ ];
9
+ function number(value) {
10
+ return Number.isFinite(value) && value >= 0 ? String(value) : '0';
11
+ }
12
+ function gauge(name, help, value) {
13
+ return [`# HELP ${name} ${help}`, `# TYPE ${name} gauge`, `${name} ${number(value)}`];
14
+ }
15
+ function counter(name, help, value) {
16
+ return [`# HELP ${name} ${help}`, `# TYPE ${name} counter`, `${name} ${number(value)}`];
17
+ }
18
+ /** Process-local, aggregate Worker metrics. Label values are fixed codes/states;
19
+ * tenant, team, player, guild, channel and actor identifiers never enter this registry. */
20
+ export class PublicSyncWorkerMetrics {
21
+ cycles = 0;
22
+ counters = {
23
+ teamsDiscovered: 0,
24
+ teamsAttempted: 0,
25
+ teamsCompleted: 0,
26
+ teamsFailed: 0,
27
+ matchesDiscovered: 0,
28
+ telemetryFetched: 0,
29
+ telemetryUnavailable: 0,
30
+ };
31
+ alertCounts = new Map(ALERT_CODES.map(({ code }) => [code, 0]));
32
+ durationBuckets = DURATION_BUCKETS_MS.map(() => 0);
33
+ durationCount = 0;
34
+ durationSumMs = 0;
35
+ latestDurationMs = 0;
36
+ latestQueue = null;
37
+ recordCycle(log) {
38
+ this.cycles += 1;
39
+ this.counters.teamsDiscovered += log.cycle.teamsDiscovered;
40
+ this.counters.teamsAttempted += log.cycle.teamsAttempted;
41
+ this.counters.teamsCompleted += log.cycle.teamsCompleted;
42
+ this.counters.teamsFailed += log.cycle.teamsFailed;
43
+ this.counters.matchesDiscovered += log.cycle.matchesDiscovered;
44
+ this.counters.telemetryFetched += log.cycle.telemetryFetched;
45
+ this.counters.telemetryUnavailable += log.cycle.telemetryUnavailable;
46
+ this.latestDurationMs = log.cycle.durationMs;
47
+ this.durationCount += 1;
48
+ this.durationSumMs += log.cycle.durationMs;
49
+ DURATION_BUCKETS_MS.forEach((bound, index) => {
50
+ if (log.cycle.durationMs <= bound)
51
+ this.durationBuckets[index] += 1;
52
+ });
53
+ this.latestQueue = log.queue;
54
+ for (const alert of log.alerts)
55
+ this.alertCounts.set(alert.code, (this.alertCounts.get(alert.code) ?? 0) + 1);
56
+ }
57
+ render(input) {
58
+ const lines = [
59
+ ...gauge('pubg_saas_worker_up', 'Worker process is serving metrics.', 1),
60
+ ...gauge('pubg_saas_worker_process_rss_bytes', 'Current Worker resident memory in bytes.', input.rssBytes),
61
+ ...gauge('pubg_saas_worker_process_heap_used_bytes', 'Current Worker V8 heap used in bytes.', input.heapUsedBytes),
62
+ ...gauge('pubg_saas_worker_pg_pool_total', 'Current PostgreSQL pool connections.', input.pool.totalCount),
63
+ ...gauge('pubg_saas_worker_pg_pool_idle', 'Idle PostgreSQL pool connections.', input.pool.idleCount),
64
+ ...gauge('pubg_saas_worker_pg_pool_waiting', 'Clients waiting for a PostgreSQL pool connection.', input.pool.waitingCount),
65
+ ...gauge('pubg_saas_worker_sync_cycle_duration_ms', 'Duration of the most recently completed sync cycle.', this.latestDurationMs),
66
+ ...gauge('pubg_saas_worker_queue_snapshot_available', 'Whether the most recent queue snapshot was available.', this.latestQueue === null ? 0 : 1),
67
+ ...gauge('pubg_saas_worker_queue_jobs_total', 'Jobs in the most recent queue snapshot.', this.latestQueue?.totalJobs ?? 0),
68
+ ...gauge('pubg_saas_worker_queue_jobs_due', 'Due jobs in the most recent queue snapshot.', this.latestQueue?.dueJobs ?? 0),
69
+ ...gauge('pubg_saas_worker_queue_jobs_delayed', 'Delayed jobs in the most recent queue snapshot.', this.latestQueue?.delayedJobs ?? 0),
70
+ ...gauge('pubg_saas_worker_queue_active_leases', 'Active leases in the most recent queue snapshot.', this.latestQueue?.activeLeases ?? 0),
71
+ ...gauge('pubg_saas_worker_queue_expired_leases', 'Expired leases in the most recent queue snapshot.', this.latestQueue?.expiredLeases ?? 0),
72
+ ...gauge('pubg_saas_worker_queue_retrying_jobs', 'Retrying jobs in the most recent queue snapshot.', this.latestQueue?.retryingJobs ?? 0),
73
+ ...gauge('pubg_saas_worker_queue_oldest_due_age_seconds', 'Age of the oldest due job in seconds; zero when no due job exists.', this.latestQueue?.oldestDueAgeSeconds ?? 0),
74
+ '# HELP pubg_saas_worker_sync_cycle_duration_milliseconds Sync cycle duration histogram since process start.',
75
+ '# TYPE pubg_saas_worker_sync_cycle_duration_milliseconds histogram',
76
+ ];
77
+ lines.push(...counter('pubg_saas_worker_sync_cycles_total', 'Completed public sync cycles since process start.', this.cycles));
78
+ lines.push(...counter('pubg_saas_worker_sync_teams_discovered_total', 'Teams discovered since process start.', this.counters.teamsDiscovered));
79
+ lines.push(...counter('pubg_saas_worker_sync_teams_attempted_total', 'Teams attempted since process start.', this.counters.teamsAttempted));
80
+ lines.push(...counter('pubg_saas_worker_sync_teams_completed_total', 'Teams completed since process start.', this.counters.teamsCompleted));
81
+ lines.push(...counter('pubg_saas_worker_sync_teams_failed_total', 'Teams failed since process start.', this.counters.teamsFailed));
82
+ lines.push(...counter('pubg_saas_worker_sync_matches_discovered_total', 'Matches discovered since process start.', this.counters.matchesDiscovered));
83
+ lines.push(...counter('pubg_saas_worker_sync_telemetry_fetched_total', 'Telemetry files fetched since process start.', this.counters.telemetryFetched));
84
+ lines.push(...counter('pubg_saas_worker_sync_telemetry_unavailable_total', 'Telemetry files unavailable since process start.', this.counters.telemetryUnavailable));
85
+ DURATION_BUCKETS_MS.forEach((bound, index) => {
86
+ lines.push(`pubg_saas_worker_sync_cycle_duration_milliseconds_bucket{le="${bound}"} ${number(this.durationBuckets[index])}`);
87
+ });
88
+ lines.push(`pubg_saas_worker_sync_cycle_duration_milliseconds_bucket{le="+Inf"} ${number(this.durationCount)}`, `pubg_saas_worker_sync_cycle_duration_milliseconds_sum ${number(this.durationSumMs)}`, `pubg_saas_worker_sync_cycle_duration_milliseconds_count ${number(this.durationCount)}`, '# HELP pubg_saas_worker_alerts_total Worker alert codes observed since process start.', '# TYPE pubg_saas_worker_alerts_total counter');
89
+ for (const { code, severity } of ALERT_CODES) {
90
+ lines.push(`pubg_saas_worker_alerts_total{code="${code}",severity="${severity}"} ${this.alertCounts.get(code) ?? 0}`);
91
+ }
92
+ return `${lines.join('\n')}\n`;
93
+ }
94
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@rine-kit/pubg-sync",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "description": "PUBG provider sync for @rine-kit/pubg-postgres: team sync worker, player-name resolver, shared API admission (rate limit), egress proxy config, worker metrics. Extracted from Gate; no KOOK dependency.",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "pg": "^8.13.0",
22
+ "undici": "^8.10.2",
23
+ "@rine-kit/pubg-domain": "0.1.2",
24
+ "@rine-kit/pubg-intelligence": "0.1.2",
25
+ "@rine-kit/pubg-postgres": "0.1.2"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^26.6.5",
29
+ "@types/pg": "^8.11.10",
30
+ "tsx": "^4.23.15",
31
+ "typescript": "^5.9.2"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+ssh://git@github.com/ChristmasFox/rine-kit.git",
36
+ "directory": "packages/pubg-sync"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit",
41
+ "test": "tsx --test \"tests/**/*.test.ts\"",
42
+ "test:pg": "bash ../../scripts/with-pgvector.sh npx tsx --test \"tests/*.test.ts\""
43
+ }
6
44
  }