grafana / gel-app

Experimental Grafana Backend Expressions/Transform Plugin (GEL)
Apache License 2.0
2 stars 1 forks source link

Fix series length on binary series op series operations #38

Closed kylebrandt closed 5 years ago

kylebrandt commented 5 years ago

in biSeriesSeries the length of the resulting series is the result of A when A + B. However, only points where there time matches for both A and B are added to the result. This results in a series with a bunch of null points and the Grafana displaying (datapoints outside timerange) in the graph.

func biSeriesSeries(name string, labels dataframe.Labels, op string, aSeries, bSeries Series) (Series, error) {
    newSeries := NewSeries(name, labels, aSeries.Len())
    for aIdx := 0; aIdx < aSeries.Len(); aIdx++ {
        aTime, aF := aSeries.GetPoint(aIdx)
        for bIdx := 0; bIdx < bSeries.Len(); bIdx++ {
            bTime := bSeries.GetTime(bIdx)
            if *aTime == *bTime {
                bF := bSeries.GetValue(bIdx)
                if aF == nil || bF == nil {
                    newSeries.SetPoint(aIdx, aTime, nil)
                    break
                }
                nF, err := binaryOp(op, *aF, *bF)
                if err != nil {
                    return newSeries, err
                }
                newSeries.SetPoint(aIdx, aTime, &nF)
                break
            }
        }
    }
    return newSeries, nil
}