Skip to content

Commit

Permalink
fix: make probes a multiselect in traceroute dashboard
Browse files Browse the repository at this point in the history
* feat: make probes a multiselect in traceroute dashboard

* fix: make unknown TTL nodes probe specific

* fix: break out trace time by probe
  • Loading branch information
rdubrock authored Sep 16, 2021
1 parent f6e4370 commit 129887e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/dashboards/sm-traceroute.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,11 @@
"targets": [
{
"exemplar": false,
"expr": "sum((rate(probe_all_duration_seconds_sum{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]) OR rate(probe_duration_seconds_sum{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]))) / sum((rate(probe_all_duration_seconds_count{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]) OR rate(probe_duration_seconds_count{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range])))",
"expr": "sum((rate(probe_all_duration_seconds_sum{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]) OR rate(probe_duration_seconds_sum{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]))) by (probe) / sum((rate(probe_all_duration_seconds_count{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]) OR rate(probe_duration_seconds_count{probe=~\"$probe\", instance=\"$instance\", job=\"$job\"}[$__range]))) by (probe)",
"format": "time_series",
"instant": true,
"interval": "",
"legendFormat": "",
"legendFormat": "{{probe}}",
"refId": "A"
}
],
Expand Down Expand Up @@ -735,7 +735,7 @@
"hide": 0,
"includeAll": true,
"label": null,
"multi": false,
"multi": true,
"name": "probe",
"options": [],
"query": {
Expand Down Expand Up @@ -815,5 +815,5 @@
"timezone": "",
"title": "Synthetic Monitoring Traceroute",
"uid": "hk8gHB4nk",
"version": 5
"version": 6
}
26 changes: 19 additions & 7 deletions src/datasource/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class SMDataSource extends DataSourceApi<SMQuery, SMOptions> {

const dashboardVars = getTemplateSrv().getVariables();

const queryToExecute = dashboardVars ? this.getQueryFromDashboardVars(dashboardVars, query) : query;
const queryToExecute = dashboardVars ? this.getQueryFromVars(dashboardVars, query) : query;

if (!queryToExecute.job || !queryToExecute.instance) {
return {
Expand Down Expand Up @@ -100,14 +100,26 @@ export class SMDataSource extends DataSourceApi<SMQuery, SMOptions> {
return { data };
}

getProbeValueFromVar(probe: string | undefined): string {
if (!probe || probe === '$__all') {
return '.+';
getProbeValueFromVar(probe: string | string[] | undefined): string {
const allProbes = '.+';
const isArray = Array.isArray(probe);

if (!probe || (!isArray && (!probe || probe === '$__all'))) {
return allProbes;
}
if (isArray && probe.length > 1) {
return (probe as string[]).join('|');
} else if (isArray && probe.length === 1) {
if (!probe[0] || probe[0] === '$__all') {
return allProbes;
}
return probe[0];
}
return probe;

return allProbes;
}

getQueryFromDashboardVars(dashboardVars: VariableModel[], query: SMQuery): SMQuery {
getQueryFromVars(dashboardVars: VariableModel[], query: SMQuery): SMQuery {
const job = dashboardVars.find((variable) => variable.name === 'job') as DashboardVariable | undefined;
const instance = dashboardVars.find((variable) => variable.name === 'instance') as DashboardVariable | undefined;
const probe = dashboardVars.find((variable) => variable.name === 'probe') as DashboardVariable | undefined;
Expand All @@ -122,7 +134,7 @@ export class SMDataSource extends DataSourceApi<SMQuery, SMOptions> {
...query,
job: job?.current?.value ?? query.job,
instance: instance?.current?.value ?? query.instance,
probe: this.getProbeValueFromVar(probe?.current?.value ?? query.probe),
probe: this.getProbeValueFromVar(probe.current?.value ?? query.probe),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/datasource/traceroute-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const parseTracerouteLogs = (queryResponse: LogQueryResponse): MutableDat
return acc;
}

const hosts = stream.Hosts === '' ? [`??? TTL${stream.TTL}`] : stream.Hosts?.split(',');
const hosts = stream.Hosts === '' ? [`??? TTL${stream.TTL + stream.probe}`] : stream.Hosts?.split(',');
destinations.add(stream.Destination);
const updatedStream = {
...stream,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const queryMetric = async (
return {
data: response.data?.data?.result ?? [],
};
} catch (e) {
} catch (e: any) {
return { error: (e.message || e.data?.message) ?? 'Error fetching data', data: [] };
}
};
Expand Down

0 comments on commit 129887e

Please # to comment.