Skip to content

Commit 9827a31

Browse files
committed
disable metrics
1 parent 4eb0906 commit 9827a31

26 files changed

Lines changed: 115 additions & 142 deletions

src/functions/domain.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import puppeteer from "puppeteer";
22

3-
import metrics from "../metrics";
3+
// import metrics from "../metrics";
44
import { prisma } from "../prisma";
55
import {
6-
walshyService,
7-
ipQualityScoreService,
86
googleSafebrowsingService,
9-
sinkingYahtsService,
10-
virusTotalService,
7+
ipQualityScoreService,
118
phishermanService,
129
phishObserverService,
13-
urlScanService,
14-
securityTrailsService,
1510
phishReportService,
11+
securityTrailsService,
12+
sinkingYahtsService,
13+
urlScanService,
14+
virusTotalService,
15+
walshyService,
1616
} from "../services/_index";
1717

1818
/**
@@ -23,12 +23,13 @@ import {
2323
*/
2424
export async function domainCheck(domain: string) {
2525
const tsStart = Date.now();
26-
metrics.increment("functions.domainCheck");
26+
// metrics.increment("functions.domainCheck");
2727

2828
let walshyData = await walshyService.domain.check(domain);
2929
let ipQualityScoreData = await ipQualityScoreService.domain.check(domain);
30-
let googleSafebrowsingData =
31-
await googleSafebrowsingService.domain.check(domain);
30+
let googleSafebrowsingData = await googleSafebrowsingService.domain.check(
31+
domain
32+
);
3233
let sinkingYahtsData = await sinkingYahtsService.domain.check(domain);
3334
let virusTotalData = await virusTotalService.domain.check(domain);
3435
let phishermanData = await phishermanService.domain.check(domain);
@@ -81,7 +82,7 @@ export async function domainCheck(domain: string) {
8182
});
8283

8384
await browser.close();
84-
metrics.timing("functions.timing.domainCheck", Date.now() - tsStart);
85+
// metrics.timing("functions.timing.domainCheck", Date.now() - tsStart);
8586

8687
return {
8788
walshyData,

src/functions/jwt.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as jwt from "jsonwebtoken";
22

3-
import metrics from "../metrics";
3+
// import metrics from "../metrics";
44
import { prisma } from "../prisma";
55

66
/**
@@ -11,7 +11,7 @@ import { prisma } from "../prisma";
1111
* @returns void
1212
*/
1313
export async function authenticateToken(req: any, res: any, next: any) {
14-
metrics.increment("functions.jwt.authenticateToken");
14+
// metrics.increment("functions.jwt.authenticateToken");
1515

1616
const authHeader = req.headers["authorization"];
1717
const token = authHeader && authHeader.split(" ")[1];
@@ -28,7 +28,7 @@ export async function authenticateToken(req: any, res: any, next: any) {
2828
} else {
2929
return user;
3030
}
31-
},
31+
}
3232
);
3333

3434
let user = await prisma.user.findUnique({
@@ -46,7 +46,7 @@ export async function authenticateToken(req: any, res: any, next: any) {
4646
return res
4747
.status(403)
4848
.json(
49-
"Your user has been deleted. Please contact support if you believe this is an error or need to reactivate your account.",
49+
"Your user has been deleted. Please contact support if you believe this is an error or need to reactivate your account."
5050
);
5151
}
5252

@@ -61,17 +61,17 @@ export async function authenticateToken(req: any, res: any, next: any) {
6161
*/
6262
export async function generateAccessToken(user: any) {
6363
const tsStart = Date.now();
64-
metrics.increment("functions.jwt.generateAccessToken");
64+
// metrics.increment("functions.jwt.generateAccessToken");
6565

6666
let token = jwt.sign(
6767
{
6868
id: user.id,
6969
uuid: user.uuid,
7070
},
71-
process.env.JWT_SECRET!,
71+
process.env.JWT_SECRET!
7272
);
7373
const tsEnd = Date.now();
74-
metrics.timing("functions.jwt.generateAccessToken", tsEnd - tsStart);
74+
// metrics.timing("functions.jwt.generateAccessToken", tsEnd - tsStart);
7575
return token;
7676
}
7777

@@ -84,7 +84,7 @@ export async function generateAccessToken(user: any) {
8484
*/
8585
export async function getUserInfo(prisma: any, res: any, req: any) {
8686
const tsStart = Date.now();
87-
metrics.increment("functions.jwt.getUserInfo");
87+
// metrics.increment("functions.jwt.getUserInfo");
8888

8989
const authHeader = req.headers["authorization"];
9090
const token = authHeader && authHeader.split(" ")[1];
@@ -104,18 +104,18 @@ export async function getUserInfo(prisma: any, res: any, req: any) {
104104
});
105105

106106
const tsEnd = Date.now();
107-
metrics.timing("functions.jwt.getUserInfo", tsEnd - tsStart);
107+
// metrics.timing("functions.jwt.getUserInfo", tsEnd - tsStart);
108108

109109
return user;
110110
}
111111

112112
export async function getPermissionLevel(prisma: any, res: any, req: any) {
113113
const tsStart = Date.now();
114-
metrics.increment("functions.jwt.getPermissionLevel");
114+
// metrics.increment("functions.jwt.getPermissionLevel");
115115

116116
const info = await getUserInfo(prisma, res, req);
117117
// console.log(info);
118118

119119
const tsEnd = Date.now();
120-
metrics.timing("functions.jwt.getPermissionLevel", tsEnd - tsStart);
120+
// metrics.timing("functions.jwt.getPermissionLevel", tsEnd - tsStart);
121121
}

src/functions/parseData.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import metrics from "../metrics";
2-
31
/**
42
* parses the data from the different sources and returns a boolean value
53
* @param walshyData - Data from Walshy API
@@ -29,7 +27,7 @@ export async function parseData(
2927
// return true;
3028

3129
const tsStart = Date.now();
32-
metrics.increment("functions.domain.parseData");
30+
// metrics.increment("functions.domain.parseData");
3331

3432
let verdict: boolean;
3533

src/index.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import expressJSDocSwagger from "express-jsdoc-swagger";
44
import helmet from "helmet";
55

66
import { app } from "./app";
7-
import { server } from "./server";
8-
import { prisma } from "./prisma";
97
import router from "./router";
10-
import metrics from "./metrics";
11-
import { swaggerOptions as mainSwagOptions } from "./swaggerOptions";
8+
import { server } from "./server";
9+
// import metrics from "./metrics";
1210
import { swaggerOptions as adminSwagOptions } from "./routes/admin/swaggerOptions";
11+
import { swaggerOptions as mainSwagOptions } from "./swaggerOptions";
1312
import * as logger from "./utils/logger";
1413

1514
dotenv.config();
@@ -46,7 +45,7 @@ app.use(
4645
preload: true,
4746
},
4847
xPoweredBy: false,
49-
}),
48+
})
5049
);
5150

5251
// Add metric interceptors for axios
@@ -64,11 +63,11 @@ axios.interceptors.response.use((res: any) => {
6463
const httpCode = res.status;
6564
const timingStatKey = `http.request.${stat}`;
6665
const codeStatKey = `http.request.${stat}.${httpCode}`;
67-
metrics.timing(
68-
timingStatKey,
69-
performance.now() - res.config.metadata.startTs,
70-
);
71-
metrics.increment(codeStatKey, 1);
66+
// metrics.timing(
67+
// timingStatKey,
68+
// performance.now() - res.config.metadata.startTs
69+
// );
70+
// // metrics.increment(codeStatKey, 1);
7271

7372
return res;
7473
});
@@ -103,7 +102,7 @@ app.use("/", router);
103102
// "* * * * * *",
104103
// async function () {
105104
// console.log("Thump Thump");
106-
// metrics.increment("heartbeat");
105+
// // metrics.increment("heartbeat");
107106
// },
108107
// null,
109108
// true,
@@ -115,7 +114,7 @@ app.use("/", router);
115114
// "0 * * * * *",
116115
// async function () {
117116
// console.log("Thump Thump");
118-
// metrics.increment("heartbeat");
117+
// // metrics.increment("heartbeat");
119118
// },
120119
// null,
121120
// true,
@@ -124,6 +123,6 @@ app.use("/", router);
124123
//
125124

126125
server.listen(port, () => {
127-
metrics.increment("app.startup");
126+
// metrics.increment("app.startup");
128127
logger.info(`Server is running on port ${port}`);
129128
});

src/metrics.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import "dotenv/config";
2-
import { StatsD } from "node-statsd";
1+
// import "dotenv/config";
2+
// import { StatsD } from "node-statsd";
33

4-
const environment = process.env.NODE_ENV;
5-
const graphite = process.env.GRAPHITE_HOST;
4+
// const environment = process.env.NODE_ENV;
5+
// const graphite = process.env.GRAPHITE_HOST;
66

7-
if (graphite === null) throw new Error("Graphite host is not configured");
7+
// if (graphite === null) throw new Error("Graphite host is not configured");
88

9-
const metrics = new StatsD({
10-
host: graphite,
11-
port: 8125,
12-
prefix: `${environment}.phishdirectory.api.`,
13-
});
9+
// const metrics = new StatsD({
10+
// host: graphite,
11+
// port: 8125,
12+
// prefix: `${environment}.phishdirectory.api.`,
13+
// });
1414

15-
export default metrics;
15+
// export default metrics;

src/middleware/logRequest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import requestIp from "request-ip";
44
import { getUserInfo } from "../functions/jwt";
55
import { prisma } from "../prisma";
66
import { log } from "../utils/logger";
7-
import metrics from "../metrics";
87

98
/**
109
* Middleware to log requests to the console
@@ -16,9 +15,9 @@ import metrics from "../metrics";
1615
export const logRequest = async (
1716
req: Request,
1817
res: Response,
19-
next: NextFunction,
18+
next: NextFunction
2019
): Promise<void> => {
21-
metrics.increment("api.requests");
20+
// metrics.increment("api.requests");
2221

2322
let userAgent = req.headers["user-agent"];
2423
if (userAgent) {

src/middleware/stripeMeter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const stripeMeter = async (
1414
): Promise<void> => {
1515
next();
1616
// if (process.env.NODE_ENV === "production") {
17-
// metrics.increment("stripeMeter.requests");
17+
// // metrics.increment("stripeMeter.requests");
1818
// let userInfo = await getUserInfo(prisma, res, req);
1919

2020
// if (!userInfo) {

src/router.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as express from "express";
22
import responseTime from "response-time";
33

4-
import metrics from "./metrics";
4+
// import metrics from "./metrics";
55
import { logRequest } from "./middleware/logRequest";
66
import adminRouter from "./routes/admin/router";
77
import domainRouter from "./routes/domain";
@@ -22,9 +22,9 @@ router.use(
2222
const httpCode = res.statusCode;
2323
const timingStatKey = `http.response.${stat}`;
2424
const codeStatKey = `http.response.${stat}.${httpCode}`;
25-
metrics.timing(timingStatKey, time);
26-
metrics.increment(codeStatKey, 1);
27-
}),
25+
// metrics.timing(timingStatKey, time);
26+
// // metrics.increment(codeStatKey, 1);
27+
})
2828
);
2929

3030
/**
@@ -35,7 +35,7 @@ router.use(
3535
* "Redirecting to /docs"
3636
*/
3737
router.get("/", logRequest, (req, res) => {
38-
metrics.increment("http.request.root");
38+
// // metrics.increment("http.request.root");
3939
res.status(301).redirect("/docs");
4040
});
4141

@@ -49,7 +49,7 @@ router.get("/", logRequest, (req, res) => {
4949
* }
5050
*/
5151
router.get("/up", logRequest, (req, res) => {
52-
metrics.increment("http.request.up");
52+
// // metrics.increment("http.request.up");
5353
res.status(200).json({
5454
status: "up",
5555
});

src/routes/admin/router.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import moment from "moment";
33

44
import { getPackageVersion, getVersion } from "../../functions/getVersion";
55
import { authenticateToken, getUserInfo } from "../../functions/jwt";
6-
import metrics from "../../metrics";
76
import { logRequest } from "../../middleware/logRequest";
87
import { prisma } from "../../prisma";
98
import domainRouter from "./routes/domain";
@@ -80,7 +79,7 @@ router.use(async (req, res, next) => {
8079
* }
8180
*/
8281
router.get("/metrics", logRequest, async (req, res) => {
83-
metrics.increment("endpoint.misc.metrics");
82+
// // metrics.increment("endpoint.misc.metrics");
8483

8584
let uptime = process.uptime();
8685
// format the uptime

src/routes/admin/routes/user.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import bcrypt from "bcrypt";
2-
import express, { Request, Response } from "express";
2+
import express from "express";
33

4-
import metrics from "../../../metrics";
54
import { prisma } from "../../../prisma";
65
import { createCustomer } from "../../../stripe";
76

@@ -53,7 +52,7 @@ export type UserLogin = {
5352
* ]
5453
*/
5554
router.get("/", async (req, res) => {
56-
metrics.increment("endpoint.admin.users.get");
55+
// metrics.increment("endpoint.admin.users.get");
5756
try {
5857
const users = await prisma.user.findMany({
5958
orderBy: {
@@ -85,7 +84,7 @@ router.get("/", async (req, res) => {
8584
* }
8685
*/
8786
router.get("/user/:id", async (req, res) => {
88-
metrics.increment("endpoint.admin.user.get");
87+
// metrics.increment("endpoint.admin.user.get");
8988
try {
9089
const { id } = req.params;
9190

@@ -117,7 +116,7 @@ router.get("/user/:id", async (req, res) => {
117116
* }
118117
*/
119118
router.patch("/user/:id", async (req, res) => {
120-
metrics.increment("endpoint.admin.user.patch");
119+
// metrics.increment("endpoint.admin.user.patch");
121120
try {
122121
const { id } = req.params;
123122
const { email, password, permission } = req.body;
@@ -220,7 +219,7 @@ router.post("/user/new", async (req, res) => {
220219
* }
221220
*/
222221
router.delete("/user/:id", async (req, res) => {
223-
metrics.increment("endpoint.admin.user.delete");
222+
// metrics.increment("endpoint.admin.user.delete");
224223
try {
225224
const { id } = req.params;
226225

@@ -258,7 +257,7 @@ router.delete("/user/:id", async (req, res) => {
258257
* }
259258
*/
260259
router.patch("/role/:id/:permission", async (req, res) => {
261-
metrics.increment("endpoint.admin.user.role.patch");
260+
// metrics.increment("endpoint.admin.user.role.patch");
262261

263262
try {
264263
const { id, permission } = req.params;

0 commit comments

Comments
 (0)