Skip to content

Commit

Permalink
Fix long range queries (#726)
Browse files Browse the repository at this point in the history
* fix: update error rate map and latency stat

* fix: error rate map

* fix: handle long queries in log based panels

* fix: update summary table to handle long range queries

* fix: reachability thresholds

* fix: update summary error rate map to handle long queries

* fix: remaining summary panels

* fix: update uptime query to be more accurate

* chore: remove comments
  • Loading branch information
rdubrock authored Mar 20, 2024
1 parent bf8ed78 commit fbac5e0
Show file tree
Hide file tree
Showing 11 changed files with 733 additions and 400 deletions.
24 changes: 19 additions & 5 deletions src/scenes/Common/avgLatencyStat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ import { DataSourceRef, ThresholdsMode } from '@grafana/schema';

import { ExplorablePanel } from 'scenes/ExplorablePanel';

import { divideSumByCountTransformation } from './divideSumByCountTransformation';

function getQueryRunner(metrics: DataSourceRef) {
return new SceneQueryRunner({
const runner = new SceneQueryRunner({
datasource: metrics,
minInterval: '1m',
maxDataPoints: 10,
queries: [
{
expr: 'sum(rate(probe_all_duration_seconds_sum{probe=~"$probe", instance="$instance", job="$job"}[$__range])) / sum(rate(probe_all_duration_seconds_count{probe=~"$probe", instance="$instance", job="$job"}[$__range]))',
expr: 'sum(rate(probe_all_duration_seconds_sum{probe=~"$probe", instance="$instance", job="$job"}[$__rate_interval]))',
hide: false,
instant: true,
interval: '',
legendFormat: '',
instant: false,
range: true,
legendFormat: 'sum',
refId: 'A',
},
{
expr: 'sum(rate(probe_all_duration_seconds_count{probe=~"$probe", instance="$instance", job="$job"}[$__rate_interval]))',
hide: false,
instant: false,
range: true,
legendFormat: 'count',
refId: 'B',
},
],
});

return divideSumByCountTransformation(runner);
}

export function getAvgLatencyStat(metrics: DataSourceRef) {
Expand Down
53 changes: 53 additions & 0 deletions src/scenes/Common/divideSumByCountTransformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { SceneDataTransformer, SceneQueryRunner } from '@grafana/scenes';

export function divideSumByCountTransformation(runner: SceneQueryRunner) {
return new SceneDataTransformer({
$data: runner,
transformations: [
{
id: 'reduce',
options: {
labelsToFields: false,
reducers: ['sum'],
},
},
{
id: 'rowsToFields',
options: {
mappings: [
{
fieldName: 'Total',
handlerKey: 'field.value',
},
],
},
},
{
id: 'calculateField',
options: {
binary: {
left: 'sum',
operator: '/',
right: 'count',
},
mode: 'binary',
reduce: {
reducer: 'sum',
},
},
},
{
id: 'organize',
options: {
excludeByName: {
count: true,
sum: true,
},
includeByName: {},
indexByName: {},
renameByName: {},
},
},
],
});
}
210 changes: 151 additions & 59 deletions src/scenes/Common/errorRateMap.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,156 @@
import { SceneQueryRunner } from '@grafana/scenes';
import { SceneDataTransformer, SceneQueryRunner } from '@grafana/scenes';
import { DataSourceRef, ThresholdsMode } from '@grafana/schema';

import { ExplorablePanel } from 'scenes/ExplorablePanel';

function getErrorMapQuery() {
return `
100 * (
1 - (
sum by (probe, geohash) (
rate(probe_all_success_sum{instance="$instance", job="$job", probe=~"$probe"}[$__range])
*
on (instance, job, probe, config_version)
group_left(geohash)
max by (instance, job, probe, config_version, geohash)
(
sm_check_info{instance="$instance", job="$job"}
)
function getErrorMapQueries() {
return [
{
expr: `sum by (probe, geohash)
(
rate(probe_all_success_sum{instance="$instance", job="$job", probe=~"$probe"}[$__rate_interval])
*
on (instance, job, probe, config_version)
group_left(geohash)
max by (instance, job, probe, config_version, geohash)
(
sm_check_info{instance="$instance", job="$job"}
)
/
sum by (probe, geohash) (
rate(probe_all_success_count{instance="$instance", job="$job", probe=~"$probe"}[$__range])
)`,
format: 'table',
interval: '1m',
instant: false,
legendFormat: 'numerator',
refId: 'A',
range: true,
},
{
refId: 'B',
expr: `sum by (probe, geohash)
(
rate(probe_all_success_count{instance="$instance", job="$job", probe=~"$probe"}[$__rate_interval])
*
on (instance, job, probe, config_version)
group_left(geohash)
max by (instance, job, probe, config_version, geohash) (
sm_check_info{instance="$instance", job="$job"}
)
on (instance, job, probe, config_version)
group_left(geohash)
max by (instance, job, probe, config_version, geohash)
(
sm_check_info{instance="$instance", job="$job"}
)
)
)
`;
)`,
range: true,
interval: '1m',
instant: false,
hide: false,
legendFormat: 'denominator',
format: 'table',
},
];
}

function getMapQueryRunner(metrics: DataSourceRef) {
const queryRunner = new SceneQueryRunner({
datasource: metrics,
queries: [
queries: getErrorMapQueries(),
});

return new SceneDataTransformer({
$data: queryRunner,
transformations: [
{
id: 'groupBy',
options: {
fields: {
Value: {
aggregations: ['sum'],
operation: 'aggregate',
},
'Value #A': {
aggregations: ['sum'],
operation: 'aggregate',
},
'Value #B': {
aggregations: ['sum'],
operation: 'aggregate',
},
geohash: {
aggregations: [],
operation: 'groupby',
},
probe: {
aggregations: [],
operation: 'groupby',
},
'probe 1': {
aggregations: [],
operation: null,
},
'probe 2': {
aggregations: [],
operation: null,
},
},
},
},
{
expr: getErrorMapQuery(),
format: 'table',
hide: false,
instant: true,
interval: '',
legendFormat: '',
refId: 'A',
id: 'joinByField',
options: {
byField: 'probe',
mode: 'outerTabular',
},
},
{
id: 'calculateField',
options: {
alias: 'success rate',
binary: {
left: 'Value #A (sum)',
operator: '/',
right: 'Value #B (sum)',
},
mode: 'binary',
reduce: {
reducer: 'sum',
},
},
},
{
id: 'calculateField',
options: {
alias: 'Error rate',
binary: {
left: '1.00',
operator: '-',
right: 'success rate',
},
mode: 'binary',
reduce: {
reducer: 'sum',
},
},
},
{
id: 'organize',
options: {
excludeByName: {
'Value #A (sum)': true,
'Value #B (sum)': true,
geohash: false,
'probe 2': true,
'success rate': true,
'geohash 2': true,
},
indexByName: {},
renameByName: {
'error rate': '',
geohash: '',
'probe 1': 'Probe',
'geohash 1': 'geohash',
},
includeByName: {},
},
},
],
});
return queryRunner;
}

export function getErrorRateMapPanel(metrics: DataSourceRef) {
Expand All @@ -71,10 +174,10 @@ export function getErrorRateMapPanel(metrics: DataSourceRef) {
layers: [
{
config: {
showLegend: true,
showLegend: false,
style: {
color: {
field: 'Value',
field: 'Error rate',
fixed: 'dark-green',
},
opacity: 0.4,
Expand All @@ -85,7 +188,7 @@ export function getErrorRateMapPanel(metrics: DataSourceRef) {
mode: 'mod',
},
size: {
field: 'Value',
field: 'Error rate',
fixed: 5,
max: 10,
min: 4,
Expand All @@ -106,8 +209,10 @@ export function getErrorRateMapPanel(metrics: DataSourceRef) {
location: {
geohash: 'geohash',
mode: 'geohash',
latitude: 'Value',
longitude: 'Value',
},
name: 'Layer 1',
name: 'Error rate',
type: 'markers',
},
],
Expand All @@ -125,41 +230,28 @@ export function getErrorRateMapPanel(metrics: DataSourceRef) {
},
decimals: 2,
mappings: [],
max: 1,
max: 0.1,
min: 0,
thresholds: {
mode: ThresholdsMode.Absolute,
steps: [
{
color: 'dark-green',
color: 'green',
value: 0,
},
{
color: 'dark-orange',
value: 0.5,
color: '#EAB839',
value: 0.01,
},
{
color: 'dark-red',
value: 1,
color: 'red',
value: 0.015,
},
],
},
unit: 'percent',
unit: 'percentunit',
},
overrides: [
{
matcher: {
id: 'byName',
options: 'Value',
},
properties: [
{
id: 'displayName',
value: 'Error rate',
},
],
},
],
overrides: [],
},
});
return mapPanel;
Expand Down
Loading

0 comments on commit fbac5e0

Please sign in to comment.