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 (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"time"
|
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
|
|
|
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
2013-02-08 09:03:26 -08:00
|
|
|
)
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// op encapsulates a primitive query operation.
|
2013-02-08 09:03:26 -08:00
|
|
|
type op interface {
|
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
|
|
|
// Fingerprint returns the fingerprint of the metric this operation
|
|
|
|
// operates on.
|
|
|
|
Fingerprint() *clientmodel.Fingerprint
|
|
|
|
// ExtractSamples extracts samples from a stream of values and advances
|
|
|
|
// the operation time.
|
2013-05-07 05:25:01 -07:00
|
|
|
ExtractSamples(Values) Values
|
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
|
|
|
// Consumed returns whether the operator has consumed all data it needs.
|
2013-05-07 05:25:01 -07:00
|
|
|
Consumed() bool
|
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
|
|
|
// CurrentTime gets the current operation time. In a newly created op,
|
|
|
|
// this is the starting time of the operation. During ongoing execution
|
|
|
|
// of the op, the current time is advanced accordingly. Once no
|
|
|
|
// subsequent work associated with the operation remains, nil is
|
|
|
|
// returned.
|
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
|
|
|
CurrentTime() clientmodel.Timestamp
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// durationOperator encapsulates a general operation that occurs over a
|
|
|
|
// duration.
|
|
|
|
type durationOperator interface {
|
|
|
|
op
|
|
|
|
Through() clientmodel.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
// ops is a heap of operations, primary sorting key is the fingerprint.
|
2013-02-08 09:03:26 -08:00
|
|
|
type ops []op
|
|
|
|
|
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
|
|
|
// Len implements sort.Interface and heap.Interface.
|
2013-02-08 09:03:26 -08:00
|
|
|
func (o ops) Len() int {
|
|
|
|
return len(o)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Less implements sort.Interface and heap.Interface. It compares the
|
|
|
|
// fingerprints. If they are equal, the comparison is delegated to
|
|
|
|
// currentTimeSort.
|
|
|
|
func (o ops) Less(i, j int) bool {
|
|
|
|
fpi := o[i].Fingerprint()
|
|
|
|
fpj := o[j].Fingerprint()
|
|
|
|
if fpi.Equal(fpj) {
|
|
|
|
return currentTimeSort{o}.Less(i, j)
|
|
|
|
}
|
|
|
|
return fpi.Less(fpj)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap implements sort.Interface and heap.Interface.
|
|
|
|
func (o ops) Swap(i, j int) {
|
|
|
|
o[i], o[j] = o[j], o[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push implements heap.Interface.
|
|
|
|
func (o *ops) Push(x interface{}) {
|
|
|
|
// Push and Pop use pointer receivers because they modify the slice's
|
|
|
|
// length, not just its contents.
|
|
|
|
*o = append(*o, x.(op))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push implements heap.Interface.
|
|
|
|
func (o *ops) Pop() interface{} {
|
|
|
|
old := *o
|
|
|
|
n := len(old)
|
|
|
|
x := old[n-1]
|
|
|
|
*o = old[0 : n-1]
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
// currentTimeSort is a wrapper for ops with customized sorting order.
|
|
|
|
type currentTimeSort struct {
|
2013-03-15 13:05:51 -07:00
|
|
|
ops
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// currentTimeSort implements sort.Interface and sorts the operations in
|
|
|
|
// chronological order by their current time.
|
|
|
|
func (s currentTimeSort) Less(i, j int) bool {
|
|
|
|
return s.ops[i].CurrentTime().Before(s.ops[j].CurrentTime())
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
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 contains the implementations and fields shared between different op
|
|
|
|
// types.
|
|
|
|
type baseOp struct {
|
|
|
|
fp clientmodel.Fingerprint
|
|
|
|
current clientmodel.Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *baseOp) Fingerprint() *clientmodel.Fingerprint {
|
|
|
|
return &g.fp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *baseOp) CurrentTime() clientmodel.Timestamp {
|
|
|
|
return g.current
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// getValuesAtTimeOp encapsulates getting values at or adjacent to a specific
|
|
|
|
// time.
|
2013-02-08 09:03:26 -08:00
|
|
|
type getValuesAtTimeOp struct {
|
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
|
2013-03-13 14:05:58 -07:00
|
|
|
consumed bool
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-06-19 06:00:00 -07:00
|
|
|
func (g *getValuesAtTimeOp) String() string {
|
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
|
|
|
return fmt.Sprintf("getValuesAtTimeOp at %s", g.current)
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
func (g *getValuesAtTimeOp) ExtractSamples(in Values) (out Values) {
|
2013-03-13 16:27:14 -07:00
|
|
|
if len(in) == 0 {
|
|
|
|
return
|
|
|
|
}
|
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
|
|
|
out = extractValuesAroundTime(g.current, in)
|
2013-03-13 14:05:58 -07:00
|
|
|
g.consumed = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-07 05:25:01 -07:00
|
|
|
func (g getValuesAtTimeOp) Consumed() bool {
|
|
|
|
return g.consumed
|
2013-03-13 14:05:58 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// getValuesAlongRangeOp encapsulates getting all values in a given range.
|
2013-02-08 09:03:26 -08:00
|
|
|
type getValuesAlongRangeOp struct {
|
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
|
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
|
|
|
through clientmodel.Timestamp
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
func (g *getValuesAlongRangeOp) String() string {
|
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
|
|
|
return fmt.Sprintf("getValuesAlongRangeOp from %s through %s", g.current, g.through)
|
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
|
|
|
func (g *getValuesAlongRangeOp) Through() clientmodel.Timestamp {
|
2013-02-08 09:03:26 -08:00
|
|
|
return g.through
|
|
|
|
}
|
|
|
|
|
2013-06-25 05:02:27 -07:00
|
|
|
func (g *getValuesAlongRangeOp) ExtractSamples(in Values) (out Values) {
|
2013-03-13 16:27:14 -07:00
|
|
|
if len(in) == 0 {
|
|
|
|
return
|
|
|
|
}
|
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
|
|
|
// Find the first sample where time >= g.current.
|
2013-03-13 23:22:59 -07:00
|
|
|
firstIdx := sort.Search(len(in), func(i int) bool {
|
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
|
|
|
return !in[i].Timestamp.Before(g.current)
|
2013-03-13 23:22:59 -07:00
|
|
|
})
|
|
|
|
if firstIdx == len(in) {
|
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
|
|
|
// No samples at or after operator start time. This can only
|
|
|
|
// happen if we try applying the operator to a time after the
|
|
|
|
// last recorded sample. In this case, we're finished.
|
|
|
|
g.current = g.through.Add(clientmodel.MinimumTick)
|
2013-03-13 23:22:59 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the first sample where time > g.through.
|
|
|
|
lastIdx := sort.Search(len(in), func(i int) bool {
|
|
|
|
return in[i].Timestamp.After(g.through)
|
|
|
|
})
|
|
|
|
if lastIdx == firstIdx {
|
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
|
|
|
g.current = g.through.Add(clientmodel.MinimumTick)
|
2013-03-13 23:22:59 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-03-14 14:27:51 -07:00
|
|
|
lastSampleTime := in[lastIdx-1].Timestamp
|
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
|
|
|
// Sample times are stored with a maximum time resolution of one second,
|
|
|
|
// so we have to add exactly that to target the next chunk on the next
|
|
|
|
// op iteration.
|
|
|
|
g.current = lastSampleTime.Add(time.Second)
|
2013-03-13 23:22:59 -07:00
|
|
|
return in[firstIdx:lastIdx]
|
2013-03-13 14:05:58 -07:00
|
|
|
}
|
|
|
|
|
2013-05-07 05:25:01 -07:00
|
|
|
func (g *getValuesAlongRangeOp) Consumed() bool {
|
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
|
|
|
return g.current.After(g.through)
|
2013-03-15 13:05:51 -07:00
|
|
|
}
|
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
// getValuesAtIntervalOp encapsulates getting values at a given interval over a
|
|
|
|
// duration.
|
|
|
|
type getValuesAtIntervalOp struct {
|
|
|
|
getValuesAlongRangeOp
|
|
|
|
interval time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getValuesAtIntervalOp) String() string {
|
|
|
|
return fmt.Sprintf("getValuesAtIntervalOp from %s each %s through %s", g.current, g.interval, g.through)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getValuesAtIntervalOp) ExtractSamples(in Values) (out Values) {
|
|
|
|
if len(in) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lastChunkTime := in[len(in)-1].Timestamp
|
|
|
|
for len(in) > 0 {
|
|
|
|
out = append(out, extractValuesAroundTime(g.current, in)...)
|
|
|
|
lastExtractedTime := out[len(out)-1].Timestamp
|
|
|
|
in = in.TruncateBefore(lastExtractedTime.Add(
|
|
|
|
clientmodel.MinimumTick))
|
|
|
|
g.current = g.current.Add(g.interval)
|
|
|
|
for !g.current.After(lastExtractedTime) {
|
|
|
|
g.current = g.current.Add(g.interval)
|
|
|
|
}
|
|
|
|
if lastExtractedTime.Equal(lastChunkTime) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if g.current.After(g.through) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
// getValueRangeAtIntervalOp encapsulates getting all values from ranges along
|
|
|
|
// intervals.
|
2013-05-07 05:25:01 -07:00
|
|
|
//
|
|
|
|
// Works just like getValuesAlongRangeOp, but when from > through, through is
|
|
|
|
// incremented by interval and from is reset to through-rangeDuration. Returns
|
|
|
|
// current time nil when from > totalThrough.
|
|
|
|
type getValueRangeAtIntervalOp struct {
|
2014-03-10 07:04:42 -07:00
|
|
|
getValuesAtIntervalOp
|
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
|
|
|
rangeThrough clientmodel.Timestamp
|
2013-05-07 05:25:01 -07:00
|
|
|
rangeDuration time.Duration
|
|
|
|
}
|
|
|
|
|
2014-02-14 10:36:27 -08:00
|
|
|
func (g *getValueRangeAtIntervalOp) String() string {
|
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
|
|
|
return fmt.Sprintf("getValueRangeAtIntervalOp range %s from %s each %s through %s", g.rangeDuration, g.current, g.interval, g.through)
|
2013-05-07 05:25:01 -07:00
|
|
|
}
|
|
|
|
|
2014-03-10 07:04:42 -07:00
|
|
|
// Through panics because the notion of 'through' is ambiguous for this op.
|
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 (g *getValueRangeAtIntervalOp) Through() clientmodel.Timestamp {
|
2013-05-07 05:25:01 -07:00
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getValueRangeAtIntervalOp) advanceToNextInterval() {
|
|
|
|
g.rangeThrough = g.rangeThrough.Add(g.interval)
|
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
|
|
|
g.current = g.rangeThrough.Add(-g.rangeDuration)
|
2013-05-07 05:25:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getValueRangeAtIntervalOp) ExtractSamples(in Values) (out Values) {
|
|
|
|
if len(in) == 0 {
|
|
|
|
return
|
|
|
|
}
|
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
|
|
|
// Find the first sample where time >= g.current.
|
2013-05-07 05:25:01 -07:00
|
|
|
firstIdx := sort.Search(len(in), func(i int) bool {
|
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
|
|
|
return !in[i].Timestamp.Before(g.current)
|
2013-05-07 05:25:01 -07:00
|
|
|
})
|
|
|
|
if firstIdx == len(in) {
|
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
|
|
|
// No samples at or after operator start time. This can only
|
|
|
|
// happen if we try applying the operator to a time after the
|
|
|
|
// last recorded sample. In this case, we're finished.
|
|
|
|
g.current = g.through.Add(clientmodel.MinimumTick)
|
2013-05-07 05:25:01 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the first sample where time > g.rangeThrough.
|
|
|
|
lastIdx := sort.Search(len(in), func(i int) bool {
|
|
|
|
return in[i].Timestamp.After(g.rangeThrough)
|
|
|
|
})
|
|
|
|
// This only happens when there is only one sample and it is both after
|
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
|
|
|
// g.current and after g.rangeThrough. In this case, both indexes are 0.
|
2013-05-07 05:25:01 -07:00
|
|
|
if lastIdx == firstIdx {
|
|
|
|
g.advanceToNextInterval()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lastSampleTime := in[lastIdx-1].Timestamp
|
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
|
|
|
// Sample times are stored with a maximum time resolution of one second,
|
|
|
|
// so we have to add exactly that to target the next chunk on the next
|
|
|
|
// op iteration.
|
|
|
|
g.current = lastSampleTime.Add(time.Second)
|
|
|
|
if g.current.After(g.rangeThrough) {
|
2013-05-07 05:25:01 -07:00
|
|
|
g.advanceToNextInterval()
|
|
|
|
}
|
|
|
|
return in[firstIdx:lastIdx]
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// getValuesAtIntervalOps contains getValuesAtIntervalOp operations. It
|
|
|
|
// implements sort.Interface and sorts the operations in ascending order by
|
|
|
|
// their frequency.
|
2013-03-13 14:05:58 -07:00
|
|
|
type getValuesAtIntervalOps []*getValuesAtIntervalOp
|
2013-02-08 09:03:26 -08:00
|
|
|
|
|
|
|
func (s getValuesAtIntervalOps) Len() int {
|
|
|
|
return len(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s getValuesAtIntervalOps) Swap(i, j int) {
|
|
|
|
s[i], s[j] = s[j], s[i]
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (s getValuesAtIntervalOps) Less(i, j int) bool {
|
|
|
|
return s[i].interval < s[j].interval
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// extractValuesAroundTime searches for the provided time in the list of
|
|
|
|
// available samples and emits a slice containing the data points that
|
|
|
|
// are adjacent to it.
|
2013-03-17 15:47:23 -07:00
|
|
|
//
|
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
|
|
|
// An assumption of this is that the provided samples are already sorted!
|
|
|
|
func extractValuesAroundTime(t clientmodel.Timestamp, in Values) Values {
|
|
|
|
i := sort.Search(len(in), func(i int) bool {
|
|
|
|
return !in[i].Timestamp.Before(t)
|
|
|
|
})
|
|
|
|
if i == len(in) {
|
|
|
|
// Target time is past the end, return only the last sample.
|
|
|
|
return in[len(in)-1:]
|
2013-03-17 15:47:23 -07:00
|
|
|
}
|
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
|
|
|
if in[i].Timestamp.Equal(t) && len(in) > i+1 {
|
|
|
|
// We hit exactly the current sample time. Very unlikely in
|
|
|
|
// practice. Return only the current sample.
|
|
|
|
return in[i : i+1]
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
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
|
|
|
if i == 0 {
|
|
|
|
// We hit before the first sample time. Return only the first
|
|
|
|
// sample.
|
|
|
|
return in[0:1]
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|
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
|
|
|
// We hit between two samples. Return both surrounding samples.
|
|
|
|
return in[i-1 : i+1]
|
2013-02-08 09:03:26 -08:00
|
|
|
}
|