Skip to content

Commit beaa7db

Browse files
authored
Merge pull request #925 from go-graphite/njpm/fix-timeshift
2 parents 9078ede + b2e0649 commit beaa7db

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

expr/functions/timeShift/function.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ func (f *timeShift) Do(ctx context.Context, eval interfaces.Evaluator, e parser.
9393
if err != nil {
9494
return nil, err
9595
}
96-
results := make([]*types.MetricData, len(arg))
96+
results := make([]*types.MetricData, 0, len(arg))
9797

98-
for n, a := range arg {
98+
for _, a := range arg {
9999
r := a.CopyLink()
100100
r.Name = "timeShift(" + a.Name + ",'" + offsStr + "'," + resetEndStr + ")"
101101
r.StartTime = a.StartTime - int64(offs)
@@ -110,7 +110,7 @@ func (f *timeShift) Do(ctx context.Context, eval interfaces.Evaluator, e parser.
110110
r.Values = r.Values[:length]
111111

112112
r.Tags["timeshift"] = fmt.Sprintf("%d", offs)
113-
results[n] = r
113+
results = append(results, r)
114114

115115
}
116116

expr/functions/timeShift/function_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ func TestTimeShift(t *testing.T) {
9595
From: startTime,
9696
Until: startTime + 6,
9797
},
98+
{
99+
// Data starts at 205 but fetch requests 200-202, so we have no data for the series, expecting an empty result
100+
Target: `timeShift(metric1, "+100s", true)`,
101+
M: map[parser.MetricRequest][]*types.MetricData{
102+
{Metric: "metric1", From: 200, Until: 202}: {types.MakeMetricData("metric1", []float64{0, 1, 2, 3, 4, 5}, 1, 205)},
103+
},
104+
Want: []*types.MetricData{},
105+
From: 100,
106+
Until: 102,
107+
},
98108
}
99109

100110
for _, tt := range tests {

0 commit comments

Comments
 (0)