-
Notifications
You must be signed in to change notification settings - Fork 19
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/uptime query v3 #1054
Open
ckbedwell
wants to merge
14
commits into
main
Choose a base branch
from
feat/uptime-query-v3
base: main
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
Feat/uptime query v3 #1054
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
30bb3e5
chore: remove singlecheckmode arg
ckbedwell 5f13750
chore: move to using single check in scenes rather than supposed array
ckbedwell f07b7bb
feat: updated uptime query in scenes dashboards. removed uptimequeryv…
ckbedwell 9dc281a
feat: updating uptime query across app
ckbedwell 1700842
feat: added queries folder
ckbedwell d3c4fd4
feat: uptime v3 with docs
ckbedwell 9c7b285
Merge branch 'main' into chore/remove-unused-singlecheckmode
ckbedwell 2c7156d
chore: revert uptime query
ckbedwell c818992
feat: uptime v3 query in uptimestat
ckbedwell f609a71
fix: update uptime.md text
ckbedwell eab7131
fix: update checklist sort test
ckbedwell c0e79e4
fix: tweak uptime documentation
ckbedwell d34911c
chore: merged in main
ckbedwell 2138e10
feat: add common timerange for scenes component
ckbedwell 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 +1,12 @@ | ||
import { type QueryKey, useQuery } from '@tanstack/react-query'; | ||
import { getUptimeQuery } from 'queries/uptime'; | ||
|
||
import { Check } from 'types'; | ||
import { queryMetric } from 'utils'; | ||
import { MetricCheckSuccess, MetricProbeSuccessRate } from 'datasource/responses.types'; | ||
import { useMetricsDS } from 'hooks/useMetricsDS'; | ||
import { STANDARD_REFRESH_INTERVAL } from 'components/constants'; | ||
import { getMinStepFromFrequency } from 'scenes/utils'; | ||
|
||
import { findCheckinMetrics } from './utils'; | ||
import { findCheckinMetrics, getStartEnd, queryInstantMetric, queryRangeMetric } from './utils'; | ||
|
||
const queryKeys: Record<'checkReachability' | 'checkUptime' | 'probeReachability', QueryKey> = { | ||
checkReachability: ['check_reachability'], | ||
|
@@ -16,7 +15,6 @@ const queryKeys: Record<'checkReachability' | 'checkUptime' | 'probeReachability | |
}; | ||
|
||
export function useChecksReachabilitySuccessRate() { | ||
const { options } = useQueryMetric(); | ||
const metricsDS = useMetricsDS(); | ||
const url = metricsDS?.url || ``; | ||
const query = | ||
|
@@ -32,7 +30,7 @@ export function useChecksReachabilitySuccessRate() { | |
return Promise.reject(`You need to have a metrics datasource available.`); | ||
} | ||
|
||
return queryMetric<MetricCheckSuccess>(url, query, options); | ||
return queryInstantMetric<MetricCheckSuccess>({ url, query, ...getStartEnd() }); | ||
}, | ||
refetchInterval: (query) => STANDARD_REFRESH_INTERVAL, | ||
enabled: Boolean(metricsDS), | ||
|
@@ -50,36 +48,44 @@ export function useCheckReachabilitySuccessRate(check: Check) { | |
} | ||
|
||
export function useCheckUptimeSuccessRate(check: Check) { | ||
const { options } = useQueryMetric(getMinStepFromFrequency(check.frequency)); | ||
const metricsDS = useMetricsDS(); | ||
const url = metricsDS?.url || ``; | ||
|
||
const query = ` | ||
ceil( | ||
sum by (instance, job) (increase(probe_all_success_sum{instance="${check.target}", job="${check.job}"}[3h])) | ||
/ | ||
(sum by (instance, job) (increase(probe_all_success_count{instance="${check.target}", job="${check.job}"}[3h])) + 1) | ||
)`; | ||
const { expr, interval } = getUptimeQuery({ | ||
job: check.job, | ||
instance: check.target, | ||
frequency: check.frequency, | ||
}); | ||
|
||
return useQuery({ | ||
// we add 'now' as an option so can't add it to the query key | ||
// otherwise it would continuously refetch | ||
// eslint-disable-next-line @tanstack/query/exhaustive-deps | ||
queryKey: [...queryKeys.checkUptime, query, url], | ||
queryFn: () => { | ||
queryKey: [...queryKeys.checkUptime, expr, url], | ||
queryFn: async () => { | ||
if (!metricsDS) { | ||
return Promise.reject(`You need to have a metrics datasource available.`); | ||
} | ||
|
||
return queryMetric<MetricCheckSuccess>(url, query, options); | ||
return queryRangeMetric({ url, query: expr, ...getStartEnd(), step: interval }); | ||
}, | ||
select: (data) => { | ||
const vals = data[0].values; | ||
const total = vals.reduce((acc, [_, value]) => { | ||
return acc + Number(value); | ||
}, 0); | ||
|
||
if (vals.length === 0) { | ||
return null; | ||
} | ||
|
||
return total / vals.length; | ||
Comment on lines
+71
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing this will ignore NODATA. |
||
}, | ||
refetchInterval: (query) => STANDARD_REFRESH_INTERVAL, | ||
enabled: Boolean(metricsDS), | ||
}); | ||
} | ||
|
||
export function useProbesReachabilitySuccessRate() { | ||
const { options } = useQueryMetric(); | ||
const metricsDS = useMetricsDS(); | ||
const url = metricsDS?.url || ``; | ||
const query = 'sum(rate(probe_all_success_sum[3h])) by (probe) / sum(rate(probe_all_success_count[3h])) by (probe)'; | ||
|
@@ -94,7 +100,7 @@ export function useProbesReachabilitySuccessRate() { | |
return Promise.reject(`You need to have a metrics datasource available.`); | ||
} | ||
|
||
return queryMetric<MetricProbeSuccessRate>(url, query, options); | ||
return queryInstantMetric<MetricProbeSuccessRate>({ url, query, ...getStartEnd() }); | ||
}, | ||
refetchInterval: (query) => STANDARD_REFRESH_INTERVAL, | ||
enabled: Boolean(metricsDS), | ||
|
@@ -110,17 +116,3 @@ export function useProbeReachabilitySuccessRate(probeName?: string) { | |
data: probe, | ||
}; | ||
} | ||
|
||
function useQueryMetric(interval?: string) { | ||
const now = Math.floor(Date.now() / 1000); | ||
const threeHoursAgo = now - 60 * 60 * 3; | ||
|
||
const options = { | ||
start: threeHoursAgo, | ||
end: now, | ||
step: 0, | ||
interval, | ||
}; | ||
|
||
return { options }; | ||
} |
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
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.
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.
Using interval as the step means a value is returned for each time range where there should be a sample. With a single probe, there's some chance for missing data that was published "too late" (and for the same reason, ignoring intervals where there are two samples, from different executions)