Skip to content

Conversation

@kschelonka
Copy link
Collaborator

@kschelonka kschelonka commented Nov 20, 2025

References:

Jira:

Required for: https://mozilla-hub.atlassian.net/browse/SVCSE-2984

Description

Updates the breach alerts email so that it can be compatible with autoscaling up and down based on queue size rather than run as a cron job. This required major pattern changes to how the job was invoked.

I refactored the job so that the pubsub subscription handling logic was separated from the business logic/processing for each message. I also updated the job to use DI pattern for easier testing. Much of the core message processing logic was lifted, with some streamlining around db checks. Since this was such a big overhaul I included some low-hanging fruit (removing premium upsell [5108] and removing the nimbus integration [5081]).

All the methods are unit-tested except for the main job entrypoint, which I had originally tried to cover with an integration test but couldn't run in jsdom environment because pubsub client requires setImmediate, etc. I tested this locally successfully and will do a dev deployment.

Other Changes

  • Narrow type requirements on object args where appropriate (makes fake data generation easier and the data contract explicit)
  • Random assortment of unit tests to pass the coverage requirement (removing imports must have uncovered the test gaps)
  • Added integration test coverage for DB methods, but these won't be factored into the test coverage until 5117.

Remove the fixed message processing count and
batch pulls.

Do not accept new messages after termination
signals

Refactor job with DI for easier unit testing
The imports and mocks in tests seem to have masked
missing coverage, and moving to DI pattern revealed
gaps once they were no longer imported
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { logger } from "@sentry/utils";
import { logger } from "@sentry/core";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was deprecated, recommended to use @sentry/core

export const redisClient = () => {
if (process.env.REDIS_URL?.includes("redis.mock")) {
singleton = createRedisMockInstance();
singleton = new MockRedis();
Copy link
Collaborator Author

@kschelonka kschelonka Nov 20, 2025

Choose a reason for hiding this comment

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

this was a one-liner in utils-mock file, which I moved here for clarity and to eliminate needing another test for that file

@kschelonka kschelonka changed the title Mntor 5070 fix(breachAlerts): updates for autoscaling vs. on-demand job Nov 20, 2025
@kschelonka kschelonka changed the title fix(breachAlerts): updates for autoscaling vs. on-demand job fix(breachAlerts): updates for autoscaling service from cron job Nov 20, 2025
@kschelonka kschelonka changed the title fix(breachAlerts): updates for autoscaling service from cron job fix(breachAlerts): update cron job to autoscaling service Nov 20, 2025
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { createRedisInstance } from "./util";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added due to coverage complaint (probably from removing this import in the test files?)

* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { isUsingMockHIBPEndpoint, isUsingMockONEREPEndpoint } from "./mock";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added due to coverage complaint (no changes to the files)


import { parseMarkup } from "./parseMarkup";

describe("parseMarkup", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added due to coverage complaint (no changes to method)


export function isUsingMockHIBPEndpoint() {
return process.env.HIBP_KANON_API_ROOT?.includes("api/mock") as boolean;
return !!process.env.HIBP_KANON_API_ROOT?.includes("api/mock");
Copy link
Collaborator Author

@kschelonka kschelonka Nov 20, 2025

Choose a reason for hiding this comment

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

this was returning undefined if HIBP_KANON_API_ROOT was unset; !! is idiomatic boolean conversion

@kschelonka kschelonka requested review from Vinnl, codemist and mansaj and removed request for mansaj November 24, 2025 17:54
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