Skip to content

Commit

Permalink
chore: add tracing for tracking disp retries
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlaud committed Jun 9, 2023
1 parent 9169dec commit dfa21a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ const logger = require('./log');
import axiosRetry from 'axios-retry';

const axiosInstance = axios.create({
timeout: 5000,
timeout: 2500,
});

axiosRetry(axiosInstance, {
retries: 3,
retryCondition: () => true, // retry no matter what
shouldResetTimeout: true,
retryDelay: axiosRetry.exponentialDelay,
onRetry: (retryCount, error, requestConfig) => {
if (error) {
if (retryCount > 2) {
logger.warn(
{
retryCount,
Expand All @@ -20,7 +21,7 @@ axiosRetry(axiosInstance, {
requestId:
requestConfig.headers && requestConfig.headers['Snyk-Request-Id'],
},
'retrying request',
`retrying request x ${retryCount} `,
);
}
},
Expand Down
15 changes: 7 additions & 8 deletions test/functional/dispatcher-server-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ describe('Broker Server Dispatcher API interaction', () => {
await expect(
dispatcher.clientConnected(token, clientId, clientVersion),
).resolves.not.toThrowError();
expect(spyLogWarn).toHaveBeenCalledTimes(3);
for (let i = 0; i < 3; i++) {
const output = spyLogWarn.mock.calls[i][0] as Object;
expect(output['errorMessage']).toEqual(
'Request failed with status code 500',
);
expect(output['retryCount']).toEqual(i + 1);
}
expect(spyLogWarn).toHaveBeenCalledTimes(1);

const output = spyLogWarn.mock.calls[0][0] as Object;
expect(output['errorMessage']).toEqual(
'Request failed with status code 500',
);
expect(output['retryCount']).toEqual(3);

expect(spyLogError).toBeCalledTimes(1);
const errorOutput = spyLogError.mock.calls[0][0] as Object;
Expand Down

0 comments on commit dfa21a0

Please # to comment.