-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #368 from camunda/feat-366
feat(zeebe): implement backoff on UNAUTHENTICATED error for workers
- Loading branch information
Showing
10 changed files
with
218 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Debug Jest Tests", | ||
"program": "${workspaceFolder}/node_modules/jest/bin/jest", | ||
"args": [ | ||
// "Worker-Backoff", // set to the name of the test file you want to run | ||
"--runInBand", | ||
"--watchAll=false" | ||
], | ||
"cwd": "${workspaceFolder}", | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"env": { | ||
"NODE_ENV": "test", | ||
"CAMUNDA_UNIT_TEST": "true", | ||
"ZEEBE_ADDRESS": "localhost:26500", | ||
"ZEEBE_REST_ADDRESS": "http://localhost:8080", | ||
"ZEEBE_GRPC_ADDRESS": "localhost:26500", | ||
"ZEEBE_CLIENT_ID": "zeebe", | ||
"ZEEBE_CLIENT_SECRET": "not_a_real_thing", | ||
"CAMUNDA_OAUTH_URL": "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token", | ||
"ZEEBE_AUTHORIZATION_SERVER_URL": "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token", | ||
"CAMUNDA_TASKLIST_BASE_URL": "http://localhost:8082", | ||
"CAMUNDA_OPERATE_BASE_URL": "http://localhost:8081", | ||
"CAMUNDA_OPTIMIZE_BASE_URL": "http://localhost:8083", | ||
"CAMUNDA_MODELER_BASE_URL": "http://localhost:8070/api", | ||
"CAMUNDA_ZEEBE_OAUTH_AUDIENCE": "zeebe.camunda.io", | ||
"CAMUNDA_TENANT_ID": "<default>", | ||
"CAMUNDA_SECURE_CONNECTION": "false", | ||
"ZEEBE_INSECURE_CONNECTION": "true", | ||
"CAMUNDA_OAUTH_TOKEN_REFRESH_THRESHOLD_MS": "10000", | ||
"CAMUNDA_AUTH_STRATEGY": "OAUTH", | ||
"CAMUNDA_OPTIMIZE_OAUTH_AUDIENCE": "optimize-api", | ||
"ZEEBE_TOKEN_AUDIENCE": "zeebe.camunda.io" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { restoreZeebeLogging, suppressZeebeLogging } from '../../../lib' | ||
import { ZeebeGrpcClient } from '../../../zeebe' | ||
|
||
/** | ||
* This is a manually verified test. To check it, comment out the next line, then check the console output. | ||
* You should see the error messages from the worker, and the backoff expanding the time between them. | ||
*/ | ||
suppressZeebeLogging() | ||
|
||
jest.setTimeout(30000) | ||
afterAll(() => { | ||
restoreZeebeLogging() | ||
}) | ||
|
||
test('Will backoff on UNAUTHENTICATED', (done) => { | ||
let durations = 0 | ||
|
||
const zbc = new ZeebeGrpcClient({ | ||
config: { | ||
CAMUNDA_AUTH_STRATEGY: 'NONE', | ||
CAMUNDA_LOG_LEVEL: 'DEBUG', | ||
}, | ||
}) | ||
|
||
const w = zbc.createWorker({ | ||
taskType: 'unauthenticated-worker', | ||
taskHandler: async () => { | ||
throw new Error('Not Implemented') // is never called | ||
}, | ||
}) | ||
w.on('backoff', (duration) => { | ||
durations += duration | ||
}) | ||
setTimeout(() => { | ||
expect(durations).toBe(31000) | ||
w.close() | ||
done() | ||
}, 25000) | ||
}) | ||
|
||
test('Will use a supplied custom max backoff', (done) => { | ||
let durations = 0 | ||
|
||
const zbc = new ZeebeGrpcClient({ | ||
config: { | ||
CAMUNDA_AUTH_STRATEGY: 'NONE', | ||
CAMUNDA_LOG_LEVEL: 'DEBUG', | ||
CAMUNDA_JOB_WORKER_MAX_BACKOFF_MS: 2000, | ||
}, | ||
}) | ||
|
||
const w = zbc.createWorker({ | ||
taskType: 'unauthenticated-worker', | ||
taskHandler: async () => { | ||
throw new Error('Not Implemented') // is never called | ||
}, | ||
}) | ||
w.on('backoff', (duration) => { | ||
durations += duration | ||
}) | ||
setTimeout(() => { | ||
expect(durations).toBe(11000) | ||
w.close() | ||
done() | ||
}, 10000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
export const ConnectionStatusEvent = { | ||
close: 'close' as const, | ||
/** This is a latched error event. It will fire once to signal the start of a error state. */ | ||
connectionError: 'connectionError' as const, | ||
ready: 'ready' as const, | ||
unknown: 'unknown' as const, | ||
/** The worker is applying a backoff. The duration of the backoff in ms is passed as a parameter to any listener */ | ||
backoff: 'backoff' as const, | ||
/** This is an unlatched error event. It will fire multiple times when an error state is encountered. */ | ||
streamError: 'streamError' as const, | ||
} | ||
|
||
export type ConnectionStatusEventMap = { | ||
close: void | ||
[ConnectionStatusEvent.connectionError]: void | ||
[ConnectionStatusEvent.ready]: void | ||
[ConnectionStatusEvent.unknown]: void | ||
[ConnectionStatusEvent.backoff]: number | ||
[ConnectionStatusEvent.streamError]: Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.