Skip to content

Commit

Permalink
[OTE-600] Emit metrics for geoblock endpoint (#2000)
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 authored Aug 1, 2024
1 parent b953cf6 commit a7f676a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ describe('ComplianceV2Controller', () => {
}));
toBech32Mock.mockReturnValue(testConstants.defaultAddress);
jest.spyOn(DateTime, 'now').mockReturnValue(DateTime.fromSeconds(1620000000)); // Mock current time
jest.spyOn(stats, 'increment');
});

afterEach(async () => {
Expand Down Expand Up @@ -468,6 +469,11 @@ describe('ComplianceV2Controller', () => {
reason: ComplianceReason.US_GEO,
}));

expect(stats.increment).toHaveBeenCalledWith(`${config.SERVICE_NAME}.compliance-v2-controller.geo_block.compliance_status_changed.count`,
{
newStatus: ComplianceStatus.BLOCKED,
});

expect(response.body.status).toEqual(ComplianceStatus.BLOCKED);
expect(response.body.reason).toEqual(ComplianceReason.US_GEO);
expect(response.body.updatedAt).toBeDefined();
Expand Down Expand Up @@ -495,6 +501,10 @@ describe('ComplianceV2Controller', () => {
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: ComplianceReason.US_GEO,
}));
expect(stats.increment).toHaveBeenCalledWith(`${config.SERVICE_NAME}.compliance-v2-controller.geo_block.compliance_status_changed.count`,
{
newStatus: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
});

expect(response.body.status).toEqual(ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY);
expect(response.body.reason).toEqual(ComplianceReason.US_GEO);
Expand Down Expand Up @@ -574,6 +584,11 @@ describe('ComplianceV2Controller', () => {
expectedStatus: 200,
});

expect(stats.increment).toHaveBeenCalledWith(`${config.SERVICE_NAME}.compliance-v2-controller.geo_block.compliance_status_changed.count`,
{
newStatus: ComplianceStatus.CLOSE_ONLY,
});

const data: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll({}, [], {});
expect(data).toHaveLength(1);
expect(data[0]).toEqual(expect.objectContaining({
Expand Down Expand Up @@ -608,7 +623,6 @@ describe('ComplianceV2Controller', () => {
},
expectedStatus: 200,
});

const data: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll({}, [], {});
expect(data).toHaveLength(1);
expect(data[0]).toEqual(expect.objectContaining({
Expand Down Expand Up @@ -642,6 +656,10 @@ describe('ComplianceV2Controller', () => {
},
expectedStatus: 200,
});
expect(stats.increment).toHaveBeenCalledWith(`${config.SERVICE_NAME}.compliance-v2-controller.geo_block.compliance_status_changed.count`,
{
newStatus: ComplianceStatus.CLOSE_ONLY,
});

const data: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll({}, [], {});
expect(data).toHaveLength(1);
Expand Down Expand Up @@ -675,6 +693,10 @@ describe('ComplianceV2Controller', () => {
},
expectedStatus: 200,
});
expect(stats.increment).toHaveBeenCalledWith(`${config.SERVICE_NAME}.compliance-v2-controller.geo_block.compliance_status_changed.count`,
{
newStatus: ComplianceStatus.FIRST_STRIKE,
});

const data: ComplianceStatusFromDatabase[] = await ComplianceStatusTable.findAll({}, [], {});
expect(data).toHaveLength(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ router.post(
complianceStatus,
updatedAt,
);
if (complianceStatus.length === 0 ||
complianceStatus[0] !== complianceStatusFromDatabase) {
if (complianceStatusFromDatabase !== undefined &&
complianceStatusFromDatabase.status !== ComplianceStatus.COMPLIANT
) {
stats.increment(
`${config.SERVICE_NAME}.${controllerName}.geo_block.compliance_status_changed.count`,
{
newStatus: complianceStatusFromDatabase!.status,
},
);
}
}

const response = {
status: complianceStatusFromDatabase!.status,
Expand Down

0 comments on commit a7f676a

Please sign in to comment.