cmd/bosun: fix single dimension case in azure insights
also avoid possible panic
@@ -149,10 +149,11 @@ func AzureAIQuery(prefix string, e *State, metric, segmentCSV, filter string, ap
next = &(*next.Segments)[0]
return nil
}
-
+ if segLen > 1 {
if err := decend("root-level"); err != nil {
return r, err
}
+ }
// When multiple dimensions are requests, there are nested MetricsSegmentInfo objects
// The higher levels just contain all the dimension key-value pairs except the last.
// So we fast forward to the depth that has the last tag pair and the metric values
@@ -166,6 +167,9 @@ func AzureAIQuery(prefix string, e *State, metric, segmentCSV, filter string, ap
}
}
}
+ if next == nil {
+ return r, fmt.Errorf("unexpected segement/dimension in insights response")
+ }
for _, innerSeg := range *next.Segments {
err := handleInnerSegment(innerSeg)
if err != nil {
