refact(map-metrics): collect map metrics on event instead of job#250
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
loadingMapSRCDS command parser + handler that logs and persists map load metrics on receipt. - Remove the scheduled server metrics collection routine and the
CollectServerMetricscore use case (and its tests/exports). - Update
ServerStatusMetric+ SQLite repository + DB migration to removeserver_idfromserver_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", | ||
| }, | ||
| }); |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.