From 0673d0d7f58625251bcf567cb4669568946f53de Mon Sep 17 00:00:00 2001 From: Sean Brickley Date: Fri, 26 Mar 2021 13:40:57 -0400 Subject: [PATCH] fix: Check length of possibly empty array (#241) --- .../influxdb2_operational_monitoring.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/influxdb2_operational_monitoring/influxdb2_operational_monitoring.yml b/influxdb2_operational_monitoring/influxdb2_operational_monitoring.yml index b332b3db..2a29c1d3 100644 --- a/influxdb2_operational_monitoring/influxdb2_operational_monitoring.yml +++ b/influxdb2_operational_monitoring/influxdb2_operational_monitoring.yml @@ -108,11 +108,12 @@ spec: |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "runs") |> filter(fn: (r) => r["_field"] == "logs") - |> map(fn: (r) => { - ind = regexp.findStringIndex(r: /name: \\\\\\".+?\\\\\\"/, v: r._value) - finalstring = strings.trimSuffix(v: strings.trimPrefix(v: strings.substring(end: ind[1], start: ind[0], v: r._value ), prefix: "name: \\\\\\\""), suffix: "\\\\\\\"") - return {r with name: finalstring } - } + |> map( + fn: (r) => { + ind = regexp.findStringIndex(r: /name: \\\\\\".+?\\\\\\"/, v: r._value) + finalstring = if length(arr: ind) > 1 then strings.trimSuffix(v: strings.trimPrefix(v: strings.substring(end: ind[1], start: ind[0], v: r._value ), prefix: "name: \\\\\\\""), suffix: "\\\\\\\"") else "none" + return {r with name: finalstring } + } ) |> group(columns: ["_start"]) |> count()