2013-02-08 17:03:26 +00:00
|
|
|
// Copyright 2013 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package metric
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/prometheus/model"
|
|
|
|
"github.com/prometheus/prometheus/utility/test"
|
2013-02-08 17:03:26 +00:00
|
|
|
"testing"
|
2013-02-08 17:03:26 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2013-03-26 17:02:58 +00:00
|
|
|
func GetValueAtTimeTests(persistenceMaker func() (MetricPersistence, test.Closer), t test.Tester) {
|
2013-02-08 17:03:26 +00:00
|
|
|
type value struct {
|
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-04-21 18:52:21 +00:00
|
|
|
value model.SampleValue
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type input struct {
|
2013-04-18 14:10:52 +00:00
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 14:10:52 +00:00
|
|
|
type output []model.SampleValue
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
type behavior struct {
|
|
|
|
name string
|
|
|
|
input input
|
2013-04-18 14:10:52 +00:00
|
|
|
output output
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var contexts = []struct {
|
|
|
|
name string
|
|
|
|
values []value
|
|
|
|
behaviors []behavior
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no values",
|
|
|
|
values: []value{},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
|
|
|
name: "random target",
|
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "singleton",
|
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "before",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 29,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "after",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 31,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "double",
|
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact first",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact second",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "before first",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1983,
|
|
|
|
month: 9,
|
|
|
|
day: 29,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "after second",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1985,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "middle",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
|
|
|
1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "triple",
|
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact first",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact second",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "exact third",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
2,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "before first",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1983,
|
|
|
|
month: 9,
|
|
|
|
day: 29,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "after third",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1986,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
2,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "first middle",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1984,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
0,
|
|
|
|
1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "second middle",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-04-18 14:10:52 +00:00
|
|
|
year: 1985,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
2013-04-18 14:10:52 +00:00
|
|
|
output: output{
|
|
|
|
1,
|
|
|
|
2,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, context := range contexts {
|
|
|
|
// Wrapping in function to enable garbage collection of resources.
|
|
|
|
func() {
|
|
|
|
p, closer := persistenceMaker()
|
|
|
|
|
2013-04-01 11:22:38 +00:00
|
|
|
defer closer.Close()
|
|
|
|
defer p.Close()
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
m := model.Metric{
|
2013-03-26 14:32:48 +00:00
|
|
|
model.MetricNameLabel: "age_in_years",
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, value := range context.values {
|
2013-02-08 17:03:26 +00:00
|
|
|
testAppendSample(p, model.Sample{
|
2013-02-08 17:03:26 +00:00
|
|
|
Value: model.SampleValue(value.value),
|
|
|
|
Timestamp: time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC),
|
|
|
|
Metric: m,
|
|
|
|
}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, behavior := range context.behaviors {
|
|
|
|
input := behavior.input
|
|
|
|
time := time.Date(input.year, input.month, input.day, input.hour, 0, 0, 0, time.UTC)
|
|
|
|
|
2013-04-18 14:10:52 +00:00
|
|
|
actual := p.GetValueAtTime(model.NewFingerprintFromMetric(m), time)
|
2013-02-08 17:03:26 +00:00
|
|
|
|
2013-04-18 14:10:52 +00:00
|
|
|
if len(behavior.output) != len(actual) {
|
2013-05-21 16:12:02 +00:00
|
|
|
t.Fatalf("%d.%d(%s.%s). Expected %d samples but got: %v\n", i, j, context.name, behavior.name, len(behavior.output), actual)
|
2013-04-18 14:10:52 +00:00
|
|
|
}
|
|
|
|
for k, samplePair := range actual {
|
|
|
|
if samplePair.Value != behavior.output[k] {
|
2013-05-21 16:12:02 +00:00
|
|
|
t.Fatalf("%d.%d.%d(%s.%s). Expected %s but got %s\n", i, j, k, context.name, behavior.name, behavior.output[k], samplePair)
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
func GetRangeValuesTests(persistenceMaker func() (MetricPersistence, test.Closer), onlyBoundaries bool, t test.Tester) {
|
2013-02-08 17:03:26 +00:00
|
|
|
type value struct {
|
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-04-21 18:52:21 +00:00
|
|
|
value model.SampleValue
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type input struct {
|
|
|
|
openYear int
|
|
|
|
openMonth time.Month
|
|
|
|
openDay int
|
|
|
|
openHour int
|
|
|
|
endYear int
|
|
|
|
endMonth time.Month
|
|
|
|
endDay int
|
|
|
|
endHour int
|
|
|
|
}
|
|
|
|
|
|
|
|
type output struct {
|
2013-05-12 00:03:16 +00:00
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
|
|
|
value model.SampleValue
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type behavior struct {
|
|
|
|
name string
|
|
|
|
input input
|
2013-05-12 00:03:16 +00:00
|
|
|
output []output
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var contexts = []struct {
|
|
|
|
name string
|
|
|
|
values []value
|
|
|
|
behaviors []behavior
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no values",
|
|
|
|
values: []value{},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 14:10:52 +00:00
|
|
|
name: "non-existent interval",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "singleton value",
|
2013-02-08 17:03:26 +00:00
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "start on first value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "end on first value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1984,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "overlap on first value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-05-12 00:03:16 +00:00
|
|
|
openYear: 1983,
|
2013-02-08 17:03:26 +00:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
endYear: 1985,
|
2013-02-08 17:03:26 +00:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "two values",
|
2013-02-08 17:03:26 +00:00
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "start on first value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "start on second value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-05-12 00:03:16 +00:00
|
|
|
openYear: 1985,
|
2013-02-08 17:03:26 +00:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
endYear: 1986,
|
2013-02-08 17:03:26 +00:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "end on first value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-05-12 00:03:16 +00:00
|
|
|
openYear: 1983,
|
2013-02-08 17:03:26 +00:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
endYear: 1984,
|
2013-02-08 17:03:26 +00:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "end on second value",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
2013-05-12 00:03:16 +00:00
|
|
|
openYear: 1985,
|
|
|
|
openMonth: 1,
|
|
|
|
openDay: 1,
|
2013-02-08 17:03:26 +00:00
|
|
|
openHour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
endYear: 1985,
|
2013-02-08 17:03:26 +00:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
year: 1985,
|
2013-02-08 17:03:26 +00:00
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
value: 1,
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "overlap on values",
|
2013-02-08 17:03:26 +00:00
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-12 00:03:16 +00:00
|
|
|
endYear: 1986,
|
2013-02-08 17:03:26 +00:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-12 00:03:16 +00:00
|
|
|
name: "three values",
|
2013-02-08 17:03:26 +00:00
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
|
|
|
name: "start on first value",
|
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "start on second value",
|
|
|
|
input: input{
|
|
|
|
openYear: 1985,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1986,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "end on first value",
|
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1984,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "end on second value",
|
|
|
|
input: input{
|
|
|
|
openYear: 1985,
|
|
|
|
openMonth: 1,
|
|
|
|
openDay: 1,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "overlap on values",
|
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1986,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-05-12 00:03:16 +00:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 17:03:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, context := range contexts {
|
|
|
|
// Wrapping in function to enable garbage collection of resources.
|
|
|
|
func() {
|
|
|
|
p, closer := persistenceMaker()
|
|
|
|
|
2013-04-01 11:22:38 +00:00
|
|
|
defer closer.Close()
|
|
|
|
defer p.Close()
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
m := model.Metric{
|
2013-03-26 14:32:48 +00:00
|
|
|
model.MetricNameLabel: "age_in_years",
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, value := range context.values {
|
2013-02-08 17:03:26 +00:00
|
|
|
testAppendSample(p, model.Sample{
|
2013-02-08 17:03:26 +00:00
|
|
|
Value: model.SampleValue(value.value),
|
|
|
|
Timestamp: time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC),
|
|
|
|
Metric: m,
|
|
|
|
}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, behavior := range context.behaviors {
|
|
|
|
input := behavior.input
|
|
|
|
open := time.Date(input.openYear, input.openMonth, input.openDay, input.openHour, 0, 0, 0, time.UTC)
|
|
|
|
end := time.Date(input.endYear, input.endMonth, input.endDay, input.endHour, 0, 0, 0, time.UTC)
|
|
|
|
in := model.Interval{
|
|
|
|
OldestInclusive: open,
|
|
|
|
NewestInclusive: end,
|
|
|
|
}
|
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
actualValues := model.Values{}
|
|
|
|
expectedValues := []output{}
|
|
|
|
fp := model.NewFingerprintFromMetric(m)
|
|
|
|
if onlyBoundaries {
|
|
|
|
actualValues = p.GetBoundaryValues(fp, in)
|
|
|
|
l := len(behavior.output)
|
|
|
|
if l == 1 {
|
|
|
|
expectedValues = behavior.output[0:1]
|
|
|
|
}
|
|
|
|
if l > 1 {
|
|
|
|
expectedValues = append(behavior.output[0:1], behavior.output[l-1])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actualValues = p.GetRangeValues(fp, in)
|
|
|
|
expectedValues = behavior.output
|
|
|
|
}
|
2013-02-08 17:03:26 +00:00
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
if actualValues == nil && len(expectedValues) != 0 {
|
|
|
|
t.Fatalf("%d.%d(%s). Expected %s but got: %s\n", i, j, behavior.name, expectedValues, actualValues)
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
if expectedValues == nil {
|
|
|
|
if actualValues != nil {
|
|
|
|
t.Fatalf("%d.%d(%s). Expected nil values but got: %s\n", i, j, behavior.name, actualValues)
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-05-12 00:03:16 +00:00
|
|
|
if len(expectedValues) != len(actualValues) {
|
|
|
|
t.Fatalf("%d.%d(%s). Expected length %d but got: %d\n", i, j, behavior.name, len(expectedValues), len(actualValues))
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
for k, actual := range actualValues {
|
|
|
|
expected := expectedValues[k]
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
if actual.Value != model.SampleValue(expected.value) {
|
2013-05-12 00:03:16 +00:00
|
|
|
t.Fatalf("%d.%d.%d(%s). Expected %v but got: %v\n", i, j, k, behavior.name, expected.value, actual.Value)
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if actual.Timestamp.Year() != expected.year {
|
|
|
|
t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.year, actual.Timestamp.Year())
|
|
|
|
}
|
|
|
|
if actual.Timestamp.Month() != expected.month {
|
|
|
|
t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.month, actual.Timestamp.Month())
|
|
|
|
}
|
|
|
|
// XXX: Find problem here.
|
|
|
|
// Mismatches occur in this and have for a long time in the LevelDB
|
|
|
|
// case, however not im-memory.
|
|
|
|
//
|
|
|
|
// if actual.Timestamp.Day() != expected.day {
|
|
|
|
// t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.day, actual.Timestamp.Day())
|
|
|
|
// }
|
|
|
|
// if actual.Timestamp.Hour() != expected.hour {
|
|
|
|
// t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.hour, actual.Timestamp.Hour())
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
2013-02-08 17:03:26 +00:00
|
|
|
|
|
|
|
// Test Definitions Follow
|
|
|
|
|
|
|
|
func testMemoryGetValueAtTime(t test.Tester) {
|
2013-03-26 17:02:58 +00:00
|
|
|
persistenceMaker := func() (MetricPersistence, test.Closer) {
|
2013-06-06 16:16:22 +00:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetValueAtTimeTests(persistenceMaker, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemoryGetValueAtTime(t *testing.T) {
|
|
|
|
testMemoryGetValueAtTime(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMemoryGetValueAtTime(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testMemoryGetValueAtTime(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemoryGetBoundaryValues(t *testing.T) {
|
|
|
|
testMemoryGetBoundaryValues(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMemoryGetBoundaryValues(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testMemoryGetBoundaryValues(b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMemoryGetRangeValues(t test.Tester) {
|
2013-03-26 17:02:58 +00:00
|
|
|
persistenceMaker := func() (MetricPersistence, test.Closer) {
|
2013-06-06 16:16:22 +00:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 00:03:16 +00:00
|
|
|
GetRangeValuesTests(persistenceMaker, false, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMemoryGetBoundaryValues(t test.Tester) {
|
|
|
|
persistenceMaker := func() (MetricPersistence, test.Closer) {
|
2013-06-06 16:16:22 +00:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-05-12 00:03:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetRangeValuesTests(persistenceMaker, true, t)
|
2013-02-08 17:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemoryGetRangeValues(t *testing.T) {
|
|
|
|
testMemoryGetRangeValues(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMemoryGetRangeValues(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testMemoryGetRangeValues(b)
|
|
|
|
}
|
|
|
|
}
|