-
Notifications
You must be signed in to change notification settings - Fork 0
fix: reject lossy metering usage values #1630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kang-heewon
wants to merge
2
commits into
trunk
Choose a base branch
from
fix/1577-integer-usage-values
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| "@croco/metering-core": minor | ||
| "@croco/problems-core": patch | ||
| --- | ||
|
|
||
| Reject usage values outside the positive 32-bit integer range before idempotency or storage, and fail closed when Redis contains an invalid or unsafe accumulated value. | ||
This file contains hidden or 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
298 changes: 298 additions & 0 deletions
298
...docs/src/content/docs/api/metering-core/src/classes/InvalidUsageValueProblem.md
This file contains hidden or 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,298 @@ | ||
| --- | ||
| editUrl: false | ||
| next: false | ||
| prev: false | ||
| title: "InvalidUsageValueProblem" | ||
| --- | ||
|
|
||
| A usage record contains a value that cannot be represented by every supported storage adapter. | ||
|
|
||
| ## Extends | ||
|
|
||
| - [`Problem`](/api/problems-core/src/classes/problem/) | ||
|
|
||
| ## Constructors | ||
|
|
||
| ### Constructor | ||
|
|
||
| > **new InvalidUsageValueProblem**(`value`, `reason?`): `InvalidUsageValueProblem` | ||
|
|
||
| #### Parameters | ||
|
|
||
| ##### value | ||
|
|
||
| `number` | ||
|
|
||
| ##### reason? | ||
|
|
||
| `string` = `...` | ||
|
|
||
| #### Returns | ||
|
|
||
| `InvalidUsageValueProblem` | ||
|
|
||
| #### Overrides | ||
|
|
||
| `Problem.constructor` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### category | ||
|
|
||
| > `readonly` **category**: [`ProblemCategory`](/api/problems-core/src/enumerations/problemcategory/) | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`category`](/api/problems-core/src/classes/problem/#category) | ||
|
|
||
| *** | ||
|
|
||
| ### cause? | ||
|
|
||
| > `readonly` `optional` **cause?**: `Error` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`cause`](/api/problems-core/src/classes/problem/#cause) | ||
|
|
||
| *** | ||
|
|
||
| ### code | ||
|
|
||
| > `readonly` **code**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`code`](/api/problems-core/src/classes/problem/#code) | ||
|
|
||
| *** | ||
|
|
||
| ### detail? | ||
|
|
||
| > `readonly` `optional` **detail?**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`detail`](/api/problems-core/src/classes/problem/#detail) | ||
|
|
||
| *** | ||
|
|
||
| ### extensions? | ||
|
|
||
| > `readonly` `optional` **extensions?**: [`ProblemExtensions`](/api/problems-core/src/type-aliases/problemextensions/) | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`extensions`](/api/problems-core/src/classes/problem/#extensions) | ||
|
|
||
| *** | ||
|
|
||
| ### instance? | ||
|
|
||
| > `readonly` `optional` **instance?**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`instance`](/api/problems-core/src/classes/problem/#instance) | ||
|
|
||
| *** | ||
|
|
||
| ### message | ||
|
|
||
| > **message**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`message`](/api/problems-core/src/classes/problem/#message) | ||
|
|
||
| *** | ||
|
|
||
| ### name | ||
|
|
||
| > **name**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`name`](/api/problems-core/src/classes/problem/#name) | ||
|
|
||
| *** | ||
|
|
||
| ### stack? | ||
|
|
||
| > `optional` **stack?**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`stack`](/api/problems-core/src/classes/problem/#stack) | ||
|
|
||
| *** | ||
|
|
||
| ### type | ||
|
|
||
| > `readonly` **type**: `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`type`](/api/problems-core/src/classes/problem/#type) | ||
|
|
||
| *** | ||
|
|
||
| ### stackTraceLimit | ||
|
|
||
| > `static` **stackTraceLimit**: `number` | ||
|
|
||
| The `Error.stackTraceLimit` property specifies the number of stack frames | ||
| collected by a stack trace (whether generated by `new Error().stack` or | ||
| `Error.captureStackTrace(obj)`). | ||
|
|
||
| The default value is `10` but may be set to any valid JavaScript number. Changes | ||
| will affect any stack trace captured _after_ the value has been changed. | ||
|
|
||
| If set to a non-number value, or set to a negative number, stack traces will | ||
| not capture any frames. | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`stackTraceLimit`](/api/problems-core/src/classes/problem/#stacktracelimit) | ||
|
|
||
| ## Accessors | ||
|
|
||
| ### status | ||
|
|
||
| #### Get Signature | ||
|
|
||
| > **get** **status**(): `number` | ||
|
|
||
| ##### Returns | ||
|
|
||
| `number` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`status`](/api/problems-core/src/classes/problem/#status) | ||
|
|
||
| *** | ||
|
|
||
| ### title | ||
|
|
||
| #### Get Signature | ||
|
|
||
| > **get** **title**(): `string` | ||
|
|
||
| ##### Returns | ||
|
|
||
| `string` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`title`](/api/problems-core/src/classes/problem/#title) | ||
|
|
||
| ## Methods | ||
|
|
||
| ### toJSON() | ||
|
|
||
| > **toJSON**(): [`ProblemDetails`](/api/problems-core/src/type-aliases/problemdetails/) | ||
|
|
||
| #### Returns | ||
|
|
||
| [`ProblemDetails`](/api/problems-core/src/type-aliases/problemdetails/) | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`toJSON`](/api/problems-core/src/classes/problem/#tojson) | ||
|
|
||
| *** | ||
|
|
||
| ### captureStackTrace() | ||
|
|
||
| > `static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` | ||
|
|
||
| Creates a `.stack` property on `targetObject`, which when accessed returns | ||
| a string representing the location in the code at which | ||
| `Error.captureStackTrace()` was called. | ||
|
|
||
| ```js | ||
| const myObject = {}; | ||
| Error.captureStackTrace(myObject); | ||
| myObject.stack; // Similar to `new Error().stack` | ||
| ``` | ||
|
|
||
| The first line of the trace will be prefixed with | ||
| `${myObject.name}: ${myObject.message}`. | ||
|
|
||
| The optional `constructorOpt` argument accepts a function. If given, all frames | ||
| above `constructorOpt`, including `constructorOpt`, will be omitted from the | ||
| generated stack trace. | ||
|
|
||
| The `constructorOpt` argument is useful for hiding implementation | ||
| details of error generation from the user. For instance: | ||
|
|
||
| ```js | ||
| function a() { | ||
| b(); | ||
| } | ||
|
|
||
| function b() { | ||
| c(); | ||
| } | ||
|
|
||
| function c() { | ||
| // Create an error without stack trace to avoid calculating the stack trace twice. | ||
| const { stackTraceLimit } = Error; | ||
| Error.stackTraceLimit = 0; | ||
| const error = new Error(); | ||
| Error.stackTraceLimit = stackTraceLimit; | ||
|
|
||
| // Capture the stack trace above function b | ||
| Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace | ||
| throw error; | ||
| } | ||
|
|
||
| a(); | ||
| ``` | ||
|
|
||
| #### Parameters | ||
|
|
||
| ##### targetObject | ||
|
|
||
| `object` | ||
|
|
||
| ##### constructorOpt? | ||
|
|
||
| `Function` | ||
|
|
||
| #### Returns | ||
|
|
||
| `void` | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`captureStackTrace`](/api/problems-core/src/classes/problem/#capturestacktrace) | ||
|
|
||
| *** | ||
|
|
||
| ### prepareStackTrace() | ||
|
|
||
| > `static` **prepareStackTrace**(`err`, `stackTraces`): `any` | ||
|
|
||
| #### Parameters | ||
|
|
||
| ##### err | ||
|
|
||
| `Error` | ||
|
|
||
| ##### stackTraces | ||
|
|
||
| `CallSite`[] | ||
|
|
||
| #### Returns | ||
|
|
||
| `any` | ||
|
|
||
| #### See | ||
|
|
||
| https://v8.dev/docs/stack-trace-api#customizing-stack-traces | ||
|
|
||
| #### Inherited from | ||
|
|
||
| [`Problem`](/api/problems-core/src/classes/problem/).[`prepareStackTrace`](/api/problems-core/src/classes/problem/#preparestacktrace) |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.