Skip to content

refact(map-metrics): collect map metrics on event instead of job#250

Merged
sonikro merged 1 commit into
mainfrom
refactor-map-metrics
Feb 7, 2026
Merged

refact(map-metrics): collect map metrics on event instead of job#250
sonikro merged 1 commit into
mainfrom
refactor-map-metrics

Conversation

@sonikro
Copy link
Copy Markdown
Owner

@sonikro sonikro commented Feb 7, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 7, 2026 18:06
@sonikro sonikro enabled auto-merge (squash) February 7, 2026 18:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors map metrics collection to be driven by SRCDS “Loading map …” UDP log events instead of a scheduled background job, and updates the domain/schema accordingly (dropping server_id from stored metrics).

Changes:

  • Add a new loadingMap SRCDS command parser + handler that logs and persists map load metrics on receipt.
  • Remove the scheduled server metrics collection routine and the CollectServerMetrics core use case (and its tests/exports).
  • Update ServerStatusMetric + SQLite repository + DB migration to remove server_id from server_status_metrics.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/providers/src/repository/SQliteServerStatusMetricsRepository.ts Stops writing/returning server_id when persisting metrics.
packages/entrypoints/src/udp/srcdsCommands/index.ts Registers the new loadingMap parser in the SRCDS command list.
packages/entrypoints/src/udp/srcdsCommands/UDPCommandServices.ts Extends UDP command DI services with serverStatusMetricsRepository.
packages/entrypoints/src/udp/srcdsCommands/LoadingMap.ts Implements parsing + handler to log and persist map load metrics.
packages/entrypoints/src/udp/srcdsCommands/LoadingMap.test.ts Adds tests for parsing and handler behavior.
packages/entrypoints/src/jobs/index.ts Removes export of the deleted metrics-collection routine.
packages/entrypoints/src/jobs/ServerMetricsCollectionRoutine.ts Deletes the scheduled job that used to collect metrics periodically.
packages/entrypoints/src/discordBot.ts Removes routine scheduling and wires serverStatusMetricsRepository into the UDP listener DI.
packages/core/src/usecase/CollectServerMetrics.ts Deletes the use case previously used by the scheduled job.
packages/core/src/usecase/CollectServerMetrics.test.ts Deletes tests for the removed use case.
packages/core/src/domain/ServerStatusMetric.ts Removes serverId from the domain model.
packages/core/index.ts Stops exporting the removed use case.
migrations/20260207175944_drop_server_id_from_server_status_metrics.ts Adds migration to drop server_id column from server_status_metrics.

Comment on lines +63 to +78
it("should log the loading map event", async () => {
const { services } = makeSut();
const rawString = '02/07/2026 - 17:54:33: Loading map "cp_badlands"';
const command = loadingMap(rawString);

if (!command || !command.handler) throw new Error("No handler");

await command.handler({ args: command.args, password: "123", services });

expect(vi.mocked(logger.emit)).toHaveBeenCalledWith({
severityText: 'INFO',
body: 'Server loading map',
attributes: {
map: "cp_badlands",
},
});
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

These handler tests share the same mocked logger.emit across test cases, but the mock is never cleared. That makes assertions like toHaveBeenCalledWith(...) potentially pass due to calls from earlier tests. Clear/reset the logger.emit mock (or vi.clearAllMocks()) within makeSut() or at the start of each test to keep tests independent.

Copilot uses AI. Check for mistakes.
@sonikro sonikro merged commit 1adb4ae into main Feb 7, 2026
15 checks passed
@sonikro sonikro deleted the refactor-map-metrics branch February 7, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants