* Alerting: implement loki query for alert state history
* extract selector building
* add unit tests for selector creation
* backup
* give selectors their own type
* build dataframe
* add some tests
* small changes after manual testing
* use struct client
* golint
* more golint
* Make RuleUID optional for Loki implementation
* Drop initial assumption that we only have one series
* Pare down to three columns, fix timestamp overflows, improve failure cases in loki responses
* Embed structred log lines in the dataframe as objects rather than json strings
* Include state history label filter
* Remove dead code
---------
Co-authored-by: Alex Weaver <weaver.alex.d@gmail.com>
pull/62834/head
Jean-Philippe Quéméner2 years agocommitted byGitHub
// Find the total number of elements in all arrays.
totalLen:=0
for_,arr:=rangeres.Data.Result{
totalLen+=len(arr.Values)
}
// Create a new slice to store the merged elements.
frame:=data.NewFrame("states")
// We merge all series into a single linear history.
lbls:=data.Labels(map[string]string{})
// We represent state history as a single merged history, that roughly corresponds to what you get in the Grafana Explore tab when querying Loki directly.
// The format is composed of the following vectors:
// 1. `time` - timestamp - when the transition happened
// 2. `line` - JSON - the full data of the transition
// 3. `labels` - JSON - the labels associated with that state transition
times:=make([]time.Time,0,totalLen)
lines:=make([]json.RawMessage,0,totalLen)
labels:=make([]json.RawMessage,0,totalLen)
// Initialize a slice of pointers to the current position in each array.
pointers:=make([]int,len(res.Data.Result))
for{
minTime:=int64(math.MaxInt64)
minEl:=[2]string{}
minElStreamIdx:=-1
// Find the element with the earliest time among all arrays.
fori,stream:=rangeres.Data.Result{
// Skip if we already reached the end of the current array.