Skip to content
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: Logs sample #430

Merged
merged 30 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cda8d2a
chore(patterns): wip poc
gtk-grafana Jun 7, 2024
04b2947
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/38…
gtk-grafana Jun 7, 2024
4861376
chore(patterns): wip poc
gtk-grafana Jun 7, 2024
3324068
chore: document/comment
gtk-grafana Jun 10, 2024
449451e
fix(patterns): refactor expanded row to fix orphaned scene bug - wip
gtk-grafana Jun 10, 2024
3f22c45
Merge branch 'main' into gtk-grafana/issues/389/patterns-table-log-sa…
gtk-grafana Jun 11, 2024
ddc29c8
chore(patterns): interpolate query string pattern value
gtk-grafana Jun 11, 2024
75c380e
feat(patterns): include all indexed labels to patterns query, and pat…
gtk-grafana Jun 11, 2024
1b4fd90
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/38…
gtk-grafana Jun 17, 2024
e0bcfcc
chore(patterns): apply detected field and line-filter to patterns sam…
gtk-grafana Jun 17, 2024
debdb2a
chore: update dependencies to 11.1
gtk-grafana Jun 27, 2024
7cc9bdd
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/38…
gtk-grafana Jul 26, 2024
478ec14
feat: if first query is empty, run without filters and show warning
gtk-grafana Jul 26, 2024
9250a11
chore: add error state if second query fails to get results
gtk-grafana Jul 26, 2024
4b7503e
fix: allow filtering after removing line-filter
gtk-grafana Jul 26, 2024
054fbd8
chore: clean up
gtk-grafana Jul 26, 2024
d0127ff
chore: add error state for initial query
gtk-grafana Jul 26, 2024
0779607
chore: refactor
gtk-grafana Jul 26, 2024
6dc343b
chore: update error message
gtk-grafana Jul 26, 2024
db2d687
chore: update error message
gtk-grafana Jul 26, 2024
2d66c1e
Merge remote-tracking branch 'origin/main' into gtk-grafana/issues/38…
gtk-grafana Aug 1, 2024
0c0ddb5
chore: cleanup/refactor
gtk-grafana Aug 2, 2024
3279d2c
chore: cleanup/refactor
gtk-grafana Aug 2, 2024
58663dd
chore: whoopsie
gtk-grafana Aug 2, 2024
f1d1ad3
Merge branch 'main' into gtk-grafana/issues/389/patterns-table-log-sa…
gtk-grafana Aug 2, 2024
9de4e6a
Merge branch 'main' into gtk-grafana/issues/389/patterns-table-log-sa…
gtk-grafana Aug 2, 2024
49b076e
chore: fix after main refactor
gtk-grafana Aug 2, 2024
5ad556f
Merge branch 'main' into gtk-grafana/issues/389/patterns-table-log-sa…
gtk-grafana Aug 2, 2024
8997905
chore: update spellcheck
gtk-grafana Aug 2, 2024
84f8a4f
Merge branch 'main' into gtk-grafana/issues/389/patterns-table-log-sa…
gtk-grafana Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.0'

services:
grafana:
image: grafana/grafana:11.0.0
image: grafana/grafana:11.1.1
environment:
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_ANONYMOUS_ENABLED=true
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
"dependencies": {
"@bsull/augurs": "^0.3.1",
"@emotion/css": "^11.10.6",
"@grafana/data": "^11.0.0",
"@grafana/data": "^11.1.1",
"@grafana/lezer-logql": "^0.2.6",
"@grafana/runtime": "^11.0.0",
"@grafana/runtime": "^11.1.1",
"@grafana/scenes": "5.7.2",
"@grafana/ui": "^11.0.0",
"@grafana/ui": "^11.1.1",
"@lezer/common": "^1.2.1",
"@lezer/lr": "^1.4.1",
"@playwright/test": "^1.43.1",
Expand Down
1 change: 1 addition & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,4 @@ logql
subqueries
dbscan
svgs
Dont
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export class FieldsBreakdownScene extends SceneObjectBase<FieldsBreakdownSceneSt
};
}

const emptyStateStyles = {
export const emptyStateStyles = {
link: css({
textDecoration: 'underline',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SceneComponentProps,
SceneDataNode,
sceneGraph,
SceneObject,
SceneObjectBase,
SceneObjectState,
} from '@grafana/scenes';
Expand All @@ -20,30 +21,32 @@ import { testIds } from '../../../../services/testIds';
import { PatternsFrameScene } from './PatternsFrameScene';
import { PatternNameLabel } from './PatternNameLabel';
import { getExplorationFor } from 'services/scenes';
import { PatternsTableExpandedRow } from '../PatternsTableExpandedRow';

// copied from from grafana repository packages/grafana-data/src/valueFormats/categories.ts
// that is used in Grafana codebase for "short" units
const SCALED_UNITS = ['', ' K', ' Mil', ' Bil', ' Tri', ' Quadr', ' Quint', ' Sext', ' Sept'];
export interface SingleViewTableSceneState extends SceneObjectState {
// The local copy of the pattern frames, the parent breakdown scene decides if we get the filtered subset or not, in this scene we just present the data
patternFrames: PatternFrame[] | undefined;
expandedRows?: SceneObject[];

// An array of patterns to exclude links
patternsNotMatchingFilters?: string[];
}

interface WithCustomCellData {
export interface PatternsTableCellData {
pattern: string;
dataFrame: DataFrame;
sum: number;
// samples: Array<[number, string]>,
includeLink: () => void;
excludeLink: () => void;
undoLink: () => void;
}

export class PatternsViewTableScene extends SceneObjectBase<SingleViewTableSceneState> {
constructor(state: SingleViewTableSceneState) {
super({
...state,
});
super(state);
}

public static Component = PatternTableViewSceneComponent;
Expand All @@ -53,16 +56,22 @@ export class PatternsViewTableScene extends SceneObjectBase<SingleViewTableScene
* @param total
* @param appliedPatterns
* @param theme
* @param patternsNotMatchingFilters
* @protected
*/
public buildColumns(total: number, appliedPatterns: AppliedPattern[] | undefined, theme: GrafanaTheme2) {
public buildColumns(
total: number,
appliedPatterns: AppliedPattern[] | undefined,
theme: GrafanaTheme2,
patternsNotMatchingFilters?: string[]
) {
const styles = getColumnStyles(theme);
const timeRange = sceneGraph.getTimeRange(this).state.value;
const columns: Array<Column<WithCustomCellData>> = [
const columns: Array<Column<PatternsTableCellData>> = [
{
id: 'volume-samples',
header: '',
cell: (props: CellProps<WithCustomCellData>) => {
cell: (props: CellProps<PatternsTableCellData>) => {
const panelData: PanelData = {
timeRange: timeRange,
series: [props.cell.row.original.dataFrame],
Expand Down Expand Up @@ -125,7 +134,7 @@ export class PatternsViewTableScene extends SceneObjectBase<SingleViewTableScene
{
id: 'pattern',
header: 'Pattern',
cell: (props: CellProps<WithCustomCellData>) => {
cell: (props: CellProps<PatternsTableCellData>) => {
return (
<div className={cx(getTablePatternTextStyles(), styles.tablePatternTextDefault)}>
<PatternNameLabel exploration={getExplorationFor(this)} pattern={props.cell.row.original.pattern} />
Expand All @@ -137,7 +146,11 @@ export class PatternsViewTableScene extends SceneObjectBase<SingleViewTableScene
id: 'include',
header: undefined,
disableGrow: true,
cell: (props: CellProps<WithCustomCellData>) => {
cell: (props: CellProps<PatternsTableCellData>) => {
if (patternsNotMatchingFilters?.includes(props.cell.row.original.pattern)) {
return undefined;
}

const existingPattern = appliedPatterns?.find(
(appliedPattern) => appliedPattern.pattern === props.cell.row.original.pattern
);
Expand All @@ -164,7 +177,7 @@ export class PatternsViewTableScene extends SceneObjectBase<SingleViewTableScene
* @param legendSyncPatterns
* @private
*/
public buildTableData(patternFrames: PatternFrame[], legendSyncPatterns: Set<string>): WithCustomCellData[] {
public buildTableData(patternFrames: PatternFrame[], legendSyncPatterns: Set<string>): PatternsTableCellData[] {
const logExploration = sceneGraph.getAncestor(this, IndexScene);
return patternFrames
.filter((patternFrame) => {
Expand Down Expand Up @@ -211,6 +224,9 @@ const getTablePatternTextStyles = () => {

const getTableStyles = (theme: GrafanaTheme2) => {
return {
link: css({
textDecoration: 'underline',
}),
tableWrap: css({
// Override interactive table style
'> div': {
Expand Down Expand Up @@ -265,7 +281,7 @@ export function PatternTableViewSceneComponent({ model }: SceneComponentProps<Pa
const { legendSyncPatterns } = patternsFrameScene.useState();

// Must use local patternFrames as the parent decides if we get the filtered or not
const { patternFrames: patternFramesRaw } = model.useState();
const { patternFrames: patternFramesRaw, patternsNotMatchingFilters } = model.useState();
const patternFrames = patternFramesRaw ?? [];

// Calculate total for percentages
Expand All @@ -274,11 +290,16 @@ export function PatternTableViewSceneComponent({ model }: SceneComponentProps<Pa
}, 0);

const tableData = model.buildTableData(patternFrames, legendSyncPatterns);
const columns = model.buildColumns(total, appliedPatterns, theme);
const columns = model.buildColumns(total, appliedPatterns, theme, patternsNotMatchingFilters);

return (
<div data-testid={testIds.patterns.tableWrapper} className={styles.tableWrap}>
<InteractiveTable columns={columns} data={tableData} getRowId={(r: WithCustomCellData) => r.pattern} />
<InteractiveTable
columns={columns}
data={tableData}
getRowId={(r: PatternsTableCellData) => r.pattern}
renderExpandedRow={(row) => <PatternsTableExpandedRow tableViz={model} row={row} />}
/>
</div>
);
}
Loading
Loading