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
29 changes: 16 additions & 13 deletions workers/grouper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,23 @@ export default class GrouperWorker extends Worker {
if (patterns && patterns.length > 0) {
const matchingPattern = await this.findMatchingPattern(patterns, event);

if (matchingPattern !== null) {
const originalEvent = await this.cache.get(`${projectId}:${matchingPattern}:originalEvent`, async () => {
return await this.eventsDb.getConnection()
.collection(`events:${projectId}`)
.findOne(
{ 'payload.title': { $regex: matchingPattern } },
{ sort: { _id: 1 } }
);
});

this.logger.info(`original event for pattern: ${JSON.stringify(originalEvent)}`);
if (matchingPattern !== null && matchingPattern !== undefined) {
try {
const originalEvent = await this.cache.get(`${projectId}:${matchingPattern}:originalEvent`, async () => {
return await this.eventsDb.getConnection()
.collection(`events:${projectId}`)
.findOne(
{ 'payload.title': { $regex: matchingPattern } },
{ sort: { _id: 1 } }
);
});
this.logger.info(`original event for pattern: ${JSON.stringify(originalEvent)}`);

if (originalEvent) {
return originalEvent;
if (originalEvent) {
return originalEvent;
}
} catch (e) {
this.logger.error(`Error while getting original event for pattern ${matchingPattern}`)
}
}
}
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 @@ export default class JavascriptEventWorker extends EventWorker {
* 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 @@ export default class JavascriptEventWorker extends EventWorker {
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
*/
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 @@ export default class JavascriptEventWorker extends EventWorker {
/**
* 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 @@ export default class JavascriptEventWorker extends EventWorker {
},
/**
* 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 @@ export default class JavascriptEventWorker extends EventWorker {
}
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
Loading
Loading