-
Notifications
You must be signed in to change notification settings - Fork 14
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
Patterns: Use runtime datasource for queries #672
Merged
gtk-grafana
merged 41 commits into
main
from
gtk-grafana/issues/670/patterns-runtime-resource-call
Aug 13, 2024
Merged
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9e7aa16
chore: refactor to allow multiple queries
gtk-grafana d55c9ac
chore: wip - major functionality implemented
gtk-grafana 80879ca
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/67…
gtk-grafana bc010ee
chore: refactor patterns
gtk-grafana b786d67
chore: clean up
gtk-grafana 468361b
chore: clean up
gtk-grafana af3673f
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/67…
gtk-grafana 6bda2fd
test: fix test
gtk-grafana a34dc57
fix: refactor and fix buggy re-rendering in logs panels
gtk-grafana d3f1486
fix: fix data node not being set from scene cache on route/activation
gtk-grafana 1c2e57b
fix: removing multiple queries per query runner, adding multiple quer…
gtk-grafana c3a6182
chore: remove console.log
gtk-grafana 365a4ef
chore: docs
gtk-grafana 982d76c
chore: why are the videos gone in failed playwright reports?
gtk-grafana 1ef913a
chore: clean up
gtk-grafana 7bcf816
chore: clean up
gtk-grafana 1f4d517
fix: fix table loading state
gtk-grafana bf8c10a
chore: clean up
gtk-grafana 9a9a3e0
chore: clean up
gtk-grafana 6a8241a
chore: clean up def
gtk-grafana e8bbf8c
chore: clean up datasource
gtk-grafana d2907f0
chore: clean up
gtk-grafana bc33f3b
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/67…
gtk-grafana 8e5314c
chore: add loading state
gtk-grafana a851425
chore: add the dang video
gtk-grafana 41f90e8
chore: remove e2e video in ci
gtk-grafana d49c8c2
Merge branch 'main' into gtk-grafana/issues/670/patterns-runtime-reso…
gtk-grafana c4d63aa
fix: dont run when query is already running, or we have cached state
gtk-grafana 9733c28
chore: clean up extra rendering
gtk-grafana 9a5f2ca
chore: remove console.warn
gtk-grafana 4447791
chore: refactor, clean up, remove getPatternsFrames
gtk-grafana 3d56793
chore: rename LogsActionBarScene to ActionBarScene
gtk-grafana b6cfe4d
chore: refactor counter ternary
gtk-grafana e9cd5d7
chore: remove nested if
gtk-grafana 080bf3d
chore: clean up
gtk-grafana 5e5101c
chore: partition queries by resource
gtk-grafana 3101bf8
chore: add assertion that queries do not have multiple targets
gtk-grafana db0b7a7
chore: refactor
gtk-grafana 96f1daf
chore: no need to iterate
gtk-grafana 24a6060
chore: move patterns files
gtk-grafana 4508fc2
chore: update types, prevent runtime error
gtk-grafana 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 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 |
---|---|---|
|
@@ -469,4 +469,5 @@ subqueries | |
dbscan | ||
svgs | ||
Dont | ||
REFID | ||
unroute |
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { SceneComponentProps, sceneGraph, SceneObjectBase, SceneObjectState } from '@grafana/scenes'; | ||
import { Box, Stack, Tab, TabsBar, useStyles2 } from '@grafana/ui'; | ||
import { getExplorationFor } from '../../services/scenes'; | ||
import { getDrilldownSlug, getDrilldownValueSlug, PageSlugs, ValueSlugs } from '../../services/routing'; | ||
import { GoToExploreButton } from './GoToExploreButton'; | ||
import { reportAppInteraction, USER_EVENTS_ACTIONS, USER_EVENTS_PAGES } from '../../services/analytics'; | ||
import { ALL_VARIABLE_VALUE, getLabelsVariable } from '../../services/variables'; | ||
import { SERVICE_NAME } from '../ServiceSelectionScene/ServiceSelectionScene'; | ||
import { navigateToDrilldownPage, navigateToIndex } from '../../services/navigate'; | ||
import React from 'react'; | ||
import { ServiceScene, ServiceSceneState } from './ServiceScene'; | ||
import { GrafanaTheme2 } from '@grafana/data'; | ||
import { css } from '@emotion/css'; | ||
import { BreakdownViewDefinition, breakdownViewsDefinitions } from './BreakdownViews'; | ||
|
||
export interface ActionBarSceneState extends SceneObjectState {} | ||
|
||
export class ActionBarScene extends SceneObjectBase<ActionBarSceneState> { | ||
public static Component = ({ model }: SceneComponentProps<ActionBarScene>) => { | ||
const styles = useStyles2(getStyles); | ||
const exploration = getExplorationFor(model); | ||
let currentBreakdownViewSlug = getDrilldownSlug(); | ||
let allowNavToParent = false; | ||
|
||
if (!Object.values(PageSlugs).includes(currentBreakdownViewSlug)) { | ||
const drilldownValueSlug = getDrilldownValueSlug(); | ||
allowNavToParent = true; | ||
if (drilldownValueSlug === ValueSlugs.field) { | ||
currentBreakdownViewSlug = PageSlugs.fields; | ||
} | ||
if (drilldownValueSlug === ValueSlugs.label) { | ||
currentBreakdownViewSlug = PageSlugs.labels; | ||
} | ||
} | ||
|
||
const serviceScene = sceneGraph.getAncestor(model, ServiceScene); | ||
const { loading, $data, ...state } = serviceScene.useState(); | ||
|
||
return ( | ||
<Box paddingY={0}> | ||
<div className={styles.actions}> | ||
<Stack gap={1}> | ||
<GoToExploreButton exploration={exploration} /> | ||
</Stack> | ||
</div> | ||
|
||
<TabsBar> | ||
{breakdownViewsDefinitions.map((tab, index) => { | ||
return ( | ||
<Tab | ||
data-testid={tab.testId} | ||
key={index} | ||
label={tab.displayName} | ||
active={currentBreakdownViewSlug === tab.value} | ||
counter={loading ? undefined : getCounter(tab, { ...state, $data })} | ||
icon={loading ? 'spinner' : undefined} | ||
onChangeTab={() => { | ||
if ((tab.value && tab.value !== currentBreakdownViewSlug) || allowNavToParent) { | ||
reportAppInteraction( | ||
USER_EVENTS_PAGES.service_details, | ||
USER_EVENTS_ACTIONS.service_details.action_view_changed, | ||
{ | ||
newActionView: tab.value, | ||
previousActionView: currentBreakdownViewSlug, | ||
} | ||
); | ||
|
||
const serviceScene = sceneGraph.getAncestor(model, ServiceScene); | ||
const variable = getLabelsVariable(serviceScene); | ||
const service = variable.state.filters.find((f) => f.key === SERVICE_NAME); | ||
|
||
if (service?.value) { | ||
navigateToDrilldownPage(tab.value, serviceScene); | ||
} else { | ||
navigateToIndex(); | ||
} | ||
} | ||
}} | ||
/> | ||
); | ||
})} | ||
</TabsBar> | ||
</Box> | ||
); | ||
}; | ||
} | ||
const getCounter = (tab: BreakdownViewDefinition, state: ServiceSceneState) => { | ||
switch (tab.value) { | ||
case 'fields': | ||
return state.fieldsCount ?? (state.fields?.filter((l) => l !== ALL_VARIABLE_VALUE) ?? []).length; | ||
case 'patterns': | ||
return state.patternsCount; | ||
case 'labels': | ||
return (state.labels?.filter((l) => l.label !== ALL_VARIABLE_VALUE) ?? []).length; | ||
default: | ||
return undefined; | ||
} | ||
}; | ||
|
||
function getStyles(theme: GrafanaTheme2) { | ||
return { | ||
actions: css({ | ||
[theme.breakpoints.up(theme.breakpoints.values.md)]: { | ||
position: 'absolute', | ||
right: 0, | ||
zIndex: 2, | ||
}, | ||
}), | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { PageSlugs, ValueSlugs } from '../../services/routing'; | ||
import { LogsListScene } from './LogsListScene'; | ||
import { testIds } from '../../services/testIds'; | ||
import { buildLabelValuesBreakdownActionScene, LabelBreakdownScene } from './Breakdowns/LabelBreakdownScene'; | ||
import { FieldsBreakdownScene } from './Breakdowns/FieldsBreakdownScene'; | ||
import { PatternsBreakdownScene } from './Breakdowns/Patterns/PatternsBreakdownScene'; | ||
import { SceneFlexItem, SceneFlexLayout, SceneObject } from '@grafana/scenes'; | ||
import { LogsVolumePanel } from './LogsVolumePanel'; | ||
|
||
interface ValueBreakdownViewDefinition { | ||
displayName: string; | ||
value: ValueSlugs; | ||
testId: string; | ||
getScene: (value: string) => SceneObject; | ||
} | ||
|
||
export interface BreakdownViewDefinition { | ||
displayName: string; | ||
value: PageSlugs; | ||
testId: string; | ||
getScene: (changeFields: (f: string[]) => void) => SceneObject; | ||
} | ||
|
||
export const breakdownViewsDefinitions: BreakdownViewDefinition[] = [ | ||
{ | ||
displayName: 'Logs', | ||
value: PageSlugs.logs, | ||
getScene: () => buildLogsListScene(), | ||
testId: testIds.exploreServiceDetails.tabLogs, | ||
}, | ||
{ | ||
displayName: 'Labels', | ||
value: PageSlugs.labels, | ||
getScene: () => buildLabelBreakdownActionScene(), | ||
testId: testIds.exploreServiceDetails.tabLabels, | ||
}, | ||
{ | ||
displayName: 'Fields', | ||
value: PageSlugs.fields, | ||
getScene: (f) => buildFieldsBreakdownActionScene(f), | ||
testId: testIds.exploreServiceDetails.tabFields, | ||
}, | ||
{ | ||
displayName: 'Patterns', | ||
value: PageSlugs.patterns, | ||
getScene: () => buildPatternsScene(), | ||
testId: testIds.exploreServiceDetails.tabPatterns, | ||
}, | ||
]; | ||
export const valueBreakdownViews: ValueBreakdownViewDefinition[] = [ | ||
{ | ||
displayName: 'Label', | ||
value: ValueSlugs.label, | ||
getScene: (value: string) => buildLabelValuesBreakdownActionScene(value), | ||
testId: testIds.exploreServiceDetails.tabLabels, | ||
}, | ||
{ | ||
displayName: 'Field', | ||
value: ValueSlugs.field, | ||
getScene: (value: string) => buildFieldValuesBreakdownActionScene(value), | ||
testId: testIds.exploreServiceDetails.tabFields, | ||
}, | ||
]; | ||
|
||
function buildPatternsScene() { | ||
return new SceneFlexLayout({ | ||
children: [ | ||
new SceneFlexItem({ | ||
body: new PatternsBreakdownScene({}), | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
function buildFieldsBreakdownActionScene(changeFieldNumber: (n: string[]) => void) { | ||
return new SceneFlexLayout({ | ||
children: [ | ||
new SceneFlexItem({ | ||
body: new FieldsBreakdownScene({ changeFields: changeFieldNumber }), | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
function buildFieldValuesBreakdownActionScene(value: string) { | ||
return new SceneFlexLayout({ | ||
children: [ | ||
new SceneFlexItem({ | ||
body: new FieldsBreakdownScene({ value }), | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
function buildLogsListScene() { | ||
return new SceneFlexLayout({ | ||
direction: 'column', | ||
children: [ | ||
new SceneFlexItem({ | ||
minHeight: 200, | ||
body: new LogsVolumePanel({}), | ||
}), | ||
new SceneFlexItem({ | ||
minHeight: '470px', | ||
height: 'calc(100vh - 500px)', | ||
body: new LogsListScene({}), | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
function buildLabelBreakdownActionScene() { | ||
return new SceneFlexLayout({ | ||
children: [ | ||
new SceneFlexItem({ | ||
body: new LabelBreakdownScene({}), | ||
}), | ||
], | ||
}); | ||
} |
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.
We don't need multiple queries anymore, and I would highly suggest we don't mix queries that call different API endpoints, but if we wanted to include multiple queries that call the same API endpoint this should work.
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.
At first glance, I like this ability of running more than one query. What was the original purpose of this change?
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.
Initially I tried to smoosh all the queries into $data, which was a bad idea as queries would end at different times, but if we have multiple data queries, that should work fine as they are all returned from the backend at the same time
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.
I think it makes sense for "combined panels", i.e. the ones at the service selection scene, where we do one logs and one metrics query for each service 👍
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.
Good point, that's probably worth opening in another issue. Might be good for the lazy-loaded panels as well to at least batch things up a bit.