Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: endsWith(github.ref, '/prod') || endsWith(github.ref, '/stage') || endsWith(github.ref, '/migration')
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push]
jobs:
lint:
name: Unit testing
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-monorepository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
REPOSITORY_MONO_PATH: workers
jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Mono repository update
uses: peter-evans/repository-dispatch@v1
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ module.exports = {

setupFiles: [ './jest.setup.js' ],

setupFilesAfterEnv: [ './jest.setup.redis-mock.js', './jest.setup.mongo-repl-set.js' ],
setupFilesAfterEnv: ['./jest.setup.redis-mock.js', './jest.setup.mongo-repl-set.js'],
};
19 changes: 10 additions & 9 deletions jest.setup.mongo-repl-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let admin;
let connection;

beforeAll(async () => {
connection = await MongoClient.connect("mongodb://127.0.0.1:55010/hawk?", {
connection = await MongoClient.connect('mongodb://127.0.0.1:55010/hawk?', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
Expand All @@ -13,11 +13,12 @@ beforeAll(async () => {

try {
let status = await admin.command({ replSetGetStatus: 1 }).catch(() => null);

if (status && status.ok) {
console.log("✅ Replica set already initialized");
console.log('✅ Replica set already initialized');
} else {
await admin.command({ replSetInitiate: {} });
console.log("✅ Replica set initiated");
console.log('✅ Replica set initiated');
}

const startTime = Date.now();
Expand All @@ -30,15 +31,15 @@ beforeAll(async () => {
await new Promise(resolve => setTimeout(resolve, 1000));
status = await admin.command({ replSetGetStatus: 1 });

const primary = status.members.find(member => member.stateStr === "PRIMARY");
const secondary = status.members.find(member => member.stateStr === "SECONDARY");
const primary = status.members.find(member => member.stateStr === 'PRIMARY');
const secondary = status.members.find(member => member.stateStr === 'SECONDARY');

if (primary && secondary) break;
if (primary && secondary) {
break;
}
} while (Date.now() - startTime < timeout);


console.log("✅ Replica set is stable");

console.log('✅ Replica set is stable');
} catch (err) {
console.error('❌ Failed to initiate replica set:', err);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"dependencies": {
"@hawk.so/nodejs": "^3.1.1",
"@hawk.so/types": "^0.1.28",
"@hawk.so/types": "^0.1.29",
"@types/amqplib": "^0.8.2",
"@types/jest": "^29.2.3",
"@types/mongodb": "^3.5.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@
<td align="center" style="padding: 15px 0;">
<font color="#dbe6ff" style="font-size: 15px; text-align: center; color: #dbe6ff; letter-spacing: 0.4px;">
<span style="vertical-align: middle; display: inline-block;">
Warning of the Used Volume
You’re almost out of your error tracking limit
</span>
</font>
</td>
</tr>
<tr>
<td style="display: block; padding: 20px; margin-bottom: 30px; border-width: 1px; border-color: #494f5e; border-style: solid; border-radius: 10px; line-height: 1.47">
<font color="#dbe6ff" style="font-size: 15px; letter-spacing: 0.4px;">
You've used {{ eventsCount }} of {{ eventsLimit }} events available on {{ workspace.name | escape }} workspace.
Youve used {{ eventsCount }} of {{ eventsLimit }} events this month in the {{ workspace.name | escape }} workspace.

Increase used volume and don't miss the new ones.
Your project is growing — that’s awesome! Let’s make sure you don’t miss any important errors.

Upgrade your plan to stay on top of everything.
</font>
</td>
</tr>
<tr>
<td style="padding-right: 20px; padding-left: 20px; padding-bottom: 40px;">
{% include '../../components/button.twig' with {href: host ~ '/workspace/' ~ workspace._id ~ '/settings/volume', label: 'Go to event usage settings'} %}
{% include '../../components/button.twig' with {href: host ~ '/workspace/' ~ workspace._id ~ '/settings/billing', label: 'Increase limit — from 99₽'} %}
</td>
</tr>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Warning of the Used Volume for workspace {{ workspace.name | escape }}!
You’re almost out of error tracking events in {{ workspace.name }} workspace
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
You've used {{ eventsCount }} of {{ eventsLimit }} events available on {{ workspace.name | escape }} workspace plan.
Youve used {{ eventsCount }} of {{ eventsLimit }} events this month in the {{ workspace.name | escape }} workspace.

Upgrade the plan and don't miss the new ones: {{ host }}/workspace/{{ workspace._id }}/settings/billing
Your project is growing — that’s awesome! Let’s make sure you don’t miss any important errors.

Upgrade your plan to stay on top of everything: {{ host }}/workspace/{{ workspace._id }}/settings/billing

***

Expand Down
57 changes: 33 additions & 24 deletions workers/javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
* Fixes bug: https://github.com/codex-team/hawk.workers/issues/121
*/
if (originalLocation.source) {
console.log('original location source found')
console.log('original location source found');
/**
* Get 5 lines above and 5 below
*/
Expand All @@ -247,40 +247,43 @@
sourceCode: lines,
}) as BacktraceFrame;
}

/**
* Method that is used to parse full function context of the code position
*
* @param sourceCode - content of the source file
* @param line - number of the line from the stack trace
* @returns - string of the function context or null if it could not be parsed

Check warning on line 256 in workers/javascript/src/index.ts

View workflow job for this annotation

GitHub Actions / ESlint

Missing JSDoc @returns type
*/
private getFunctionContext(sourceCode: string, line: number): string | null {
let functionName: string | null = null;
let className: string | null = null;
let isAsync: boolean = false;
let isAsync = false;

try {
const ast = parse(sourceCode, {
sourceType: "module",
sourceType: 'module',
plugins: [
"typescript",
"jsx",
"classProperties",
"decorators",
"optionalChaining",
"nullishCoalescingOperator",
"dynamicImport",
"bigInt",
"topLevelAwait"
]
'typescript',
'jsx',
'classProperties',
'decorators',
'optionalChaining',
'nullishCoalescingOperator',
'dynamicImport',
'bigInt',
'topLevelAwait',
],
});

traverse(ast as any, {
/**
* It is used to get class decorator of the position, it will save class that is related to original position
*
* @param path
*/
ClassDeclaration(path) {
console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`)
console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`);

if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) {
className = path.node.id.name || null;
Expand All @@ -289,9 +292,11 @@
/**
* It is used to get class and its method decorator of the position
* It will save class and method, that are related to original position
*
* @param path
*/
ClassMethod(path) {
console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`)
console.log(`class declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`);

if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) {
// Handle different key types
Expand All @@ -303,24 +308,28 @@
},
/**
* It is used to get function name that is declared out of class
*
* @param path
*/
FunctionDeclaration(path) {
console.log(`function declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`)
console.log(`function declaration: loc: ${path.node.loc}, line: ${line}, node.start.line: ${path.node.loc.start.line}, node.end.line: ${path.node.loc.end.line}`);

if (path.node.loc && path.node.loc.start.line <= line && path.node.loc.end.line >= line) {
functionName = path.node.id.name || null;
isAsync = path.node.async;
}
},
/**
* It is used to get anonimous function names in function expressions or arrow function expressions
*
* @param path
*/
VariableDeclarator(path) {
console.log(`variable declaration: node.type: ${path.node.init.type}, line: ${line}, `)
console.log(`variable declaration: node.type: ${path.node.init.type}, line: ${line}, `);

if (
path.node.init &&
(path.node.init.type === "FunctionExpression" || path.node.init.type === "ArrowFunctionExpression") &&
(path.node.init.type === 'FunctionExpression' || path.node.init.type === 'ArrowFunctionExpression') &&
path.node.loc &&
path.node.loc.start.line <= line &&
path.node.loc.end.line >= line
Expand All @@ -331,14 +340,14 @@
}
isAsync = (path.node.init as any).async;
}
}
},
});
} catch (e) {
console.error(`Failed to parse source code: ${e.message}`);
console.error(`Failed to parse source code: ${e.message}`);
}

return functionName ? `${isAsync ? "async " : ""}${className ? `${className}.` : ""}${functionName}` : null;
}
return functionName ? `${isAsync ? 'async ' : ''}${className ? `${className}.` : ''}${functionName}` : null;
}

/**
* Downloads source map file from Grid FS
Expand Down
9 changes: 5 additions & 4 deletions workers/notifier/tests/redisHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ describe('RedisHelper', () => {
const thresholdPeriod = 2000; // 2 seconds in milliseconds
const key = `${projectId}:${ruleId}:${groupHash}:${thresholdPeriod}:times`;

/**
* Call computeEventCountForPeriod to set the key
*/
await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);
/**
* Call computeEventCountForPeriod to set the key
*/
await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);

/**
* Verify, that key exists
*/
let value = await redisClient.hGet(key, 'eventsCount');

expect(value).not.toBeNull();

/**
Expand Down
37 changes: 20 additions & 17 deletions workers/paymaster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ export default class PaymasterWorker extends Worker {
* Pay day is calculated by formula: last charge date + 30 days
*
* @param date - last charge date
* @param isDebug
* @param paidUntil - paid until date
* @param isDebug - flag for debug purposes
*/
private static isTimeToPay(date: Date, isDebug = false): boolean {
const expectedPayDay = new Date(date);
private static isTimeToPay(date: Date, paidUntil: Date, isDebug = false): boolean {
const expectedPayDay = paidUntil ? new Date(paidUntil) : new Date(date);

if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
} else if (!paidUntil) {
expectedPayDay.setMonth(date.getMonth() + 1);
}

Expand All @@ -82,17 +83,18 @@ export default class PaymasterWorker extends Worker {
/**
* Returns difference between now and payday in days
*
* Pay day is calculated by formula: last charge date + 30 days
* Pay day is calculated by formula: paidUntil date or last charge date + 1 month
*
* @param date - last charge date
* @param isDebug
* @param paidUntil - paid until date
* @param isDebug - flag for debug purposes
*/
private static daysBeforePayday(date: Date, isDebug = false): number {
const expectedPayDay = new Date(date);
private static daysBeforePayday(date: Date, paidUntil: Date = null, isDebug = false): number {
const expectedPayDay = paidUntil ? new Date(paidUntil) : new Date(date);

if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
} else if (!paidUntil) {
expectedPayDay.setMonth(date.getMonth() + 1);
}

Expand All @@ -104,17 +106,18 @@ export default class PaymasterWorker extends Worker {
/**
* Returns difference between payday and now in days
*
* Pay day is calculated by formula: last charge date + 30 days
* Pay day is calculated by formula: paidUntil date or last charge date + 1 month
*
* @param date - last charge date
* @param isDebug
* @param paidUntil - paid until date
* @param isDebug - flag for debug purposes
*/
private static daysAfterPayday(date: Date, isDebug = false): number {
const expectedPayDay = new Date(date);
private static daysAfterPayday(date: Date, paidUntil: Date = null, isDebug = false): number {
const expectedPayDay = paidUntil ? new Date(paidUntil) : new Date(date);

if (isDebug) {
expectedPayDay.setDate(date.getDate() + 1);
} else {
} else if (!paidUntil) {
expectedPayDay.setMonth(date.getMonth() + 1);
}

Expand Down Expand Up @@ -209,19 +212,19 @@ export default class PaymasterWorker extends Worker {
* Is it time to pay
*/
// @ts-expect-error debug
const isTimeToPay = PaymasterWorker.isTimeToPay(workspace.lastChargeDate, workspace.isDebug);
const isTimeToPay = PaymasterWorker.isTimeToPay(workspace.lastChargeDate, workspace.paidUntil, workspace.isDebug);

/**
* How many days have passed since payments the expected day of payments
*/
// @ts-expect-error debug
const daysAfterPayday = PaymasterWorker.daysAfterPayday(workspace.lastChargeDate, workspace.isDebug);
const daysAfterPayday = PaymasterWorker.daysAfterPayday(workspace.lastChargeDate, workspace.paidUntil, workspace.isDebug);

/**
* How many days left for the expected day of payments
*/
// @ts-expect-error debug
const daysLeft = PaymasterWorker.daysBeforePayday(workspace.lastChargeDate, workspace.isDebug);
const daysLeft = PaymasterWorker.daysBeforePayday(workspace.lastChargeDate, workspace.paidUntil, workspace.isDebug);

/**
* Do we need to ask for money
Expand Down
Loading
Loading