Skip to content

Commit e50bfc0

Browse files
authored
Merge pull request #6228 from mozilla/mntor-5024-2
feat(fx breaches): fix breach alerts cron job in fx settings
2 parents 7e1ef2a + 8c02be7 commit e50bfc0

File tree

14 files changed

+991
-167
lines changed

14 files changed

+991
-167
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const config = [
4141
"dist",
4242
"coverage",
4343
"!.storybook",
44+
"playwright-report/**",
4445
],
4546
},
4647
...compat.config({

jest.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const customJestConfig = {
4444
"<rootDir>/src/apiMocks/mockData.ts",
4545
"<rootDir>/src/(.+).stories.(ts|tsx)",
4646
"<rootDir>/.storybook/",
47+
"<rootDir>/src/test/",
4748
],
4849

4950
// Indicates which provider should be used to instrument code for coverage

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dev:cron:db-delete-unverified-subscribers": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/deleteUnverifiedSubscribers.ts",
1717
"dev:cron:db-pull-breaches": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/syncBreaches.ts",
1818
"dev:cron:db-pull-data-brokers": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/syncOnerepDataBrokers.ts",
19-
"dev:cron:remote-settings-pull-breaches": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/updateBreachesInRemoteSettings.ts",
19+
"dev:cron:remote-settings-pull-breaches": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/updateBreachesInRemoteSettings/index.ts",
2020
"dev:cron:onerep-limits-alert": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/onerepStatsAlert.ts",
2121
"dev:cron:report-lighthouse-results": "tsx --tsconfig tsconfig.cronjobs.json src/scripts/cronjobs/reportLighthouseResults.ts",
2222
"dev:nimbus": "node --watch-path config/nimbus.yaml src/scripts/build/nimbusTypes.js",
@@ -36,7 +36,7 @@
3636
"cron:db-delete-unverified-subscribers": "node dist/scripts/cronjobs/deleteUnverifiedSubscribers.js",
3737
"cron:db-pull-breaches": "node dist/scripts/cronjobs/syncBreaches.js",
3838
"cron:db-pull-data-brokers": "node dist/scripts/cronjobs/syncOnerepDataBrokers.js",
39-
"cron:remote-settings-pull-breaches": "node dist/scripts/cronjobs/updateBreachesInRemoteSettings.js",
39+
"cron:remote-settings-pull-breaches": "node dist/scripts/cronjobs/updateBreachesInRemoteSettings/index.js",
4040
"cron:onerep-limits-alert": "node dist/scripts/cronjobs/onerepStatsAlert.js",
4141
"cron:report-lighthouse-results": "node dist/scripts/cronjobs/reportLighthouseResults.js",
4242
"db:migrate": "node -r dotenv-flow/config node_modules/knex/bin/cli.js migrate:latest --knexfile src/db/knexfile.js",
@@ -116,7 +116,8 @@
116116
"server-only": "^0.0.1",
117117
"sharp": "^0.34.2",
118118
"uuid": "^11.1.0",
119-
"winston": "^3.17.0"
119+
"winston": "^3.17.0",
120+
"winston-transport": "^4.9.0"
120121
},
121122
"devDependencies": {
122123
"@eslint/eslintrc": "^3.3.1",

src/app/functions/server/logging.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { createLogger, transports } from "winston";
5+
import { createLogger, transports, LoggerOptions } from "winston";
6+
import Transport from "winston-transport";
67
import { LoggingWinston } from "@google-cloud/logging-winston";
8+
import * as Sentry from "@sentry/node";
79

810
// Explicitly not run in tests (and other non-gcpdev environments)
911
/* c8 ignore next 7 */
@@ -24,3 +26,26 @@ export const logger = createLogger({
2426
? [getLoggingWinston()]
2527
: [new transports.Console()],
2628
});
29+
30+
// Automatically capture logger error, warn and forward to Sentry
31+
// Avoids double-logging
32+
/* c8 ignore start */
33+
// can't be used in tests due to jsdom environment
34+
// [MNTOR-1880]
35+
const SentryWinstonTransport = Sentry.createSentryWinstonTransport(Transport, {
36+
levels: ["error", "warn"],
37+
});
38+
const sentryTransports: LoggerOptions["transports"] = [
39+
["gcpdev"].includes(process.env.APP_ENV ?? "local")
40+
? getLoggingWinston()
41+
: new transports.Console(),
42+
];
43+
if (Sentry.isInitialized()) {
44+
sentryTransports.push(new SentryWinstonTransport());
45+
}
46+
47+
export const sentryLogger = createLogger({
48+
level: "info",
49+
transports: sentryTransports,
50+
});
51+
/* c8 ignore stop */

src/scripts/cronjobs/updateBreachesInRemoteSettings.ts

Lines changed: 0 additions & 162 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use strict";
6+
7+
/**
8+
* Cron: Daily
9+
* From all the HIBP breaches, we parse out the new breaches that are not already present
10+
* in firefox remote settings, and update the data source accordingly
11+
*/
12+
13+
import * as Sentry from "@sentry/node";
14+
15+
Sentry.init({
16+
environment: process.env.APP_ENV,
17+
dsn: process.env.SENTRY_DSN,
18+
tracesSampleRate: 1.0,
19+
});
20+
21+
Sentry.setTag("job", "updateBreachesInRemoteSettings");
22+
23+
import "dotenv-flow/config";
24+
import { sentryLogger } from "../../../app/functions/server/logging";
25+
import { main } from "./updateBreachesInRemoteSettings";
26+
27+
await main(sentryLogger);

0 commit comments

Comments
 (0)