-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: send prometheus metrics when someone tries to exceed resource …
…limits (#7617) This PR adds prometheus metrics for when users attempt to exceed the limits for a given resource. The implementation sets up a second function exported from the ExceedsLimitError file that records metrics and then throws the error. This could also be a static method on the class, but I'm not sure that'd be better.
- Loading branch information
1 parent
19121f2
commit f15bcdc
Showing
12 changed files
with
162 additions
and
16 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,54 @@ | ||
import type EventEmitter from 'events'; | ||
import { EXCEEDS_LIMIT } from '../metric-events'; | ||
import { | ||
ExceedsLimitError, | ||
throwExceedsLimitError, | ||
} from './exceeds-limit-error'; | ||
|
||
it('emits events event when created through the external function', () => { | ||
const emitEvent = jest.fn(); | ||
const resource = 'some-resource'; | ||
const limit = 10; | ||
|
||
expect(() => | ||
throwExceedsLimitError( | ||
{ | ||
emit: emitEvent, | ||
} as unknown as EventEmitter, | ||
{ | ||
resource, | ||
limit, | ||
}, | ||
), | ||
).toThrow(ExceedsLimitError); | ||
|
||
expect(emitEvent).toHaveBeenCalledWith(EXCEEDS_LIMIT, { | ||
resource, | ||
limit, | ||
}); | ||
}); | ||
|
||
it('emits uses the resourceNameOverride for the event when provided, but uses the resource for the error', () => { | ||
const emitEvent = jest.fn(); | ||
const resource = 'not this'; | ||
const resourceNameOverride = 'but this!'; | ||
const limit = 10; | ||
|
||
expect(() => | ||
throwExceedsLimitError( | ||
{ | ||
emit: emitEvent, | ||
} as unknown as EventEmitter, | ||
{ | ||
resource, | ||
resourceNameOverride, | ||
limit, | ||
}, | ||
), | ||
).toThrow(new ExceedsLimitError(resource, limit)); | ||
|
||
expect(emitEvent).toHaveBeenCalledWith(EXCEEDS_LIMIT, { | ||
resource: resourceNameOverride, | ||
limit, | ||
}); | ||
}); |
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
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
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
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