Repository navigation
fix: Fix Services Dashboard bugs #1484
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
8 commits
Select commit
Hold shift + click to select a range
83fd7f2
fix: Prevent errors from DESCRIBEing CTEs
pulpdrew 3a71b3e
fix: Prevent extra Request Throughput refetches
pulpdrew 17b0556
fix: Prevent extra Services Dashboard requests when switching sources
pulpdrew 209c5b2
test: Fix integration test after renderChartConfig update
pulpdrew 4bf27bc
fix: Prevent errors on services dashboard when source has metricTable…
pulpdrew 5a54d45
fix: Fix render loop
pulpdrew 58da5ee
fix: Use the right source value in effect
pulpdrew 7644d23
Merge branch 'main' into drew/services-dashboard-fixes
pulpdrew 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,7 @@ | ||
| --- | ||
| "@hyperdx/common-utils": patch | ||
| "@hyperdx/api": patch | ||
| "@hyperdx/app": patch | ||
| --- | ||
|
|
||
| fix: Fix bugs in the Services dashboard |
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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { | |
| useQueryState, | ||
| useQueryStates, | ||
| } from 'nuqs'; | ||
| import { UseControllerProps, useForm } from 'react-hook-form'; | ||
| import { UseControllerProps, useForm, useWatch } from 'react-hook-form'; | ||
| import { tcFromSource } from '@hyperdx/common-utils/dist/core/metadata'; | ||
| import { DEFAULT_AUTO_GRANULARITY_MAX_BUCKETS } from '@hyperdx/common-utils/dist/core/renderChartConfig'; | ||
| import { | ||
|
|
@@ -128,7 +128,7 @@ function ServiceSelectControlled({ | |
| const { expressions } = useServiceDashboardExpressions({ source }); | ||
|
|
||
| const queriedConfig = { | ||
| ...source, | ||
| timestampValueExpression: source?.timestampValueExpression || '', | ||
| from: { | ||
| databaseName: source?.from.databaseName || '', | ||
| tableName: source?.from.tableName || '', | ||
|
|
@@ -240,7 +240,11 @@ export function EndpointLatencyChart({ | |
| 'avg_duration_ns', | ||
| ]} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| select: [ | ||
|
|
@@ -289,7 +293,11 @@ export function EndpointLatencyChart({ | |
| ) : ( | ||
| <DBHistogramChart | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| select: [ | ||
|
|
@@ -343,7 +351,7 @@ function HttpTab({ | |
| if (!source || !expressions) return null; | ||
| if (reqChartType === 'overall') { | ||
| return { | ||
| ...source, | ||
| ...pick(source, ['timestampValueExpression', 'connection', 'from']), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| displayType: DisplayType.Line, | ||
|
|
@@ -539,13 +547,14 @@ function HttpTab({ | |
| <DBTimeChart | ||
| sourceId={source.id} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| displayType: | ||
| reqChartType === 'overall' | ||
| ? DisplayType.Line | ||
| : DisplayType.StackedBar, | ||
| displayType: DisplayType.Line, | ||
| select: [ | ||
| { | ||
| aggFn: 'count' as const, | ||
|
|
@@ -582,7 +591,11 @@ function HttpTab({ | |
| 'error_requests', | ||
| ]} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| select: [ | ||
|
|
@@ -703,7 +716,11 @@ function HttpTab({ | |
| 'error_count', | ||
| ]} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| select: [ | ||
|
|
@@ -1122,7 +1139,11 @@ function DatabaseTab({ | |
| 'p50_duration_ns', | ||
| ]} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| dateRange: searchedTimeRange, | ||
|
|
@@ -1198,7 +1219,11 @@ function DatabaseTab({ | |
| 'p50_duration_ns', | ||
| ]} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| dateRange: searchedTimeRange, | ||
|
|
@@ -1292,7 +1317,11 @@ function ErrorsTab({ | |
| <DBTimeChart | ||
| sourceId={source.id} | ||
| config={{ | ||
| ...source, | ||
| ...pick(source, [ | ||
| 'timestampValueExpression', | ||
| 'connection', | ||
| 'from', | ||
| ]), | ||
| where: appliedConfig.where || '', | ||
| whereLanguage: appliedConfig.whereLanguage || 'sql', | ||
| displayType: DisplayType.StackedBar, | ||
|
|
@@ -1341,13 +1370,34 @@ function ServicesDashboardPage() { | |
|
|
||
| const { data: sources } = useSources(); | ||
|
|
||
| const [appliedConfig, setAppliedConfig] = useQueryStates(appliedConfigMap); | ||
| const [appliedConfigParams, setAppliedConfigParams] = | ||
| useQueryStates(appliedConfigMap); | ||
|
|
||
| // Only use the source from the URL params if it is a trace source | ||
| const appliedConfig = useMemo(() => { | ||
| if (!sources?.length) return appliedConfigParams; | ||
|
|
||
| const traceSources = sources?.filter(s => s.kind === SourceKind.Trace); | ||
| const paramsSourceIdIsTraceSource = traceSources?.find( | ||
| s => s.id === appliedConfigParams.source, | ||
| ); | ||
|
|
||
| const effectiveSourceId = paramsSourceIdIsTraceSource | ||
| ? appliedConfigParams.source | ||
| : traceSources?.[0]?.id || ''; | ||
|
|
||
| return { | ||
| ...appliedConfigParams, | ||
| source: effectiveSourceId, | ||
| }; | ||
| }, [appliedConfigParams, sources]); | ||
|
|
||
| const { control, watch, setValue, handleSubmit } = useForm({ | ||
| values: { | ||
| defaultValues: { | ||
| where: '', | ||
| whereLanguage: 'sql' as 'sql' | 'lucene', | ||
| service: appliedConfig?.service || '', | ||
| source: appliedConfig?.source || sources?.[0]?.id, | ||
| source: appliedConfig?.source ?? '', | ||
| }, | ||
| }); | ||
|
|
||
|
|
@@ -1357,11 +1407,19 @@ function ServicesDashboardPage() { | |
| id: watch('source'), | ||
| }); | ||
|
|
||
| // Update the `source` query parameter if the appliedConfig source changes | ||
| useEffect(() => { | ||
| if (sourceId && !appliedConfig.source) { | ||
| setAppliedConfig({ source: sourceId }); | ||
| if ( | ||
| appliedConfig.source && | ||
| appliedConfig.source !== appliedConfigParams.source | ||
| ) { | ||
| setAppliedConfigParams({ source: appliedConfig.source }); | ||
| } | ||
| }, [appliedConfig.source, setAppliedConfig, sourceId]); | ||
| }, [ | ||
| appliedConfig.source, | ||
| appliedConfigParams.source, | ||
| setAppliedConfigParams, | ||
| ]); | ||
|
|
||
| const DEFAULT_INTERVAL = 'Past 1h'; | ||
| const [displayedTimeInputValue, setDisplayedTimeInputValue] = | ||
|
|
@@ -1374,7 +1432,7 @@ function ServicesDashboardPage() { | |
| }); | ||
|
|
||
| // For future use if Live button is added | ||
| const [isLive, setIsLive] = useState(false); | ||
| const [isLive, _setIsLive] = useState(false); | ||
|
|
||
| const { manualRefreshCooloff, refresh } = useDashboardRefresh({ | ||
| searchedTimeRange, | ||
|
|
@@ -1385,30 +1443,38 @@ function ServicesDashboardPage() { | |
| const onSubmit = useCallback(() => { | ||
| onSearch(displayedTimeInputValue); | ||
| handleSubmit(values => { | ||
| setAppliedConfig(values); | ||
| setAppliedConfigParams(values); | ||
| })(); | ||
| }, [handleSubmit, setAppliedConfig, onSearch, displayedTimeInputValue]); | ||
| }, [handleSubmit, setAppliedConfigParams, onSearch, displayedTimeInputValue]); | ||
|
|
||
| // Auto submit when service or source changes | ||
| // Auto-submit when source changes | ||
| useEffect(() => { | ||
| const normalizedService = service ?? ''; | ||
| const appliedService = appliedConfig.service ?? ''; | ||
| const normalizedSource = sourceId ?? ''; | ||
| const appliedSource = appliedConfig.source ?? ''; | ||
| const { unsubscribe } = watch((data, { name, type }) => { | ||
| if ( | ||
| name === 'source' && | ||
| type === 'change' && | ||
| data.source && | ||
| data.source !== appliedConfig.source | ||
| ) { | ||
| onSubmit(); | ||
| } | ||
| }); | ||
| return () => unsubscribe(); | ||
| }, [appliedConfig.source, onSubmit, watch]); | ||
|
|
||
| if ( | ||
| normalizedService !== appliedService || | ||
| (normalizedSource && normalizedSource !== appliedSource) | ||
| ) { | ||
| onSubmit(); | ||
| } | ||
| }, [ | ||
| service, | ||
| sourceId, | ||
| appliedConfig.service, | ||
| appliedConfig.source, | ||
| onSubmit, | ||
| ]); | ||
| // Auto-submit when service changes | ||
| useEffect(() => { | ||
| const { unsubscribe } = watch((data, { name, type }) => { | ||
| if ( | ||
| name === 'service' && | ||
| type === 'change' && | ||
| data.service !== appliedConfig.service | ||
| ) { | ||
| onSubmit(); | ||
| } | ||
| }); | ||
| return () => unsubscribe(); | ||
| }, [appliedConfig.service, onSubmit, watch]); | ||
|
Comment on lines
+1466
to
+1477
Contributor
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. ditto |
||
|
|
||
| return ( | ||
| <Box p="sm"> | ||
|
|
@@ -1554,7 +1620,7 @@ const ServicesDashboardPageDynamic = dynamic( | |
| }, | ||
| ); | ||
|
|
||
| // @ts-ignore | ||
| // @ts-expect-error Next.js layout typing | ||
| ServicesDashboardPageDynamic.getLayout = withAppNav; | ||
|
|
||
| export default ServicesDashboardPageDynamic; | ||
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.
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.
Should this be a
useWatchwith a control?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.
The intent here is to auto-submit the form when the form's source field changes.
With useWatch, I believe we'd then need an additional useEffect (like the one in the old version of this code) to trigger the onSubmit when
source != appliedConfig.source. However, that resulted in render loops when navigating away from the page, sinceappliedConfig.sourcechanges during navigation away (since the URL params are changing).Is there a particular issue with this approach (watch callback) that I should be aware of?