2013-02-08 09:03:26 -08: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 (
|
2013-02-08 09:03:26 -08:00
|
|
|
"testing"
|
2013-02-08 09:03:26 -08:00
|
|
|
"time"
|
2013-06-25 05:02:27 -07:00
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/utility/test"
|
2013-02-08 09:03:26 -08:00
|
|
|
)
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
func GetValueAtTimeTests(persistenceMaker func() (ViewableMetricPersistence, test.Closer), t test.Tester) {
|
2013-02-08 09:03:26 -08:00
|
|
|
type value struct {
|
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-06-25 05:02:27 -07:00
|
|
|
value clientmodel.SampleValue
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type input struct {
|
2013-04-18 07:10:52 -07:00
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
type output []clientmodel.SampleValue
|
2013-02-08 09:03:26 -08:00
|
|
|
|
|
|
|
type behavior struct {
|
|
|
|
name string
|
|
|
|
input input
|
2013-04-18 07:10:52 -07:00
|
|
|
output output
|
2013-02-08 09:03:26 -08: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 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "singleton",
|
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "exact",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "before",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 29,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "after",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 31,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08: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 07:10:52 -07:00
|
|
|
name: "exact first",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "exact second",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "before first",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1983,
|
|
|
|
month: 9,
|
|
|
|
day: 29,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "after second",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1985,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "middle",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
|
|
|
1,
|
2013-02-08 09:03:26 -08: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 07:10:52 -07:00
|
|
|
name: "exact first",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "exact second",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
1,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "exact third",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
2,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "before first",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1983,
|
|
|
|
month: 9,
|
|
|
|
day: 29,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "after third",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1986,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
2,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "first middle",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1984,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
0,
|
|
|
|
1,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "second middle",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-04-18 07:10:52 -07:00
|
|
|
year: 1985,
|
|
|
|
month: 9,
|
|
|
|
day: 28,
|
|
|
|
hour: 12,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
2013-04-18 07:10:52 -07:00
|
|
|
output: output{
|
|
|
|
1,
|
|
|
|
2,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, context := range contexts {
|
|
|
|
// Wrapping in function to enable garbage collection of resources.
|
|
|
|
func() {
|
|
|
|
p, closer := persistenceMaker()
|
|
|
|
|
2013-04-01 04:22:38 -07:00
|
|
|
defer closer.Close()
|
|
|
|
defer p.Close()
|
2013-02-08 09:03:26 -08:00
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
m := clientmodel.Metric{
|
|
|
|
clientmodel.MetricNameLabel: "age_in_years",
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, value := range context.values {
|
2013-08-15 02:35:50 -07:00
|
|
|
testAppendSamples(p, &clientmodel.Sample{
|
2013-06-25 05:02:27 -07:00
|
|
|
Value: clientmodel.SampleValue(value.value),
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
Timestamp: clientmodel.TimestampFromTime(time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC)),
|
2013-02-08 09:03:26 -08:00
|
|
|
Metric: m,
|
|
|
|
}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, behavior := range context.behaviors {
|
|
|
|
input := behavior.input
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
time := clientmodel.TimestampFromTime(time.Date(input.year, input.month, input.day, input.hour, 0, 0, 0, time.UTC))
|
2013-06-25 05:02:27 -07:00
|
|
|
fingerprint := &clientmodel.Fingerprint{}
|
|
|
|
fingerprint.LoadFromMetric(m)
|
|
|
|
actual := p.GetValueAtTime(fingerprint, time)
|
2013-02-08 09:03:26 -08:00
|
|
|
|
2013-04-18 07:10:52 -07:00
|
|
|
if len(behavior.output) != len(actual) {
|
2013-05-21 09:12:02 -07: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 07:10:52 -07:00
|
|
|
}
|
|
|
|
for k, samplePair := range actual {
|
|
|
|
if samplePair.Value != behavior.output[k] {
|
2013-05-21 09:12:02 -07: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 09:03:26 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
func GetRangeValuesTests(persistenceMaker func() (ViewableMetricPersistence, test.Closer), onlyBoundaries bool, t test.Tester) {
|
2013-02-08 09:03:26 -08:00
|
|
|
type value struct {
|
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-06-25 05:02:27 -07:00
|
|
|
value clientmodel.SampleValue
|
2013-02-08 09:03:26 -08: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-11 17:03:16 -07:00
|
|
|
year int
|
|
|
|
month time.Month
|
|
|
|
day int
|
|
|
|
hour int
|
2013-06-25 05:02:27 -07:00
|
|
|
value clientmodel.SampleValue
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type behavior struct {
|
|
|
|
name string
|
|
|
|
input input
|
2013-05-11 17:03:16 -07:00
|
|
|
output []output
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var contexts = []struct {
|
|
|
|
name string
|
|
|
|
values []value
|
|
|
|
behaviors []behavior
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no values",
|
|
|
|
values: []value{},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-04-18 07:10:52 -07:00
|
|
|
name: "non-existent interval",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "singleton value",
|
2013-02-08 09:03:26 -08:00
|
|
|
values: []value{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
behaviors: []behavior{
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "start on first value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "end on first value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1984,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "overlap on first value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-05-11 17:03:16 -07:00
|
|
|
openYear: 1983,
|
2013-02-08 09:03:26 -08:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
endYear: 1985,
|
2013-02-08 09:03:26 -08:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "two values",
|
2013-02-08 09:03:26 -08: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-11 17:03:16 -07:00
|
|
|
name: "start on first value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
|
|
|
openYear: 1984,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
|
|
|
endYear: 1985,
|
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07: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 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "start on second value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-05-11 17:03:16 -07:00
|
|
|
openYear: 1985,
|
2013-02-08 09:03:26 -08:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
endYear: 1986,
|
2013-02-08 09:03:26 -08:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07:00
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "end on first value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-05-11 17:03:16 -07:00
|
|
|
openYear: 1983,
|
2013-02-08 09:03:26 -08:00
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
endYear: 1984,
|
2013-02-08 09:03:26 -08:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "end on second value",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
2013-05-11 17:03:16 -07:00
|
|
|
openYear: 1985,
|
|
|
|
openMonth: 1,
|
|
|
|
openDay: 1,
|
2013-02-08 09:03:26 -08:00
|
|
|
openHour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
endYear: 1985,
|
2013-02-08 09:03:26 -08:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
year: 1985,
|
2013-02-08 09:03:26 -08:00
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
value: 1,
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "overlap on values",
|
2013-02-08 09:03:26 -08:00
|
|
|
input: input{
|
|
|
|
openYear: 1983,
|
|
|
|
openMonth: 3,
|
|
|
|
openDay: 30,
|
|
|
|
openHour: 0,
|
2013-05-11 17:03:16 -07:00
|
|
|
endYear: 1986,
|
2013-02-08 09:03:26 -08:00
|
|
|
endMonth: 3,
|
|
|
|
endDay: 30,
|
|
|
|
endHour: 0,
|
|
|
|
},
|
|
|
|
output: []output{
|
|
|
|
{
|
|
|
|
year: 1984,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 0,
|
|
|
|
},
|
2013-05-11 17:03:16 -07:00
|
|
|
{
|
|
|
|
year: 1985,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 1,
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2013-05-11 17:03:16 -07:00
|
|
|
name: "three values",
|
2013-02-08 09:03:26 -08: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-11 17:03:16 -07:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 09:03:26 -08: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-11 17:03:16 -07:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 09:03:26 -08: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-11 17:03:16 -07:00
|
|
|
{
|
|
|
|
year: 1986,
|
|
|
|
month: 3,
|
|
|
|
day: 30,
|
|
|
|
hour: 0,
|
|
|
|
value: 2,
|
|
|
|
},
|
2013-02-08 09:03:26 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, context := range contexts {
|
|
|
|
// Wrapping in function to enable garbage collection of resources.
|
|
|
|
func() {
|
|
|
|
p, closer := persistenceMaker()
|
|
|
|
|
2013-04-01 04:22:38 -07:00
|
|
|
defer closer.Close()
|
|
|
|
defer p.Close()
|
2013-02-08 09:03:26 -08:00
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
m := clientmodel.Metric{
|
|
|
|
clientmodel.MetricNameLabel: "age_in_years",
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, value := range context.values {
|
2013-08-15 02:35:50 -07:00
|
|
|
testAppendSamples(p, &clientmodel.Sample{
|
2013-06-25 05:02:27 -07:00
|
|
|
Value: clientmodel.SampleValue(value.value),
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
Timestamp: clientmodel.TimestampFromTime(time.Date(value.year, value.month, value.day, value.hour, 0, 0, 0, time.UTC)),
|
2013-02-08 09:03:26 -08:00
|
|
|
Metric: m,
|
|
|
|
}, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, behavior := range context.behaviors {
|
|
|
|
input := behavior.input
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
open := clientmodel.TimestampFromTime(time.Date(input.openYear, input.openMonth, input.openDay, input.openHour, 0, 0, 0, time.UTC))
|
|
|
|
end := clientmodel.TimestampFromTime(time.Date(input.endYear, input.endMonth, input.endDay, input.endHour, 0, 0, 0, time.UTC))
|
2013-06-25 05:02:27 -07:00
|
|
|
in := Interval{
|
2013-02-08 09:03:26 -08:00
|
|
|
OldestInclusive: open,
|
|
|
|
NewestInclusive: end,
|
|
|
|
}
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
actualValues := Values{}
|
2013-05-11 17:03:16 -07:00
|
|
|
expectedValues := []output{}
|
2013-06-25 05:02:27 -07:00
|
|
|
fp := &clientmodel.Fingerprint{}
|
|
|
|
fp.LoadFromMetric(m)
|
2013-05-11 17:03:16 -07:00
|
|
|
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 09:03:26 -08:00
|
|
|
|
2013-05-11 17:03:16 -07:00
|
|
|
if actualValues == nil && len(expectedValues) != 0 {
|
2014-02-14 10:36:27 -08:00
|
|
|
t.Fatalf("%d.%d(%s). Expected %v but got: %v\n", i, j, behavior.name, expectedValues, actualValues)
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-05-11 17:03:16 -07: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 09:03:26 -08:00
|
|
|
}
|
|
|
|
} else {
|
2013-05-11 17:03:16 -07: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 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-05-11 17:03:16 -07:00
|
|
|
for k, actual := range actualValues {
|
|
|
|
expected := expectedValues[k]
|
2013-02-08 09:03:26 -08:00
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
if actual.Value != clientmodel.SampleValue(expected.value) {
|
2013-05-11 17:03:16 -07: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 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
if actual.Timestamp.Time().Year() != expected.year {
|
|
|
|
t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.year, actual.Timestamp.Time().Year())
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
Use custom timestamp type for sample timestamps and related code.
So far we've been using Go's native time.Time for anything related to sample
timestamps. Since the range of time.Time is much bigger than what we need, this
has created two problems:
- there could be time.Time values which were out of the range/precision of the
time type that we persist to disk, therefore causing incorrectly ordered keys.
One bug caused by this was:
https://github.com/prometheus/prometheus/issues/367
It would be good to use a timestamp type that's more closely aligned with
what the underlying storage supports.
- sizeof(time.Time) is 192, while Prometheus should be ok with a single 64-bit
Unix timestamp (possibly even a 32-bit one). Since we store samples in large
numbers, this seriously affects memory usage. Furthermore, copying/working
with the data will be faster if it's smaller.
*MEMORY USAGE RESULTS*
Initial memory usage comparisons for a running Prometheus with 1 timeseries and
100,000 samples show roughly a 13% decrease in total (VIRT) memory usage. In my
tests, this advantage for some reason decreased a bit the more samples the
timeseries had (to 5-7% for millions of samples). This I can't fully explain,
but perhaps garbage collection issues were involved.
*WHEN TO USE THE NEW TIMESTAMP TYPE*
The new clientmodel.Timestamp type should be used whenever time
calculations are either directly or indirectly related to sample
timestamps.
For example:
- the timestamp of a sample itself
- all kinds of watermarks
- anything that may become or is compared to a sample timestamp (like the timestamp
passed into Target.Scrape()).
When to still use time.Time:
- for measuring durations/times not related to sample timestamps, like duration
telemetry exporting, timers that indicate how frequently to execute some
action, etc.
*NOTE ON OPERATOR OPTIMIZATION TESTS*
We don't use operator optimization code anymore, but it still lives in
the code as dead code. It still has tests, but I couldn't get all of them to
pass with the new timestamp format. I commented out the failing cases for now,
but we should probably remove the dead code soon. I just didn't want to do that
in the same change as this.
Change-Id: I821787414b0debe85c9fffaeb57abd453727af0f
2013-10-28 06:35:02 -07:00
|
|
|
if actual.Timestamp.Time().Month() != expected.month {
|
|
|
|
t.Fatalf("%d.%d.%d(%s). Expected %d but got: %d\n", i, j, k, behavior.name, expected.month, actual.Timestamp.Time().Month())
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
// 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 09:03:26 -08:00
|
|
|
|
|
|
|
// Test Definitions Follow
|
|
|
|
|
|
|
|
func testMemoryGetValueAtTime(t test.Tester) {
|
2014-02-14 10:36:27 -08:00
|
|
|
persistenceMaker := func() (ViewableMetricPersistence, test.Closer) {
|
2013-06-06 09:16:22 -07:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-02-08 09:03:26 -08: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) {
|
2014-02-14 10:36:27 -08:00
|
|
|
persistenceMaker := func() (ViewableMetricPersistence, test.Closer) {
|
2013-06-06 09:16:22 -07:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-05-11 17:03:16 -07:00
|
|
|
GetRangeValuesTests(persistenceMaker, false, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testMemoryGetBoundaryValues(t test.Tester) {
|
2014-02-14 10:36:27 -08:00
|
|
|
persistenceMaker := func() (ViewableMetricPersistence, test.Closer) {
|
2013-06-06 09:16:22 -07:00
|
|
|
return NewMemorySeriesStorage(MemorySeriesOptions{}), test.NilCloser
|
2013-05-11 17:03:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GetRangeValuesTests(persistenceMaker, true, t)
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMemoryGetRangeValues(t *testing.T) {
|
|
|
|
testMemoryGetRangeValues(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMemoryGetRangeValues(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testMemoryGetRangeValues(b)
|
|
|
|
}
|
|
|
|
}
|