-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(aci): useMetricDetectorLimit #97969
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
feat(aci): useMetricDetectorLimit #97969
Conversation
export function useMetricDetectorLimit(): MetricDetectorLimitResponse { | ||
const organization = useOrganization(); | ||
const subscription = useSubscription(); | ||
const {data: detectors, isLoading, isError} = useDetectorsQuery(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {..., getResponseHeader} = useDetectorsQuery({
query: 'type:metric'
limit: 0
}, {
enabled: !organization.features.includes('workflow-engine-metric-detector-limit') ||
detectorLimit === UNLIMITED_QUOTA
})
const hits = getResponseHeader()['X-Hits'];
const totalMetricDetectors = hits ? parseInt(hits): 0;
This will get the max number through the header so we don't return every detector in the response data, and limit it to metric detectors. Also skips the request if it's not necessary
2381da5
to
2f863e9
Compare
query: 'type:metric', | ||
limit: 0, | ||
}, | ||
{enabled: has_flag} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also disable this request if there is an unlimited quota
0323d7f
to
e74969b
Compare
b326c21
into
malwilley/feat/metric-alert-quota
detectorLimit: -1, | ||
detectorCount: -1, | ||
detectorLimit: UNLIMITED_QUOTA, | ||
detectorCount, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Hook Misinterprets Header, Bypasses Limits
The hook incorrectly parses non-numeric X-Hits
header values, resulting in detectorCount
being NaN
. This causes hasReachedLimit
to always be false and isError
to be incorrect, potentially bypassing detector limits. Additionally, the detector query runs unnecessarily when detectorLimit
is unlimited, and the hook's early return then misreports isLoading
and isError
states.
Used by #97953