-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding a governor to prevent excessive Datadog calls - Fixed a couple of spots I missed in the CJS migration - Adding the Governor for HTTP posts to Datadog. It's quasi-configurable, but I haven't exposed the config yet. * Update CHANGELOG.md
- Loading branch information
1 parent
d0cbd31
commit 8d7449d
Showing
6 changed files
with
78 additions
and
2 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
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,47 @@ | ||
// Need to use inputs for some of our parameters | ||
const core = require('@actions/core') | ||
|
||
const {DatadogPostGovernor } = require('../../lib/governors') | ||
|
||
describe('DatadogPostGovernor', () => { | ||
test('init', () => { | ||
DatadogPostGovernor.init() | ||
expect(DatadogPostGovernor.state).toBe(0) | ||
expect(DatadogPostGovernor.limit).toBe(10) | ||
DatadogPostGovernor.init(42) | ||
expect(DatadogPostGovernor.state).toBe(0) | ||
expect(DatadogPostGovernor.limit).toBe(42) | ||
}) | ||
|
||
test('increment', () => { | ||
DatadogPostGovernor.init() | ||
expect(DatadogPostGovernor.state).toBe(0) | ||
expect(DatadogPostGovernor.limit).toBe(10) | ||
|
||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(1) | ||
|
||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(2) | ||
}) | ||
|
||
test('enforcement', () => { | ||
DatadogPostGovernor.init(3) | ||
expect(DatadogPostGovernor.state).toBe(0) | ||
expect(DatadogPostGovernor.limit).toBe(3) | ||
|
||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(1) | ||
expect(core.setFailed).not.toHaveBeenCalled() | ||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(2) | ||
expect(core.setFailed).not.toHaveBeenCalled() | ||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(3) | ||
expect(core.setFailed).not.toHaveBeenCalled() | ||
|
||
DatadogPostGovernor.increment() | ||
expect(DatadogPostGovernor.state).toBe(3) | ||
expect(core.setFailed).toHaveBeenCalled() | ||
}) | ||
}) |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
const ddPostGovernor = { | ||
const core = require('@actions/core') | ||
|
||
const DatadogPostGovernor = { | ||
state: undefined, | ||
limit: undefined, | ||
init: (limit = 10) => { | ||
DatadogPostGovernor.limit = limit | ||
DatadogPostGovernor.state = 0 | ||
}, | ||
increment: () => { | ||
if (DatadogPostGovernor.state >= DatadogPostGovernor.limit) { | ||
return core.setFailed(`Rate limit reached. Please do not exceed ${DatadogPostGovernor.limit} calls to Datadog in a single action.`) | ||
} | ||
DatadogPostGovernor.state += 1 | ||
}, | ||
} | ||
|
||
module.exports = { | ||
DatadogPostGovernor | ||
} |