Skip to content

Commit

Permalink
chore: handle no assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rdubrock committed Dec 21, 2023
1 parent 7e13fb6 commit dcf15b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/scenes/SCRIPTED/AssertionsTable/AssertionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SceneQueryRunner,
} from '@grafana/scenes';
import { DataSourceRef } from '@grafana/schema';
import { useStyles2 } from '@grafana/ui';
import { LinkButton, useStyles2 } from '@grafana/ui';

import { Table, TableColumn } from 'components/Table';

Expand Down Expand Up @@ -170,7 +170,20 @@ function AssertionsTable({ model }: SceneComponentProps<AssertionsTableSceneObje
expandableRowsComponentProps: { tableViz: model, logs },
}}
expandableComponent={AssertionTableRow}
noDataText={'No assertions found'}
//@ts-ignore - noDataText expects a string, but we want to render a component and it works
noDataText={
<div className={styles.noDataContainer}>
<p>There are no assertions in this script. You can use k6 Checks to validate conditions in your script.</p>
<LinkButton
variant="primary"
href="https://k6.io/docs/using-k6/checks/"
target="_blank"
rel="noopener noreferrer"
>
Learn more about Checks
</LinkButton>
</div>
}
pagination={false}
id="assertion-table"
name="Assertions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ResultsByTargetTableSceneObject extends SceneObjectBase<ResultsByTa
fields?.[1].values.reduce<DataRow[]>((acc, name, index) => {
const successRate = fields[2].values[index] * 100;
const expectedResponse = data.series[1].fields[2].values[index] * 100;
const latency = data.series[2].fields[2].values[index];
const latency = data.series[2].fields[2].values[index] * 100;

acc.push({ name, successRate, latency, expectedResponse, metrics });
return acc;
Expand Down Expand Up @@ -155,7 +155,8 @@ function getQueryRunner(metrics: DataSourceRef) {
datasource: metrics,
editorMode: 'code',
exemplar: false,
expr: `sum by(name)(rate(probe_http_duration_seconds{job="$job", instance="$instance"}[5m]))`,
// TODO: Does this make sense at all? I want get the total latency for each URL and then average the different probes, not just sum all the probes together
expr: `avg by (name) (sum by(name, probe)(rate(probe_http_duration_seconds{job="$job", instance="$instance"}[5m])))`,
format: 'table',
hide: false,
instant: true,
Expand Down
6 changes: 6 additions & 0 deletions src/scenes/SCRIPTED/getTablePanelStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@ export function getTablePanelStyles(theme: GrafanaTheme2) {
display: 'flex',
alignItems: 'center',
}),
noDataContainer: css({
padding: theme.spacing(4),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}),
};
}

0 comments on commit dcf15b6

Please sign in to comment.