-
Notifications
You must be signed in to change notification settings - Fork 1
Show retry budget usage and why a retry was refused #160
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
Merged
Merged
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import React from "react"; | ||
| import {useResetRetryPolicyUsageMutation, useRetryPolicyUsageQuery} from "src/client/apis/retryPoliciesApi"; | ||
| import Button from "src/components/common/forms/Button"; | ||
| import FormField from "src/components/common/forms/FormField"; | ||
| import Authorize from "src/components/common/authorize/authorize"; | ||
| import dayjs from "dayjs"; | ||
|
|
||
| interface Props { | ||
| policyId: number | ||
| } | ||
|
|
||
| // "Max attempts total" never resets on its own, so an integration that reaches its ceiling stops | ||
| // being retried until someone clears the counter here. Without this panel that state is invisible. | ||
| const RetryBudgetUsage: React.FC<Props> = ({policyId}) => { | ||
|
|
||
| const {data, isLoading, isError, refetch} = useRetryPolicyUsageQuery(policyId) | ||
| const [reset] = useResetRetryPolicyUsageMutation() | ||
|
|
||
| const rows = data ?? [] | ||
| const exhaustedCount = rows.filter(r => r.exhausted).length | ||
|
|
||
| return ( | ||
| <FormField title="Budget usage" | ||
| tooltip="How much of each group's 'max attempts total' the integrations using this policy have spent. The total never resets on its own — clear it here to let a group retry again."> | ||
| <p className={"text-xs text-gray-500 mb-2"}> | ||
| Counted separately for each integration. Integrations that have never failed under this | ||
| policy do not appear. | ||
| </p> | ||
|
|
||
| {isLoading && <p className={"text-sm text-gray-400 italic px-2 py-3"}>Loading…</p>} | ||
|
|
||
| {/* Never fall through to the empty state on failure: "no budget spent" would claim | ||
| every group is untouched when the truth is that we could not find out. */} | ||
| {isError && | ||
| <div className={"flex flex-row items-center justify-between gap-3 text-sm text-red-700 bg-red-50 border border-red-200 rounded px-3 py-2"}> | ||
| <span>Could not load budget usage.</span> | ||
| <Button variant={"secondary"} onClick={() => refetch()}>Try again</Button> | ||
| </div>} | ||
|
|
||
| {!isLoading && !isError && rows.length === 0 && | ||
| <p className={"text-sm text-gray-400 italic px-2 py-3"}> | ||
| No budget spent — every group has its full allowance. | ||
| </p>} | ||
|
|
||
| {!isError && rows.length > 0 && <div className={"flex flex-col gap-2"}> | ||
| {exhaustedCount > 0 && | ||
| <p className={"text-sm text-red-700 bg-red-50 border border-red-200 rounded px-3 py-2"}> | ||
| {exhaustedCount === 1 | ||
| ? "1 integration has exhausted its budget and is no longer being retried." | ||
| : `${exhaustedCount} integrations have exhausted their budget and are no longer being retried.`} | ||
| </p>} | ||
|
|
||
| <table className="appearance-none min-w-full"> | ||
| <thead className="border-y bg-gray-50"> | ||
| <tr> | ||
| <th scope="col" className="text-sm font-medium text-gray-900 px-6 py-2 text-left">Integration</th> | ||
| <th scope="col" className="text-sm font-medium text-gray-900 px-6 py-2 text-left">Group</th> | ||
| <th scope="col" className="text-sm font-medium text-gray-900 px-6 py-2 text-left">Used</th> | ||
| <th scope="col" className="text-sm font-medium text-gray-900 px-6 py-2 text-left">Last retry</th> | ||
| <th scope="col" className="text-sm font-medium text-gray-900 px-6 py-2 text-left"></th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {rows.map((r) => ( | ||
| <tr key={`${r.subscriptionId}-${r.groupId}`} className="bg-white border-b"> | ||
| <td className="text-sm text-gray-900 font-semibold px-6 py-4 whitespace-nowrap"> | ||
| {r.subscriptionName} | ||
| </td> | ||
| <td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"> | ||
| {r.groupName} | ||
| </td> | ||
| <td className="text-sm px-6 py-4 whitespace-nowrap"> | ||
| <span className={r.exhausted ? "text-red-600 font-semibold" : "text-gray-900"}> | ||
| {r.attemptsUsed} / {r.maxAttemptsTotal} | ||
| </span> | ||
| {r.exhausted && | ||
| <span className={"ml-2 inline-block bg-red-100 text-red-700 rounded px-2 py-0.5 text-xs"}> | ||
| Exhausted | ||
| </span>} | ||
| </td> | ||
| <td className="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"> | ||
| {dayjs(r.lastAttemptOn).format("YYYY-MM-DD HH:mm")} | ||
| </td> | ||
| <td className={"px-6 py-4"}> | ||
| <Authorize roles={["Admin", "Member"]}> | ||
| <Button variant={"secondary"} | ||
| onClick={() => reset({ | ||
| id: policyId, | ||
| subscriptionId: r.subscriptionId, | ||
| groupId: r.groupId | ||
| })}> | ||
| Reset | ||
| </Button> | ||
| </Authorize> | ||
| </td> | ||
| </tr> | ||
| ))} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| <Authorize roles={["Admin", "Member"]}> | ||
| <div className={"flex flex-row-reverse"}> | ||
| <Button variant={"secondary"} onClick={() => reset({id: policyId})}> | ||
| Reset all | ||
| </Button> | ||
| </div> | ||
| </Authorize> | ||
|
hamzahalq marked this conversation as resolved.
|
||
| </div>} | ||
| </FormField> | ||
| ); | ||
| } | ||
|
|
||
| export default RetryBudgetUsage; | ||
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
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.
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.