2013-03-06 18:16:20 -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.
|
|
|
|
|
2014-04-11 00:27:05 -07:00
|
|
|
package tiered
|
2013-03-06 18:16:20 -08:00
|
|
|
|
|
|
|
import (
|
2014-03-10 07:04:42 -07:00
|
|
|
"math"
|
2013-03-26 06:46:02 -07:00
|
|
|
"sort"
|
2013-03-06 18:16:20 -08:00
|
|
|
"testing"
|
|
|
|
"time"
|
2013-06-25 05:02:27 -07:00
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/stats"
|
2014-04-11 00:27:05 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/metric"
|
2013-03-06 18:16:20 -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
|
|
|
func buildSamples(from, to clientmodel.Timestamp, interval time.Duration, m clientmodel.Metric) (v clientmodel.Samples) {
|
2013-06-25 05:02:27 -07:00
|
|
|
i := clientmodel.SampleValue(0)
|
2013-03-07 11:01:32 -08:00
|
|
|
|
|
|
|
for from.Before(to) {
|
2013-06-25 05:02:27 -07:00
|
|
|
v = append(v, &clientmodel.Sample{
|
2013-03-07 11:01:32 -08:00
|
|
|
Metric: m,
|
|
|
|
Value: i,
|
|
|
|
Timestamp: from,
|
|
|
|
})
|
|
|
|
|
|
|
|
from = from.Add(interval)
|
2013-03-12 10:27:27 -07:00
|
|
|
i++
|
2013-03-07 11:01:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-04-11 00:27:05 -07:00
|
|
|
func buildValues(firstValue clientmodel.SampleValue, from, to clientmodel.Timestamp, interval time.Duration) (v metric.Values) {
|
2014-03-10 07:04:42 -07:00
|
|
|
for from.Before(to) {
|
2014-04-11 00:27:05 -07:00
|
|
|
v = append(v, metric.SamplePair{
|
2014-03-10 07:04:42 -07:00
|
|
|
Value: firstValue,
|
|
|
|
Timestamp: from,
|
|
|
|
})
|
|
|
|
|
|
|
|
from = from.Add(interval)
|
|
|
|
firstValue++
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:27:24 -07:00
|
|
|
func testMakeView(t testing.TB, flushToDisk bool) {
|
2013-03-06 18:16:20 -08:00
|
|
|
type in struct {
|
|
|
|
atTime []getValuesAtTimeOp
|
|
|
|
atInterval []getValuesAtIntervalOp
|
|
|
|
alongRange []getValuesAlongRangeOp
|
|
|
|
}
|
|
|
|
|
|
|
|
type out struct {
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime []metric.Values
|
|
|
|
atInterval []metric.Values
|
|
|
|
alongRange []metric.Values
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
2014-04-11 00:27:05 -07:00
|
|
|
m := clientmodel.Metric{clientmodel.MetricNameLabel: "request_count"}
|
2013-06-25 05:02:27 -07:00
|
|
|
fingerprint := &clientmodel.Fingerprint{}
|
2014-04-11 00:27:05 -07:00
|
|
|
fingerprint.LoadFromMetric(m)
|
2013-03-06 18:16:20 -08:00
|
|
|
var (
|
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
|
|
|
instant = clientmodel.TimestampFromTime(time.Date(1984, 3, 30, 0, 0, 0, 0, time.Local))
|
2013-06-25 05:02:27 -07:00
|
|
|
scenarios = []struct {
|
2014-03-18 08:22:50 -07:00
|
|
|
data clientmodel.Samples
|
|
|
|
in in
|
|
|
|
out out
|
|
|
|
diskOnly bool
|
2013-03-06 18:16:20 -08:00
|
|
|
}{
|
2013-03-16 01:30:31 -07:00
|
|
|
// No sample, but query asks for one.
|
|
|
|
{
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{{}},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
// Single sample, query asks for exact sample time.
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-06 18:16:20 -08:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant},
|
2013-03-06 18:16:20 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant,
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
// Single sample, query time before the sample.
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-06 18:16:20 -08:00
|
|
|
Value: 0,
|
2013-03-16 01:30:31 -07:00
|
|
|
Timestamp: instant.Add(time.Second),
|
2013-03-06 18:16:20 -08:00
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-06 18:16:20 -08:00
|
|
|
Value: 1,
|
2013-03-16 01:30:31 -07:00
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
2013-03-06 18:16:20 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant},
|
2013-03-06 18:16:20 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-16 01:30:31 -07:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Single sample, query time after the sample.
|
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-16 01:30:31 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-16 01:30:31 -07:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant.Add(time.Second)},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-06 18:16:20 -08:00
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant,
|
|
|
|
Value: 0,
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Two samples, query asks for first sample time.
|
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-16 01:30:31 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-16 01:30:31 -07:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-16 01:30:31 -07:00
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-16 01:30:31 -07:00
|
|
|
{
|
2013-03-06 18:16:20 -08:00
|
|
|
{
|
2013-03-16 01:30:31 -07:00
|
|
|
Timestamp: instant,
|
|
|
|
Value: 0,
|
2013-03-06 18:16:20 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
// Three samples, query asks for second sample time.
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant.Add(time.Second)},
|
2013-03-07 11:01:32 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
Value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
// Three samples, query asks for time between first and second samples.
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(time.Second * 4),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant.Add(time.Second)},
|
2013-03-07 11:01:32 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant,
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
|
|
|
Value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-16 01:30:31 -07:00
|
|
|
// Three samples, query asks for time between second and third samples.
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2013-06-25 05:02:27 -07:00
|
|
|
data: clientmodel.Samples{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
|
|
|
},
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2013-03-07 11:01:32 -08:00
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(time.Second * 4),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant.Add(time.Second * 3)},
|
2013-03-07 11:01:32 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-07 11:01:32 -08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * 2),
|
|
|
|
Value: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * 4),
|
|
|
|
Value: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-03-10 07:04:42 -07:00
|
|
|
// Two chunks of samples, query asks for values from second chunk.
|
2013-03-16 01:30:31 -07:00
|
|
|
{
|
2014-03-10 07:04:42 -07:00
|
|
|
data: buildSamples(
|
|
|
|
instant,
|
|
|
|
instant.Add(time.Duration(*leveldbChunkSize*4)*time.Second),
|
|
|
|
2*time.Second,
|
2014-04-11 00:27:05 -07:00
|
|
|
m,
|
2014-03-10 07:04:42 -07:00
|
|
|
),
|
2013-03-16 01:30:31 -07:00
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
baseOp: baseOp{current: instant.Add(time.Second*time.Duration(*leveldbChunkSize*2) + clientmodel.MinimumTick)},
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2013-03-16 01:30:31 -07: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
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2)),
|
|
|
|
Value: 200,
|
2013-03-16 01:30:31 -07: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
|
|
|
Timestamp: instant.Add(time.Second * (time.Duration(*leveldbChunkSize*2) + 2)),
|
|
|
|
Value: 201,
|
2013-03-16 01:30:31 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-03-10 07:04:42 -07:00
|
|
|
// Two chunks of samples, query asks for values between both chunks.
|
|
|
|
{
|
|
|
|
data: buildSamples(
|
|
|
|
instant,
|
|
|
|
instant.Add(time.Duration(*leveldbChunkSize*4)*time.Second),
|
|
|
|
2*time.Second,
|
2014-04-11 00:27:05 -07:00
|
|
|
m,
|
2014-03-10 07:04:42 -07:00
|
|
|
),
|
|
|
|
in: in{
|
|
|
|
atTime: []getValuesAtTimeOp{
|
|
|
|
{
|
|
|
|
baseOp: baseOp{current: instant.Add(time.Second*time.Duration(*leveldbChunkSize*2) - clientmodel.MinimumTick)},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atTime: []metric.Values{
|
2014-03-10 07:04:42 -07:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * (time.Duration(*leveldbChunkSize*2) - 2)),
|
|
|
|
Value: 199,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2)),
|
|
|
|
Value: 200,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Two chunks of samples, getValuesAtIntervalOp spanning both.
|
|
|
|
{
|
|
|
|
data: buildSamples(
|
|
|
|
instant,
|
|
|
|
instant.Add(time.Duration(*leveldbChunkSize*6)*time.Second),
|
|
|
|
2*time.Second,
|
2014-04-11 00:27:05 -07:00
|
|
|
m,
|
2014-03-10 07:04:42 -07:00
|
|
|
),
|
|
|
|
in: in{
|
|
|
|
atInterval: []getValuesAtIntervalOp{
|
|
|
|
{
|
|
|
|
getValuesAlongRangeOp: getValuesAlongRangeOp{
|
|
|
|
baseOp: baseOp{current: instant.Add(time.Second*time.Duration(*leveldbChunkSize*2-4) - clientmodel.MinimumTick)},
|
|
|
|
through: instant.Add(time.Second*time.Duration(*leveldbChunkSize*2+4) + clientmodel.MinimumTick),
|
|
|
|
},
|
|
|
|
interval: time.Second * 6,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atInterval: []metric.Values{
|
2014-03-10 07:04:42 -07:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2-6)),
|
|
|
|
Value: 197,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2-4)),
|
|
|
|
Value: 198,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2)),
|
|
|
|
Value: 200,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2+2)),
|
|
|
|
Value: 201,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Three chunks of samples, getValuesAlongRangeOp spanning all of them.
|
|
|
|
{
|
|
|
|
data: buildSamples(
|
|
|
|
instant,
|
|
|
|
instant.Add(time.Duration(*leveldbChunkSize*6)*time.Second),
|
|
|
|
2*time.Second,
|
2014-04-11 00:27:05 -07:00
|
|
|
m,
|
2014-03-10 07:04:42 -07:00
|
|
|
),
|
|
|
|
in: in{
|
|
|
|
alongRange: []getValuesAlongRangeOp{
|
|
|
|
{
|
|
|
|
baseOp: baseOp{current: instant.Add(time.Second*time.Duration(*leveldbChunkSize*2-4) - clientmodel.MinimumTick)},
|
|
|
|
through: instant.Add(time.Second*time.Duration(*leveldbChunkSize*4+2) + clientmodel.MinimumTick),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
alongRange: []metric.Values{buildValues(
|
2014-03-10 07:04:42 -07:00
|
|
|
clientmodel.SampleValue(198),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*2-4)),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*4+2)+clientmodel.MinimumTick),
|
|
|
|
2*time.Second,
|
|
|
|
)},
|
|
|
|
},
|
|
|
|
},
|
2014-03-18 08:22:50 -07:00
|
|
|
// Three chunks of samples and a getValuesAlongIntervalOp with an
|
|
|
|
// interval larger than the natural sample interval, spanning the gap
|
|
|
|
// between the second and third chunks. To test two consecutive
|
|
|
|
// ExtractSamples() calls for the same op, we need three on-disk chunks,
|
|
|
|
// because the first two chunks are loaded from disk together and passed
|
|
|
|
// as one unit into ExtractSamples(). Especially, we want to test that
|
|
|
|
// the first sample of the last chunk is included in the result.
|
|
|
|
//
|
|
|
|
// This is a regression test for an interval operator advancing too far
|
|
|
|
// past the end of the currently available chunk, effectively skipping
|
|
|
|
// over a value which is only available in the next chunk passed to
|
|
|
|
// ExtractSamples().
|
|
|
|
//
|
|
|
|
// Chunk and operator layout, assuming 200 samples per chunk:
|
|
|
|
//
|
|
|
|
// Chunk 1 Chunk 2 Chunk 3
|
|
|
|
// Values: 0......199 200......399 400......599
|
|
|
|
// Times: 0......398 400......798 800......1198
|
|
|
|
// | |
|
|
|
|
// |_________ Operator _______|
|
|
|
|
// 395 399 ...... 795 799 803
|
|
|
|
{
|
|
|
|
data: buildSamples(
|
|
|
|
instant,
|
|
|
|
instant.Add(time.Duration(*leveldbChunkSize*6)*time.Second),
|
|
|
|
2*time.Second,
|
2014-04-11 00:27:05 -07:00
|
|
|
m,
|
2014-03-18 08:22:50 -07:00
|
|
|
),
|
|
|
|
in: in{
|
|
|
|
atInterval: []getValuesAtIntervalOp{
|
|
|
|
{
|
|
|
|
getValuesAlongRangeOp: getValuesAlongRangeOp{
|
|
|
|
baseOp: baseOp{current: instant.Add(time.Second * time.Duration(*leveldbChunkSize*2-5))},
|
|
|
|
through: instant.Add(time.Second * time.Duration(*leveldbChunkSize*4+3)),
|
|
|
|
},
|
|
|
|
interval: time.Second * 4,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atInterval: []metric.Values{
|
2014-03-18 08:22:50 -07:00
|
|
|
// We need two overlapping buildValues() calls here since the last
|
|
|
|
// value of the second chunk is extracted twice (value 399, time
|
|
|
|
// offset 798s).
|
|
|
|
append(
|
|
|
|
// Values 197...399.
|
|
|
|
// Times 394...798.
|
|
|
|
buildValues(
|
|
|
|
clientmodel.SampleValue(197),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*2-6)),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*4)),
|
|
|
|
2*time.Second,
|
|
|
|
),
|
|
|
|
// Values 399...402.
|
|
|
|
// Times 798...804.
|
|
|
|
buildValues(
|
|
|
|
clientmodel.SampleValue(399),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*4-2)),
|
|
|
|
instant.Add(time.Second*time.Duration(*leveldbChunkSize*4+6)),
|
|
|
|
2*time.Second,
|
|
|
|
)...,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// This example only works with on-disk chunks due to the repeatedly
|
|
|
|
// extracted value at the end of the second chunk.
|
|
|
|
diskOnly: true,
|
|
|
|
},
|
2014-03-25 11:07:27 -07:00
|
|
|
// Single sample, getValuesAtIntervalOp starting after the sample.
|
|
|
|
{
|
|
|
|
data: clientmodel.Samples{
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2014-03-25 11:07:27 -07:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atInterval: []getValuesAtIntervalOp{
|
|
|
|
{
|
|
|
|
getValuesAlongRangeOp: getValuesAlongRangeOp{
|
|
|
|
baseOp: baseOp{current: instant.Add(time.Second)},
|
|
|
|
through: instant.Add(time.Second * 2),
|
|
|
|
},
|
|
|
|
interval: time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atInterval: []metric.Values{
|
2014-03-25 11:07:27 -07:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant,
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Single sample, getValuesAtIntervalOp starting before the sample.
|
|
|
|
{
|
|
|
|
data: clientmodel.Samples{
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Metric: m,
|
2014-03-25 11:07:27 -07:00
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
in: in{
|
|
|
|
atInterval: []getValuesAtIntervalOp{
|
|
|
|
{
|
|
|
|
getValuesAlongRangeOp: getValuesAlongRangeOp{
|
|
|
|
baseOp: baseOp{current: instant},
|
|
|
|
through: instant.Add(time.Second * 2),
|
|
|
|
},
|
|
|
|
interval: time.Second,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: out{
|
2014-04-11 00:27:05 -07:00
|
|
|
atInterval: []metric.Values{
|
2014-03-25 11:07:27 -07:00
|
|
|
{
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
Value: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
2014-03-18 08:22:50 -07:00
|
|
|
if scenario.diskOnly && !flushToDisk {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2013-04-24 02:51:40 -07:00
|
|
|
tiered, closer := NewTestTieredStorage(t)
|
2013-03-06 18:16:20 -08:00
|
|
|
|
2013-04-29 07:55:18 -07:00
|
|
|
err := tiered.AppendSamples(scenario.data)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%d. failed to add fixture data: %s", i, err)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
2013-04-18 16:00:57 -07:00
|
|
|
if flushToDisk {
|
|
|
|
tiered.Flush()
|
|
|
|
}
|
2013-03-06 18:16:20 -08:00
|
|
|
|
2014-04-11 00:27:05 -07:00
|
|
|
requestBuilder := tiered.NewViewRequestBuilder()
|
2013-03-06 18:16:20 -08:00
|
|
|
|
|
|
|
for _, atTime := range scenario.in.atTime {
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
requestBuilder.GetMetricAtTime(fingerprint, atTime.current)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, atInterval := range scenario.in.atInterval {
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
requestBuilder.GetMetricAtInterval(fingerprint, atInterval.current, atInterval.through, atInterval.interval)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, alongRange := range scenario.in.alongRange {
|
Remove the multi-op-per-fingerprint capability.
Currently, rendering a view is capable of handling multiple ops for
the same fingerprint efficiently. However, this capability requires a
lot of complexity in the code, which we are not using at all because
the way we assemble a viewRequest will never have more than one
operation per fingerprint.
This commit weeds out the said capability, along with all the code
needed for it. It is still possible to have more than one operation
for the same fingerprint, it will just be handled in a less efficient
way (as proven by the unit tests).
As a result, scanjob.go could be removed entirely.
This commit also contains a few related refactorings and removals of
dead code in operation.go, view,go, and freelist.go. Also, the
docstrings received some love.
Change-Id: I032b976e0880151c3f3fdb3234fb65e484f0e2e5
2014-02-27 11:09:00 -08:00
|
|
|
requestBuilder.GetMetricRange(fingerprint, alongRange.current, alongRange.through)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
2014-04-11 00:27:05 -07:00
|
|
|
v, err := requestBuilder.Execute(time.Second*5, stats.NewTimerGroup())
|
2013-03-06 18:16:20 -08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%d. failed due to %s", i, err)
|
|
|
|
}
|
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
// To get all values in the View, ask for the 'forever' interval.
|
2014-04-11 00:27:05 -07:00
|
|
|
interval := metric.Interval{OldestInclusive: math.MinInt64, NewestInclusive: math.MaxInt64}
|
2014-03-10 07:04:42 -07:00
|
|
|
|
|
|
|
for j, atTime := range scenario.out.atTime {
|
|
|
|
actual := v.GetRangeValues(fingerprint, interval)
|
|
|
|
|
|
|
|
if len(actual) != len(atTime) {
|
|
|
|
t.Fatalf("%d.%d. expected %d output, got %d", i, j, len(atTime), len(actual))
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, value := range atTime {
|
|
|
|
if value.Value != actual[k].Value {
|
|
|
|
t.Errorf("%d.%d.%d expected %v value, got %v", i, j, k, value.Value, actual[k].Value)
|
|
|
|
}
|
|
|
|
if !value.Timestamp.Equal(actual[k].Timestamp) {
|
2014-03-18 08:22:50 -07:00
|
|
|
t.Errorf("%d.%d.%d expected %s (offset %ss) timestamp, got %s (offset %ss)", i, j, k, value.Timestamp, value.Timestamp.Sub(instant), actual[k].Timestamp, actual[k].Timestamp.Sub(instant))
|
2014-03-10 07:04:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, atInterval := range scenario.out.atInterval {
|
|
|
|
actual := v.GetRangeValues(fingerprint, interval)
|
|
|
|
|
|
|
|
if len(actual) != len(atInterval) {
|
|
|
|
t.Fatalf("%d.%d. expected %d output, got %d", i, j, len(atInterval), len(actual))
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, value := range atInterval {
|
|
|
|
if value.Value != actual[k].Value {
|
|
|
|
t.Errorf("%d.%d.%d expected %v value, got %v", i, j, k, value.Value, actual[k].Value)
|
|
|
|
}
|
|
|
|
if !value.Timestamp.Equal(actual[k].Timestamp) {
|
2014-03-18 08:22:50 -07:00
|
|
|
t.Errorf("%d.%d.%d expected %s (offset %ds) timestamp, got %s (offset %ds, value %s)", i, j, k, value.Timestamp, int(value.Timestamp.Sub(instant)/time.Second), actual[k].Timestamp, int(actual[k].Timestamp.Sub(instant)/time.Second), actual[k].Value)
|
2014-03-10 07:04:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, alongRange := range scenario.out.alongRange {
|
|
|
|
actual := v.GetRangeValues(fingerprint, interval)
|
2013-03-06 18:16:20 -08:00
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
if len(actual) != len(alongRange) {
|
|
|
|
t.Fatalf("%d.%d. expected %d output, got %d", i, j, len(alongRange), len(actual))
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
for k, value := range alongRange {
|
2013-03-06 18:16:20 -08:00
|
|
|
if value.Value != actual[k].Value {
|
2013-03-12 10:27:27 -07:00
|
|
|
t.Fatalf("%d.%d.%d expected %v value, got %v", i, j, k, value.Value, actual[k].Value)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
if !value.Timestamp.Equal(actual[k].Timestamp) {
|
2014-03-18 08:22:50 -07:00
|
|
|
t.Fatalf("%d.%d.%d expected %s (offset %ss) timestamp, got %s (offset %ss)", i, j, k, value.Timestamp, value.Timestamp.Sub(instant), actual[k].Timestamp, actual[k].Timestamp.Sub(instant))
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 03:45:45 -07:00
|
|
|
closer.Close()
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-18 16:00:57 -07:00
|
|
|
func TestMakeViewFlush(t *testing.T) {
|
|
|
|
testMakeView(t, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkMakeViewFlush(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testMakeView(b, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMakeViewNoFlush(t *testing.T) {
|
|
|
|
testMakeView(t, false)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
|
2013-04-18 16:00:57 -07:00
|
|
|
func BenchmarkMakeViewNoFlush(b *testing.B) {
|
2013-03-06 18:16:20 -08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2013-04-18 16:00:57 -07:00
|
|
|
testMakeView(b, false)
|
2013-03-06 18:16:20 -08:00
|
|
|
}
|
|
|
|
}
|
2013-03-25 05:04:47 -07:00
|
|
|
|
2013-03-26 03:45:56 -07:00
|
|
|
func TestGetAllValuesForLabel(t *testing.T) {
|
2013-03-25 05:04:47 -07:00
|
|
|
type in struct {
|
|
|
|
metricName string
|
|
|
|
appendToMemory bool
|
|
|
|
appendToDisk bool
|
|
|
|
}
|
|
|
|
|
|
|
|
scenarios := []struct {
|
|
|
|
in []in
|
|
|
|
out []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
// Empty case.
|
|
|
|
}, {
|
|
|
|
in: []in{
|
|
|
|
{
|
|
|
|
metricName: "request_count",
|
|
|
|
appendToMemory: false,
|
|
|
|
appendToDisk: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []string{
|
|
|
|
"request_count",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: []in{
|
|
|
|
{
|
|
|
|
metricName: "request_count",
|
|
|
|
appendToMemory: true,
|
|
|
|
appendToDisk: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
metricName: "start_time",
|
|
|
|
appendToMemory: false,
|
|
|
|
appendToDisk: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []string{
|
|
|
|
"request_count",
|
|
|
|
"start_time",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: []in{
|
|
|
|
{
|
|
|
|
metricName: "request_count",
|
|
|
|
appendToMemory: true,
|
|
|
|
appendToDisk: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
metricName: "start_time",
|
|
|
|
appendToMemory: true,
|
|
|
|
appendToDisk: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
out: []string{
|
|
|
|
"request_count",
|
|
|
|
"start_time",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
2013-04-24 02:51:40 -07:00
|
|
|
tiered, closer := NewTestTieredStorage(t)
|
2013-03-25 05:04:47 -07:00
|
|
|
for j, metric := range scenario.in {
|
2013-06-25 05:02:27 -07:00
|
|
|
sample := &clientmodel.Sample{
|
|
|
|
Metric: clientmodel.Metric{clientmodel.MetricNameLabel: clientmodel.LabelValue(metric.metricName)},
|
2013-03-25 05:04:47 -07:00
|
|
|
}
|
|
|
|
if metric.appendToMemory {
|
2013-05-02 09:27:12 -07:00
|
|
|
if err := tiered.memoryArena.AppendSample(sample); err != nil {
|
2013-03-25 05:04:47 -07:00
|
|
|
t.Fatalf("%d.%d. failed to add fixture data: %s", i, j, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if metric.appendToDisk {
|
2013-05-07 01:18:19 -07:00
|
|
|
if err := tiered.DiskStorage.AppendSample(sample); err != nil {
|
2013-03-25 05:04:47 -07:00
|
|
|
t.Fatalf("%d.%d. failed to add fixture data: %s", i, j, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-25 05:02:27 -07:00
|
|
|
metricNames, err := tiered.GetAllValuesForLabel(clientmodel.MetricNameLabel)
|
2013-04-25 04:29:28 -07:00
|
|
|
closer.Close()
|
2013-03-25 05:04:47 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%d. Error getting metric names: %s", i, err)
|
|
|
|
}
|
|
|
|
if len(metricNames) != len(scenario.out) {
|
|
|
|
t.Fatalf("%d. Expected metric count %d, got %d", i, len(scenario.out), len(metricNames))
|
|
|
|
}
|
|
|
|
|
2013-03-26 06:46:02 -07:00
|
|
|
sort.Sort(metricNames)
|
2013-03-25 05:04:47 -07:00
|
|
|
for j, expected := range scenario.out {
|
2013-03-26 03:45:56 -07:00
|
|
|
if expected != string(metricNames[j]) {
|
2013-03-25 05:04:47 -07:00
|
|
|
t.Fatalf("%d.%d. Expected metric %s, got %s", i, j, expected, metricNames[j])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-27 10:50:30 -07:00
|
|
|
|
2014-03-28 03:58:47 -07:00
|
|
|
func TestGetFingerprintsForLabelMatchers(t *testing.T) {
|
2013-04-24 02:51:40 -07:00
|
|
|
tiered, closer := NewTestTieredStorage(t)
|
2013-03-27 10:50:30 -07:00
|
|
|
defer closer.Close()
|
2013-06-25 05:02:27 -07:00
|
|
|
memorySample := &clientmodel.Sample{
|
|
|
|
Metric: clientmodel.Metric{clientmodel.MetricNameLabel: "http_requests", "method": "/foo"},
|
2013-03-27 10:50:30 -07:00
|
|
|
}
|
2013-06-25 05:02:27 -07:00
|
|
|
diskSample := &clientmodel.Sample{
|
|
|
|
Metric: clientmodel.Metric{clientmodel.MetricNameLabel: "http_requests", "method": "/bar"},
|
2013-03-27 10:50:30 -07:00
|
|
|
}
|
2013-05-02 09:27:12 -07:00
|
|
|
if err := tiered.memoryArena.AppendSample(memorySample); err != nil {
|
2013-03-27 10:50:30 -07:00
|
|
|
t.Fatalf("Failed to add fixture data: %s", err)
|
|
|
|
}
|
2013-05-07 01:18:19 -07:00
|
|
|
if err := tiered.DiskStorage.AppendSample(diskSample); err != nil {
|
2013-03-27 10:50:30 -07:00
|
|
|
t.Fatalf("Failed to add fixture data: %s", err)
|
|
|
|
}
|
|
|
|
tiered.Flush()
|
|
|
|
|
|
|
|
scenarios := []struct {
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers metric.LabelMatchers
|
2014-03-28 03:58:47 -07:00
|
|
|
fpCount int
|
2013-03-27 10:50:30 -07:00
|
|
|
}{
|
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers: metric.LabelMatchers{},
|
2014-03-28 03:58:47 -07:00
|
|
|
fpCount: 0,
|
2013-03-28 04:16:31 -07:00
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers: metric.LabelMatchers{
|
2014-03-28 03:58:47 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: clientmodel.MetricNameLabel,
|
|
|
|
Value: "http_requests",
|
|
|
|
},
|
2013-03-27 10:50:30 -07:00
|
|
|
},
|
|
|
|
fpCount: 2,
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers: metric.LabelMatchers{
|
2014-03-28 03:58:47 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: clientmodel.MetricNameLabel,
|
|
|
|
Value: "http_requests",
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: "method",
|
|
|
|
Value: "/foo",
|
|
|
|
},
|
2013-03-27 10:50:30 -07:00
|
|
|
},
|
|
|
|
fpCount: 1,
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers: metric.LabelMatchers{
|
2014-03-28 03:58:47 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: clientmodel.MetricNameLabel,
|
|
|
|
Value: "http_requests",
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: "method",
|
|
|
|
Value: "/bar",
|
|
|
|
},
|
2013-03-27 10:50:30 -07:00
|
|
|
},
|
|
|
|
fpCount: 1,
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
matchers: metric.LabelMatchers{
|
2014-03-28 03:58:47 -07:00
|
|
|
{
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: clientmodel.MetricNameLabel,
|
|
|
|
Value: "http_requests",
|
|
|
|
}, {
|
2014-04-11 00:27:05 -07:00
|
|
|
Type: metric.Equal,
|
2014-03-28 03:58:47 -07:00
|
|
|
Name: "method",
|
|
|
|
Value: "/baz",
|
|
|
|
},
|
2013-03-27 10:50:30 -07:00
|
|
|
},
|
|
|
|
fpCount: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
2014-03-28 03:58:47 -07:00
|
|
|
fingerprints, err := tiered.GetFingerprintsForLabelMatchers(scenario.matchers)
|
2013-03-27 10:50:30 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%d. Error getting metric names: %s", i, err)
|
|
|
|
}
|
|
|
|
if len(fingerprints) != scenario.fpCount {
|
|
|
|
t.Fatalf("%d. Expected metric count %d, got %d", i, scenario.fpCount, len(fingerprints))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 11:39:59 -07:00
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
func TestTruncateBefore(t *testing.T) {
|
2013-05-08 11:39:59 -07:00
|
|
|
type in struct {
|
2014-04-11 00:27:05 -07:00
|
|
|
values metric.Values
|
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.Timestamp
|
2013-05-08 11:39:59 -07: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
|
|
|
instant := clientmodel.Now()
|
2013-05-08 11:39:59 -07:00
|
|
|
var scenarios = []struct {
|
|
|
|
in in
|
2014-04-11 00:27:05 -07:00
|
|
|
out metric.Values
|
2013-05-08 11:39:59 -07:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
in: in{
|
|
|
|
time: instant,
|
2014-04-11 00:27:05 -07:00
|
|
|
values: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
{
|
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(2 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 3,
|
|
|
|
Timestamp: instant.Add(3 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-04-11 00:27:05 -07:00
|
|
|
out: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
{
|
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(2 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 3,
|
|
|
|
Timestamp: instant.Add(3 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: in{
|
|
|
|
time: instant.Add(2 * time.Second),
|
2014-04-11 00:27:05 -07:00
|
|
|
values: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
{
|
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(2 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 3,
|
|
|
|
Timestamp: instant.Add(3 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-04-11 00:27:05 -07:00
|
|
|
out: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
{
|
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(2 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 3,
|
|
|
|
Timestamp: instant.Add(3 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: in{
|
|
|
|
time: instant.Add(5 * time.Second),
|
2014-04-11 00:27:05 -07:00
|
|
|
values: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
{
|
|
|
|
Value: 0,
|
|
|
|
Timestamp: instant,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 1,
|
|
|
|
Timestamp: instant.Add(time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 2,
|
|
|
|
Timestamp: instant.Add(2 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 3,
|
|
|
|
Timestamp: instant.Add(3 * time.Second),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2014-04-11 00:27:05 -07:00
|
|
|
out: metric.Values{
|
2013-05-08 11:39:59 -07:00
|
|
|
// Preserve the last value in case it needs to be used for the next set.
|
|
|
|
{
|
|
|
|
Value: 4,
|
|
|
|
Timestamp: instant.Add(4 * time.Second),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, scenario := range scenarios {
|
|
|
|
actual := chunk(scenario.in.values).TruncateBefore(scenario.in.time)
|
|
|
|
|
|
|
|
if len(actual) != len(scenario.out) {
|
|
|
|
t.Fatalf("%d. expected length of %d, got %d", i, len(scenario.out), len(actual))
|
|
|
|
}
|
|
|
|
|
|
|
|
for j, actualValue := range actual {
|
2014-03-10 09:55:17 -07:00
|
|
|
if !actualValue.Equal(&scenario.out[j]) {
|
2013-05-08 11:39:59 -07:00
|
|
|
t.Fatalf("%d.%d. expected %s, got %s", i, j, scenario.out[j], actualValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-02 07:45:53 -08:00
|
|
|
func TestGetMetricForFingerprintCachesCopyOfMetric(t *testing.T) {
|
|
|
|
ts, closer := NewTestTieredStorage(t)
|
|
|
|
defer closer.Close()
|
|
|
|
|
|
|
|
m := clientmodel.Metric{
|
|
|
|
clientmodel.MetricNameLabel: "testmetric",
|
|
|
|
}
|
|
|
|
samples := clientmodel.Samples{
|
|
|
|
&clientmodel.Sample{
|
|
|
|
Metric: m,
|
|
|
|
Value: 0,
|
|
|
|
Timestamp: clientmodel.Now(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ts.AppendSamples(samples); err != nil {
|
2014-02-03 03:27:01 -08:00
|
|
|
t.Fatal(err)
|
2014-02-02 07:45:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ts.Flush()
|
|
|
|
|
|
|
|
fp := &clientmodel.Fingerprint{}
|
|
|
|
fp.LoadFromMetric(m)
|
|
|
|
m, err := ts.GetMetricForFingerprint(fp)
|
|
|
|
if err != nil {
|
2014-02-03 03:27:01 -08:00
|
|
|
t.Fatal(err)
|
2014-02-02 07:45:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
m[clientmodel.MetricNameLabel] = "changedmetric"
|
|
|
|
|
|
|
|
m, err = ts.GetMetricForFingerprint(fp)
|
|
|
|
if err != nil {
|
2014-02-03 03:27:01 -08:00
|
|
|
t.Fatal(err)
|
2014-02-02 07:45:53 -08:00
|
|
|
}
|
|
|
|
if m[clientmodel.MetricNameLabel] != "testmetric" {
|
|
|
|
t.Fatal("Metric name label value has changed: ", m[clientmodel.MetricNameLabel])
|
|
|
|
}
|
|
|
|
}
|