Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
1535ef14
P
prometheus
项目概览
doodoocoder
/
prometheus
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
prometheus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1535ef14
编写于
8月 22, 2015
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace metric.SamplePair with model.SamplePair
上级
c9d396f4
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
102 addition
and
138 deletion
+102
-138
promql/engine.go
promql/engine.go
+14
-14
promql/functions.go
promql/functions.go
+6
-6
promql/test.go
promql/test.go
+4
-5
storage/local/chunk.go
storage/local/chunk.go
+8
-8
storage/local/delta.go
storage/local/delta.go
+14
-14
storage/local/doubledelta.go
storage/local/doubledelta.go
+16
-16
storage/local/interface.go
storage/local/interface.go
+4
-4
storage/local/persistence_test.go
storage/local/persistence_test.go
+5
-6
storage/local/series.go
storage/local/series.go
+19
-19
storage/local/storage.go
storage/local/storage.go
+8
-8
storage/local/storage_test.go
storage/local/storage_test.go
+2
-2
storage/metric/sample.go
storage/metric/sample.go
+1
-34
web/api/v1/api_test.go
web/api/v1/api_test.go
+1
-2
未找到文件。
promql/engine.go
浏览文件 @
1535ef14
...
...
@@ -33,8 +33,8 @@ import (
// SampleStream is a stream of Values belonging to an attached COWMetric.
type
SampleStream
struct
{
Metric
model
.
COWMetric
`json:"metric"`
Values
metric
.
Values
`json:"values"`
Metric
model
.
COWMetric
`json:"metric"`
Values
[]
model
.
SamplePair
`json:"values"`
}
// Sample is a single sample belonging to a COWMetric.
...
...
@@ -47,11 +47,11 @@ type Sample struct {
// MarshalJSON implements json.Marshaler.
func
(
s
*
Sample
)
MarshalJSON
()
([]
byte
,
error
)
{
v
:=
struct
{
Metric
model
.
COWMetric
`json:"metric"`
Value
m
etric
.
SamplePair
`json:"value"`
Metric
model
.
COWMetric
`json:"metric"`
Value
m
odel
.
SamplePair
`json:"value"`
}{
Metric
:
s
.
Metric
,
Value
:
m
etric
.
SamplePair
{
Value
:
m
odel
.
SamplePair
{
Timestamp
:
s
.
Timestamp
,
Value
:
s
.
Value
,
},
...
...
@@ -480,10 +480,10 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
// as the fingerprint for scalar expressions.
ss
:=
sampleStreams
[
0
]
if
ss
==
nil
{
ss
=
&
SampleStream
{
Values
:
make
(
metric
.
Values
,
0
,
numSteps
)}
ss
=
&
SampleStream
{
Values
:
make
(
[]
model
.
SamplePair
,
0
,
numSteps
)}
sampleStreams
[
0
]
=
ss
}
ss
.
Values
=
append
(
ss
.
Values
,
m
etric
.
SamplePair
{
ss
.
Values
=
append
(
ss
.
Values
,
m
odel
.
SamplePair
{
Value
:
v
.
Value
,
Timestamp
:
v
.
Timestamp
,
})
...
...
@@ -494,11 +494,11 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
if
ss
==
nil
{
ss
=
&
SampleStream
{
Metric
:
sample
.
Metric
,
Values
:
make
(
metric
.
Values
,
0
,
numSteps
),
Values
:
make
(
[]
model
.
SamplePair
,
0
,
numSteps
),
}
sampleStreams
[
fp
]
=
ss
}
ss
.
Values
=
append
(
ss
.
Values
,
m
etric
.
SamplePair
{
ss
.
Values
=
append
(
ss
.
Values
,
m
odel
.
SamplePair
{
Value
:
sample
.
Value
,
Timestamp
:
sample
.
Timestamp
,
})
...
...
@@ -1177,9 +1177,9 @@ var StalenessDelta = 5 * time.Minute
// surrounding a given target time. If samples are found both before and after
// the target time, the sample value is interpolated between these. Otherwise,
// the single closest sample is returned verbatim.
func
chooseClosestSample
(
samples
metric
.
Values
,
timestamp
model
.
Time
)
*
metric
.
SamplePair
{
var
closestBefore
*
m
etric
.
SamplePair
var
closestAfter
*
m
etric
.
SamplePair
func
chooseClosestSample
(
samples
[]
model
.
SamplePair
,
timestamp
model
.
Time
)
*
model
.
SamplePair
{
var
closestBefore
*
m
odel
.
SamplePair
var
closestAfter
*
m
odel
.
SamplePair
for
_
,
candidate
:=
range
samples
{
delta
:=
candidate
.
Timestamp
.
Sub
(
timestamp
)
// Samples before target time.
...
...
@@ -1223,14 +1223,14 @@ func chooseClosestSample(samples metric.Values, timestamp model.Time) *metric.Sa
// interpolateSamples interpolates a value at a target time between two
// provided sample pairs.
func
interpolateSamples
(
first
,
second
*
m
etric
.
SamplePair
,
timestamp
model
.
Time
)
*
metric
.
SamplePair
{
func
interpolateSamples
(
first
,
second
*
m
odel
.
SamplePair
,
timestamp
model
.
Time
)
*
model
.
SamplePair
{
dv
:=
second
.
Value
-
first
.
Value
dt
:=
second
.
Timestamp
.
Sub
(
first
.
Timestamp
)
dDt
:=
dv
/
model
.
SampleValue
(
dt
)
offset
:=
model
.
SampleValue
(
timestamp
.
Sub
(
first
.
Timestamp
))
return
&
m
etric
.
SamplePair
{
return
&
m
odel
.
SamplePair
{
Value
:
first
.
Value
+
(
offset
*
dDt
),
Timestamp
:
timestamp
,
}
...
...
promql/functions.go
浏览文件 @
1535ef14
...
...
@@ -258,7 +258,7 @@ func funcCountScalar(ev *evaluator, args Expressions) Value {
}
}
func
aggrOverTime
(
ev
*
evaluator
,
args
Expressions
,
aggrFn
func
(
metric
.
Values
)
model
.
SampleValue
)
Value
{
func
aggrOverTime
(
ev
*
evaluator
,
args
Expressions
,
aggrFn
func
(
[]
model
.
SamplePair
)
model
.
SampleValue
)
Value
{
matrix
:=
ev
.
evalMatrix
(
args
[
0
])
resultVector
:=
Vector
{}
...
...
@@ -279,7 +279,7 @@ func aggrOverTime(ev *evaluator, args Expressions, aggrFn func(metric.Values) mo
// === avg_over_time(matrix ExprMatrix) Vector ===
func
funcAvgOverTime
(
ev
*
evaluator
,
args
Expressions
)
Value
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
metric
.
Values
)
model
.
SampleValue
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
[]
model
.
SamplePair
)
model
.
SampleValue
{
var
sum
model
.
SampleValue
for
_
,
v
:=
range
values
{
sum
+=
v
.
Value
...
...
@@ -290,7 +290,7 @@ func funcAvgOverTime(ev *evaluator, args Expressions) Value {
// === count_over_time(matrix ExprMatrix) Vector ===
func
funcCountOverTime
(
ev
*
evaluator
,
args
Expressions
)
Value
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
metric
.
Values
)
model
.
SampleValue
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
[]
model
.
SamplePair
)
model
.
SampleValue
{
return
model
.
SampleValue
(
len
(
values
))
})
}
...
...
@@ -307,7 +307,7 @@ func funcFloor(ev *evaluator, args Expressions) Value {
// === max_over_time(matrix ExprMatrix) Vector ===
func
funcMaxOverTime
(
ev
*
evaluator
,
args
Expressions
)
Value
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
metric
.
Values
)
model
.
SampleValue
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
[]
model
.
SamplePair
)
model
.
SampleValue
{
max
:=
math
.
Inf
(
-
1
)
for
_
,
v
:=
range
values
{
max
=
math
.
Max
(
max
,
float64
(
v
.
Value
))
...
...
@@ -318,7 +318,7 @@ func funcMaxOverTime(ev *evaluator, args Expressions) Value {
// === min_over_time(matrix ExprMatrix) Vector ===
func
funcMinOverTime
(
ev
*
evaluator
,
args
Expressions
)
Value
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
metric
.
Values
)
model
.
SampleValue
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
[]
model
.
SamplePair
)
model
.
SampleValue
{
min
:=
math
.
Inf
(
1
)
for
_
,
v
:=
range
values
{
min
=
math
.
Min
(
min
,
float64
(
v
.
Value
))
...
...
@@ -329,7 +329,7 @@ func funcMinOverTime(ev *evaluator, args Expressions) Value {
// === sum_over_time(matrix ExprMatrix) Vector ===
func
funcSumOverTime
(
ev
*
evaluator
,
args
Expressions
)
Value
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
metric
.
Values
)
model
.
SampleValue
{
return
aggrOverTime
(
ev
,
args
,
func
(
values
[]
model
.
SamplePair
)
model
.
SampleValue
{
var
sum
model
.
SampleValue
for
_
,
v
:=
range
values
{
sum
+=
v
.
Value
...
...
promql/test.go
浏览文件 @
1535ef14
...
...
@@ -26,7 +26,6 @@ import (
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/storage/local"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/strutil"
"github.com/prometheus/prometheus/util/testutil"
)
...
...
@@ -239,14 +238,14 @@ func (*evalCmd) testCmd() {}
type
loadCmd
struct
{
gap
time
.
Duration
metrics
map
[
model
.
Fingerprint
]
model
.
Metric
defs
map
[
model
.
Fingerprint
]
metric
.
Values
defs
map
[
model
.
Fingerprint
]
[]
model
.
SamplePair
}
func
newLoadCmd
(
gap
time
.
Duration
)
*
loadCmd
{
return
&
loadCmd
{
gap
:
gap
,
metrics
:
map
[
model
.
Fingerprint
]
model
.
Metric
{},
defs
:
map
[
model
.
Fingerprint
]
metric
.
Values
{},
defs
:
map
[
model
.
Fingerprint
]
[]
model
.
SamplePair
{},
}
}
...
...
@@ -258,11 +257,11 @@ func (cmd loadCmd) String() string {
func
(
cmd
*
loadCmd
)
set
(
m
model
.
Metric
,
vals
...
sequenceValue
)
{
fp
:=
m
.
Fingerprint
()
samples
:=
make
(
metric
.
Values
,
0
,
len
(
vals
))
samples
:=
make
(
[]
model
.
SamplePair
,
0
,
len
(
vals
))
ts
:=
testStartTime
for
_
,
v
:=
range
vals
{
if
!
v
.
omitted
{
samples
=
append
(
samples
,
m
etric
.
SamplePair
{
samples
=
append
(
samples
,
m
odel
.
SamplePair
{
Timestamp
:
ts
,
Value
:
v
.
value
,
})
...
...
storage/local/chunk.go
浏览文件 @
1535ef14
...
...
@@ -78,7 +78,7 @@ func newChunkDesc(c chunk) *chunkDesc {
return
&
chunkDesc
{
c
:
c
,
rCnt
:
1
}
}
func
(
cd
*
chunkDesc
)
add
(
s
*
m
etric
.
SamplePair
)
[]
chunk
{
func
(
cd
*
chunkDesc
)
add
(
s
*
m
odel
.
SamplePair
)
[]
chunk
{
cd
.
Lock
()
defer
cd
.
Unlock
()
...
...
@@ -143,7 +143,7 @@ func (cd *chunkDesc) lastTime() model.Time {
return
cd
.
c
.
newIterator
()
.
lastTimestamp
()
}
func
(
cd
*
chunkDesc
)
lastSamplePair
()
*
m
etric
.
SamplePair
{
func
(
cd
*
chunkDesc
)
lastSamplePair
()
*
m
odel
.
SamplePair
{
cd
.
Lock
()
defer
cd
.
Unlock
()
...
...
@@ -151,7 +151,7 @@ func (cd *chunkDesc) lastSamplePair() *metric.SamplePair {
return
nil
}
it
:=
cd
.
c
.
newIterator
()
return
&
m
etric
.
SamplePair
{
return
&
m
odel
.
SamplePair
{
Timestamp
:
it
.
lastTimestamp
(),
Value
:
it
.
lastSampleValue
(),
}
...
...
@@ -215,7 +215,7 @@ type chunk interface {
// any. The first chunk returned might be the same as the original one
// or a newly allocated version. In any case, take the returned chunk as
// the relevant one and discard the orginal chunk.
add
(
sample
*
m
etric
.
SamplePair
)
[]
chunk
add
(
sample
*
m
odel
.
SamplePair
)
[]
chunk
clone
()
chunk
firstTime
()
model
.
Time
newIterator
()
chunkIterator
...
...
@@ -244,9 +244,9 @@ type chunkIterator interface {
// value is returned. Only the first or last value is returned (as a
// single value), if the given time is before or after the first or last
// value, respectively.
valueAtTime
(
model
.
Time
)
metric
.
Values
valueAtTime
(
model
.
Time
)
[]
model
.
SamplePair
// Gets all values contained within a given interval.
rangeValues
(
metric
.
Interval
)
metric
.
Values
rangeValues
(
metric
.
Interval
)
[]
model
.
SamplePair
// Whether a given timestamp is contained between first and last value
// in the chunk.
contains
(
model
.
Time
)
bool
...
...
@@ -254,10 +254,10 @@ type chunkIterator interface {
// can be received in order. The channel is closed after the last
// one. It is generally not safe to mutate the chunk while the channel
// is still open.
values
()
<-
chan
*
m
etric
.
SamplePair
values
()
<-
chan
*
m
odel
.
SamplePair
}
func
transcodeAndAdd
(
dst
chunk
,
src
chunk
,
s
*
m
etric
.
SamplePair
)
[]
chunk
{
func
transcodeAndAdd
(
dst
chunk
,
src
chunk
,
s
*
m
odel
.
SamplePair
)
[]
chunk
{
chunkOps
.
WithLabelValues
(
transcode
)
.
Inc
()
head
:=
dst
...
...
storage/local/delta.go
浏览文件 @
1535ef14
...
...
@@ -76,7 +76,7 @@ func newDeltaEncodedChunk(tb, vb deltaBytes, isInt bool, length int) *deltaEncod
}
// add implements chunk.
func
(
c
deltaEncodedChunk
)
add
(
s
*
m
etric
.
SamplePair
)
[]
chunk
{
func
(
c
deltaEncodedChunk
)
add
(
s
*
m
odel
.
SamplePair
)
[]
chunk
{
if
c
.
len
()
==
0
{
c
=
c
[
:
deltaHeaderBytes
]
binary
.
LittleEndian
.
PutUint64
(
c
[
deltaHeaderBaseTimeOffset
:
],
uint64
(
s
.
Timestamp
))
...
...
@@ -288,36 +288,36 @@ type deltaEncodedChunkIterator struct {
func
(
it
*
deltaEncodedChunkIterator
)
length
()
int
{
return
it
.
len
}
// valueAtTime implements chunkIterator.
func
(
it
*
deltaEncodedChunkIterator
)
valueAtTime
(
t
model
.
Time
)
metric
.
Values
{
func
(
it
*
deltaEncodedChunkIterator
)
valueAtTime
(
t
model
.
Time
)
[]
model
.
SamplePair
{
i
:=
sort
.
Search
(
it
.
len
,
func
(
i
int
)
bool
{
return
!
it
.
timestampAtIndex
(
i
)
.
Before
(
t
)
})
switch
i
{
case
0
:
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
0
),
Value
:
it
.
sampleValueAtIndex
(
0
),
}}
case
it
.
len
:
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
it
.
len
-
1
),
Value
:
it
.
sampleValueAtIndex
(
it
.
len
-
1
),
}}
default
:
ts
:=
it
.
timestampAtIndex
(
i
)
if
ts
.
Equal
(
t
)
{
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
sampleValueAtIndex
(
i
),
}}
}
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
i
-
1
),
Value
:
it
.
sampleValueAtIndex
(
i
-
1
),
},
metric
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
sampleValueAtIndex
(
i
),
},
...
...
@@ -326,7 +326,7 @@ func (it *deltaEncodedChunkIterator) valueAtTime(t model.Time) metric.Values {
}
// rangeValues implements chunkIterator.
func
(
it
*
deltaEncodedChunkIterator
)
rangeValues
(
in
metric
.
Interval
)
metric
.
Values
{
func
(
it
*
deltaEncodedChunkIterator
)
rangeValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
oldest
:=
sort
.
Search
(
it
.
len
,
func
(
i
int
)
bool
{
return
!
it
.
timestampAtIndex
(
i
)
.
Before
(
in
.
OldestInclusive
)
})
...
...
@@ -339,9 +339,9 @@ func (it *deltaEncodedChunkIterator) rangeValues(in metric.Interval) metric.Valu
return
nil
}
result
:=
make
(
metric
.
Values
,
0
,
newest
-
oldest
)
result
:=
make
(
[]
model
.
SamplePair
,
0
,
newest
-
oldest
)
for
i
:=
oldest
;
i
<
newest
;
i
++
{
result
=
append
(
result
,
m
etric
.
SamplePair
{
result
=
append
(
result
,
m
odel
.
SamplePair
{
Timestamp
:
it
.
timestampAtIndex
(
i
),
Value
:
it
.
sampleValueAtIndex
(
i
),
})
...
...
@@ -355,11 +355,11 @@ func (it *deltaEncodedChunkIterator) contains(t model.Time) bool {
}
// values implements chunkIterator.
func
(
it
*
deltaEncodedChunkIterator
)
values
()
<-
chan
*
m
etric
.
SamplePair
{
valuesChan
:=
make
(
chan
*
m
etric
.
SamplePair
)
func
(
it
*
deltaEncodedChunkIterator
)
values
()
<-
chan
*
m
odel
.
SamplePair
{
valuesChan
:=
make
(
chan
*
m
odel
.
SamplePair
)
go
func
()
{
for
i
:=
0
;
i
<
it
.
len
;
i
++
{
valuesChan
<-
&
m
etric
.
SamplePair
{
valuesChan
<-
&
m
odel
.
SamplePair
{
Timestamp
:
it
.
timestampAtIndex
(
i
),
Value
:
it
.
sampleValueAtIndex
(
i
),
}
...
...
storage/local/doubledelta.go
浏览文件 @
1535ef14
...
...
@@ -83,7 +83,7 @@ func newDoubleDeltaEncodedChunk(tb, vb deltaBytes, isInt bool, length int) *doub
}
// add implements chunk.
func
(
c
doubleDeltaEncodedChunk
)
add
(
s
*
m
etric
.
SamplePair
)
[]
chunk
{
func
(
c
doubleDeltaEncodedChunk
)
add
(
s
*
m
odel
.
SamplePair
)
[]
chunk
{
if
c
.
len
()
==
0
{
return
c
.
addFirstSample
(
s
)
}
...
...
@@ -321,7 +321,7 @@ func (c doubleDeltaEncodedChunk) isInt() bool {
// addFirstSample is a helper method only used by c.add(). It adds timestamp and
// value as base time and value.
func
(
c
doubleDeltaEncodedChunk
)
addFirstSample
(
s
*
m
etric
.
SamplePair
)
[]
chunk
{
func
(
c
doubleDeltaEncodedChunk
)
addFirstSample
(
s
*
m
odel
.
SamplePair
)
[]
chunk
{
c
=
c
[
:
doubleDeltaHeaderBaseValueOffset
+
8
]
binary
.
LittleEndian
.
PutUint64
(
c
[
doubleDeltaHeaderBaseTimeOffset
:
],
...
...
@@ -336,7 +336,7 @@ func (c doubleDeltaEncodedChunk) addFirstSample(s *metric.SamplePair) []chunk {
// addSecondSample is a helper method only used by c.add(). It calculates the
// base delta from the provided sample and adds it to the chunk.
func
(
c
doubleDeltaEncodedChunk
)
addSecondSample
(
s
*
m
etric
.
SamplePair
,
tb
,
vb
deltaBytes
)
[]
chunk
{
func
(
c
doubleDeltaEncodedChunk
)
addSecondSample
(
s
*
m
odel
.
SamplePair
,
tb
,
vb
deltaBytes
)
[]
chunk
{
baseTimeDelta
:=
s
.
Timestamp
-
c
.
baseTime
()
if
baseTimeDelta
<
0
{
panic
(
"base time delta is less than zero"
)
...
...
@@ -394,36 +394,36 @@ type doubleDeltaEncodedChunkIterator struct {
func
(
it
*
doubleDeltaEncodedChunkIterator
)
length
()
int
{
return
it
.
len
}
// valueAtTime implements chunkIterator.
func
(
it
*
doubleDeltaEncodedChunkIterator
)
valueAtTime
(
t
model
.
Time
)
metric
.
Values
{
func
(
it
*
doubleDeltaEncodedChunkIterator
)
valueAtTime
(
t
model
.
Time
)
[]
model
.
SamplePair
{
i
:=
sort
.
Search
(
it
.
len
,
func
(
i
int
)
bool
{
return
!
it
.
timestampAtIndex
(
i
)
.
Before
(
t
)
})
switch
i
{
case
0
:
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
0
),
Value
:
it
.
sampleValueAtIndex
(
0
),
}}
case
it
.
len
:
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
it
.
len
-
1
),
Value
:
it
.
sampleValueAtIndex
(
it
.
len
-
1
),
}}
default
:
ts
:=
it
.
timestampAtIndex
(
i
)
if
ts
.
Equal
(
t
)
{
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
sampleValueAtIndex
(
i
),
}}
}
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
it
.
timestampAtIndex
(
i
-
1
),
Value
:
it
.
sampleValueAtIndex
(
i
-
1
),
},
metric
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
sampleValueAtIndex
(
i
),
},
...
...
@@ -432,7 +432,7 @@ func (it *doubleDeltaEncodedChunkIterator) valueAtTime(t model.Time) metric.Valu
}
// rangeValues implements chunkIterator.
func
(
it
*
doubleDeltaEncodedChunkIterator
)
rangeValues
(
in
metric
.
Interval
)
metric
.
Values
{
func
(
it
*
doubleDeltaEncodedChunkIterator
)
rangeValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
oldest
:=
sort
.
Search
(
it
.
len
,
func
(
i
int
)
bool
{
return
!
it
.
timestampAtIndex
(
i
)
.
Before
(
in
.
OldestInclusive
)
})
...
...
@@ -445,9 +445,9 @@ func (it *doubleDeltaEncodedChunkIterator) rangeValues(in metric.Interval) metri
return
nil
}
result
:=
make
(
metric
.
Values
,
0
,
newest
-
oldest
)
result
:=
make
(
[]
model
.
SamplePair
,
0
,
newest
-
oldest
)
for
i
:=
oldest
;
i
<
newest
;
i
++
{
result
=
append
(
result
,
m
etric
.
SamplePair
{
result
=
append
(
result
,
m
odel
.
SamplePair
{
Timestamp
:
it
.
timestampAtIndex
(
i
),
Value
:
it
.
sampleValueAtIndex
(
i
),
})
...
...
@@ -461,11 +461,11 @@ func (it *doubleDeltaEncodedChunkIterator) contains(t model.Time) bool {
}
// values implements chunkIterator.
func
(
it
*
doubleDeltaEncodedChunkIterator
)
values
()
<-
chan
*
m
etric
.
SamplePair
{
valuesChan
:=
make
(
chan
*
m
etric
.
SamplePair
)
func
(
it
*
doubleDeltaEncodedChunkIterator
)
values
()
<-
chan
*
m
odel
.
SamplePair
{
valuesChan
:=
make
(
chan
*
m
odel
.
SamplePair
)
go
func
()
{
for
i
:=
0
;
i
<
it
.
len
;
i
++
{
valuesChan
<-
&
m
etric
.
SamplePair
{
valuesChan
<-
&
m
odel
.
SamplePair
{
Timestamp
:
it
.
timestampAtIndex
(
i
),
Value
:
it
.
sampleValueAtIndex
(
i
),
}
...
...
storage/local/interface.go
浏览文件 @
1535ef14
...
...
@@ -44,7 +44,7 @@ type Storage interface {
// LastSamplePairForFingerprint returns the last sample pair for the
// provided fingerprint. If the respective time series does not exist or
// has an evicted head chunk, nil is returned.
LastSamplePairForFingerprint
(
model
.
Fingerprint
)
*
m
etric
.
SamplePair
LastSamplePairForFingerprint
(
model
.
Fingerprint
)
*
m
odel
.
SamplePair
// Get all of the label values that are associated with a given label name.
LabelValuesForLabelName
(
model
.
LabelName
)
model
.
LabelValues
// Get the metric associated with the provided fingerprint.
...
...
@@ -80,12 +80,12 @@ type SeriesIterator interface {
// value is returned. Only the first or last value is returned (as a
// single value), if the given time is before or after the first or last
// value, respectively.
ValueAtTime
(
model
.
Time
)
metric
.
Values
ValueAtTime
(
model
.
Time
)
[]
model
.
SamplePair
// Gets the boundary values of an interval: the first and last value
// within a given interval.
BoundaryValues
(
metric
.
Interval
)
metric
.
Values
BoundaryValues
(
metric
.
Interval
)
[]
model
.
SamplePair
// Gets all values contained within a given interval.
RangeValues
(
metric
.
Interval
)
metric
.
Values
RangeValues
(
metric
.
Interval
)
[]
model
.
SamplePair
}
// A Preloader preloads series data necessary for a query into memory and pins
...
...
storage/local/persistence_test.go
浏览文件 @
1535ef14
...
...
@@ -23,7 +23,6 @@ import (
"github.com/prometheus/prometheus/storage/local/codable"
"github.com/prometheus/prometheus/storage/local/index"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/testutil"
)
...
...
@@ -61,7 +60,7 @@ func buildTestChunks(encoding chunkEncoding) map[model.Fingerprint][]chunk {
for
_
,
fp
:=
range
fps
{
fpToChunks
[
fp
]
=
make
([]
chunk
,
0
,
10
)
for
i
:=
0
;
i
<
10
;
i
++
{
fpToChunks
[
fp
]
=
append
(
fpToChunks
[
fp
],
newChunkForEncoding
(
encoding
)
.
add
(
&
m
etric
.
SamplePair
{
fpToChunks
[
fp
]
=
append
(
fpToChunks
[
fp
],
newChunkForEncoding
(
encoding
)
.
add
(
&
m
odel
.
SamplePair
{
Timestamp
:
model
.
Time
(
i
),
Value
:
model
.
SampleValue
(
fp
),
})[
0
])
...
...
@@ -360,16 +359,16 @@ func testCheckpointAndLoadSeriesMapAndHeads(t *testing.T, encoding chunkEncoding
s3
:=
newMemorySeries
(
m3
,
nil
,
time
.
Time
{})
s4
:=
newMemorySeries
(
m4
,
nil
,
time
.
Time
{})
s5
:=
newMemorySeries
(
m5
,
nil
,
time
.
Time
{})
s1
.
add
(
&
m
etric
.
SamplePair
{
Timestamp
:
1
,
Value
:
3.14
})
s3
.
add
(
&
m
etric
.
SamplePair
{
Timestamp
:
2
,
Value
:
2.7
})
s1
.
add
(
&
m
odel
.
SamplePair
{
Timestamp
:
1
,
Value
:
3.14
})
s3
.
add
(
&
m
odel
.
SamplePair
{
Timestamp
:
2
,
Value
:
2.7
})
s3
.
headChunkClosed
=
true
s3
.
persistWatermark
=
1
for
i
:=
0
;
i
<
10000
;
i
++
{
s4
.
add
(
&
m
etric
.
SamplePair
{
s4
.
add
(
&
m
odel
.
SamplePair
{
Timestamp
:
model
.
Time
(
i
),
Value
:
model
.
SampleValue
(
i
)
/
2
,
})
s5
.
add
(
&
m
etric
.
SamplePair
{
s5
.
add
(
&
m
odel
.
SamplePair
{
Timestamp
:
model
.
Time
(
i
),
Value
:
model
.
SampleValue
(
i
*
i
),
})
...
...
storage/local/series.go
浏览文件 @
1535ef14
...
...
@@ -207,7 +207,7 @@ func newMemorySeries(m model.Metric, chunkDescs []*chunkDesc, modTime time.Time)
// completed chunks (which are now eligible for persistence).
//
// The caller must have locked the fingerprint of the series.
func
(
s
*
memorySeries
)
add
(
v
*
m
etric
.
SamplePair
)
int
{
func
(
s
*
memorySeries
)
add
(
v
*
m
odel
.
SamplePair
)
int
{
if
len
(
s
.
chunkDescs
)
==
0
||
s
.
headChunkClosed
{
newHead
:=
newChunkDesc
(
newChunk
())
s
.
chunkDescs
=
append
(
s
.
chunkDescs
,
newHead
)
...
...
@@ -482,7 +482,7 @@ type memorySeriesIterator struct {
}
// ValueAtTime implements SeriesIterator.
func
(
it
*
memorySeriesIterator
)
ValueAtTime
(
t
model
.
Time
)
metric
.
Values
{
func
(
it
*
memorySeriesIterator
)
ValueAtTime
(
t
model
.
Time
)
[]
model
.
SamplePair
{
// The most common case. We are iterating through a chunk.
if
it
.
chunkIt
!=
nil
&&
it
.
chunkIt
.
contains
(
t
)
{
return
it
.
chunkIt
.
valueAtTime
(
t
)
...
...
@@ -497,7 +497,7 @@ func (it *memorySeriesIterator) ValueAtTime(t model.Time) metric.Values {
ts
:=
it
.
chunkIt
.
timestampAtIndex
(
0
)
if
!
t
.
After
(
ts
)
{
// return first value of first chunk
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
chunkIt
.
sampleValueAtIndex
(
0
),
}}
...
...
@@ -508,7 +508,7 @@ func (it *memorySeriesIterator) ValueAtTime(t model.Time) metric.Values {
ts
=
it
.
chunkIt
.
lastTimestamp
()
if
!
t
.
Before
(
ts
)
{
// return last value of last chunk
return
metric
.
Values
{
metric
.
SamplePair
{
return
[]
model
.
SamplePair
{
{
Timestamp
:
ts
,
Value
:
it
.
chunkIt
.
sampleValueAtIndex
(
it
.
chunkIt
.
length
()
-
1
),
}}
...
...
@@ -526,14 +526,14 @@ func (it *memorySeriesIterator) ValueAtTime(t model.Time) metric.Values {
ts
=
it
.
chunkIt
.
lastTimestamp
()
if
t
.
After
(
ts
)
{
// We ended up between two chunks.
sp1
:=
m
etric
.
SamplePair
{
sp1
:=
m
odel
.
SamplePair
{
Timestamp
:
ts
,
Value
:
it
.
chunkIt
.
sampleValueAtIndex
(
it
.
chunkIt
.
length
()
-
1
),
}
it
.
chunkIt
=
it
.
chunkIterator
(
l
-
i
+
1
)
return
metric
.
Values
{
return
[]
model
.
SamplePair
{
sp1
,
m
etric
.
SamplePair
{
m
odel
.
SamplePair
{
Timestamp
:
it
.
chunkIt
.
timestampAtIndex
(
0
),
Value
:
it
.
chunkIt
.
sampleValueAtIndex
(
0
),
},
...
...
@@ -543,7 +543,7 @@ func (it *memorySeriesIterator) ValueAtTime(t model.Time) metric.Values {
}
// BoundaryValues implements SeriesIterator.
func
(
it
*
memorySeriesIterator
)
BoundaryValues
(
in
metric
.
Interval
)
metric
.
Values
{
func
(
it
*
memorySeriesIterator
)
BoundaryValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
// Find the first chunk for which the first sample is within the interval.
i
:=
sort
.
Search
(
len
(
it
.
chunks
),
func
(
i
int
)
bool
{
return
!
it
.
chunks
[
i
]
.
firstTime
()
.
Before
(
in
.
OldestInclusive
)
...
...
@@ -554,7 +554,7 @@ func (it *memorySeriesIterator) BoundaryValues(in metric.Interval) metric.Values
i
--
}
values
:=
make
(
metric
.
Values
,
0
,
2
)
values
:=
make
(
[]
model
.
SamplePair
,
0
,
2
)
for
j
,
c
:=
range
it
.
chunks
[
i
:
]
{
if
c
.
firstTime
()
.
After
(
in
.
NewestInclusive
)
{
if
len
(
values
)
==
1
{
...
...
@@ -563,7 +563,7 @@ func (it *memorySeriesIterator) BoundaryValues(in metric.Interval) metric.Values
// want must be the last value of the previous
// chunk. So backtrack...
chunkIt
:=
it
.
chunkIterator
(
i
+
j
-
1
)
values
=
append
(
values
,
m
etric
.
SamplePair
{
values
=
append
(
values
,
m
odel
.
SamplePair
{
Timestamp
:
chunkIt
.
lastTimestamp
(),
Value
:
chunkIt
.
lastSampleValue
(),
})
...
...
@@ -590,7 +590,7 @@ func (it *memorySeriesIterator) BoundaryValues(in metric.Interval) metric.Values
if
len
(
values
)
==
1
{
// We found exactly one value. In that case, add the most recent we know.
chunkIt
:=
it
.
chunkIterator
(
len
(
it
.
chunks
)
-
1
)
values
=
append
(
values
,
m
etric
.
SamplePair
{
values
=
append
(
values
,
m
odel
.
SamplePair
{
Timestamp
:
chunkIt
.
lastTimestamp
(),
Value
:
chunkIt
.
lastSampleValue
(),
})
...
...
@@ -602,7 +602,7 @@ func (it *memorySeriesIterator) BoundaryValues(in metric.Interval) metric.Values
}
// RangeValues implements SeriesIterator.
func
(
it
*
memorySeriesIterator
)
RangeValues
(
in
metric
.
Interval
)
metric
.
Values
{
func
(
it
*
memorySeriesIterator
)
RangeValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
// Find the first chunk for which the first sample is within the interval.
i
:=
sort
.
Search
(
len
(
it
.
chunks
),
func
(
i
int
)
bool
{
return
!
it
.
chunks
[
i
]
.
firstTime
()
.
Before
(
in
.
OldestInclusive
)
...
...
@@ -613,7 +613,7 @@ func (it *memorySeriesIterator) RangeValues(in metric.Interval) metric.Values {
i
--
}
values
:=
metric
.
Values
{}
values
:=
[]
model
.
SamplePair
{}
for
j
,
c
:=
range
it
.
chunks
[
i
:
]
{
if
c
.
firstTime
()
.
After
(
in
.
NewestInclusive
)
{
break
...
...
@@ -638,16 +638,16 @@ func (it *memorySeriesIterator) chunkIterator(i int) chunkIterator {
type
nopSeriesIterator
struct
{}
// ValueAtTime implements SeriesIterator.
func
(
_
nopSeriesIterator
)
ValueAtTime
(
t
model
.
Time
)
metric
.
Values
{
return
metric
.
Values
{}
func
(
_
nopSeriesIterator
)
ValueAtTime
(
t
model
.
Time
)
[]
model
.
SamplePair
{
return
[]
model
.
SamplePair
{}
}
// BoundaryValues implements SeriesIterator.
func
(
_
nopSeriesIterator
)
BoundaryValues
(
in
metric
.
Interval
)
metric
.
Values
{
return
metric
.
Values
{}
func
(
_
nopSeriesIterator
)
BoundaryValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
return
[]
model
.
SamplePair
{}
}
// RangeValues implements SeriesIterator.
func
(
_
nopSeriesIterator
)
RangeValues
(
in
metric
.
Interval
)
metric
.
Values
{
return
metric
.
Values
{}
func
(
_
nopSeriesIterator
)
RangeValues
(
in
metric
.
Interval
)
[]
model
.
SamplePair
{
return
[]
model
.
SamplePair
{}
}
storage/local/storage.go
浏览文件 @
1535ef14
...
...
@@ -328,7 +328,7 @@ func (s *memorySeriesStorage) NewIterator(fp model.Fingerprint) SeriesIterator {
}
// LastSampleForFingerprint implements Storage.
func
(
s
*
memorySeriesStorage
)
LastSamplePairForFingerprint
(
fp
model
.
Fingerprint
)
*
m
etric
.
SamplePair
{
func
(
s
*
memorySeriesStorage
)
LastSamplePairForFingerprint
(
fp
model
.
Fingerprint
)
*
m
odel
.
SamplePair
{
s
.
fpLocker
.
Lock
(
fp
)
defer
s
.
fpLocker
.
Unlock
(
fp
)
...
...
@@ -347,17 +347,17 @@ type boundedIterator struct {
}
// ValueAtTime implements the SeriesIterator interface.
func
(
bit
*
boundedIterator
)
ValueAtTime
(
ts
model
.
Time
)
metric
.
Values
{
func
(
bit
*
boundedIterator
)
ValueAtTime
(
ts
model
.
Time
)
[]
model
.
SamplePair
{
if
ts
<
bit
.
start
{
return
metric
.
Values
{}
return
[]
model
.
SamplePair
{}
}
return
bit
.
it
.
ValueAtTime
(
ts
)
}
// BoundaryValues implements the SeriesIterator interface.
func
(
bit
*
boundedIterator
)
BoundaryValues
(
interval
metric
.
Interval
)
metric
.
Values
{
func
(
bit
*
boundedIterator
)
BoundaryValues
(
interval
metric
.
Interval
)
[]
model
.
SamplePair
{
if
interval
.
NewestInclusive
<
bit
.
start
{
return
metric
.
Values
{}
return
[]
model
.
SamplePair
{}
}
if
interval
.
OldestInclusive
<
bit
.
start
{
interval
.
OldestInclusive
=
bit
.
start
...
...
@@ -366,9 +366,9 @@ func (bit *boundedIterator) BoundaryValues(interval metric.Interval) metric.Valu
}
// RangeValues implements the SeriesIterator interface.
func
(
bit
*
boundedIterator
)
RangeValues
(
interval
metric
.
Interval
)
metric
.
Values
{
func
(
bit
*
boundedIterator
)
RangeValues
(
interval
metric
.
Interval
)
[]
model
.
SamplePair
{
if
interval
.
NewestInclusive
<
bit
.
start
{
return
metric
.
Values
{}
return
[]
model
.
SamplePair
{}
}
if
interval
.
OldestInclusive
<
bit
.
start
{
interval
.
OldestInclusive
=
bit
.
start
...
...
@@ -570,7 +570,7 @@ func (s *memorySeriesStorage) Append(sample *model.Sample) {
s
.
fpLocker
.
Unlock
(
fp
)
return
}
completedChunksCount
:=
series
.
add
(
&
m
etric
.
SamplePair
{
completedChunksCount
:=
series
.
add
(
&
m
odel
.
SamplePair
{
Value
:
sample
.
Value
,
Timestamp
:
sample
.
Timestamp
,
})
...
...
storage/local/storage_test.go
浏览文件 @
1535ef14
...
...
@@ -571,7 +571,7 @@ func testChunk(t *testing.T, encoding chunkEncoding) {
for
m
:=
range
s
.
fpToSeries
.
iter
()
{
s
.
fpLocker
.
Lock
(
m
.
fp
)
var
values
metric
.
Values
var
values
[]
model
.
SamplePair
for
_
,
cd
:=
range
m
.
series
.
chunkDescs
{
if
cd
.
isEvicted
()
{
continue
...
...
@@ -1527,7 +1527,7 @@ func TestAppendOutOfOrder(t *testing.T) {
it
:=
s
.
NewIterator
(
fp
)
want
:=
metric
.
Values
{
want
:=
[]
model
.
SamplePair
{
{
Timestamp
:
0
,
Value
:
0
,
...
...
storage/metric/sample.go
浏览文件 @
1535ef14
...
...
@@ -13,40 +13,7 @@
package
metric
import
(
"fmt"
"strconv"
"github.com/prometheus/common/model"
)
// MarshalJSON implements json.Marshaler.
func
(
s
SamplePair
)
MarshalJSON
()
([]
byte
,
error
)
{
return
[]
byte
(
fmt
.
Sprintf
(
"[%s,
\"
%s
\"
]"
,
s
.
Timestamp
.
String
(),
strconv
.
FormatFloat
(
float64
(
s
.
Value
),
'f'
,
-
1
,
64
))),
nil
}
// SamplePair pairs a SampleValue with a Timestamp.
type
SamplePair
struct
{
Timestamp
model
.
Time
Value
model
.
SampleValue
}
// Equal returns true if this SamplePair and o have equal Values and equal
// Timestamps.
func
(
s
*
SamplePair
)
Equal
(
o
*
SamplePair
)
bool
{
if
s
==
o
{
return
true
}
return
s
.
Value
.
Equal
(
o
.
Value
)
&&
s
.
Timestamp
.
Equal
(
o
.
Timestamp
)
}
func
(
s
*
SamplePair
)
String
()
string
{
return
fmt
.
Sprintf
(
"SamplePair at %s of %s"
,
s
.
Timestamp
,
s
.
Value
)
}
// Values is a slice of SamplePairs.
type
Values
[]
SamplePair
import
"github.com/prometheus/common/model"
// Interval describes the inclusive interval between two Timestamps.
type
Interval
struct
{
...
...
web/api/v1/api_test.go
浏览文件 @
1535ef14
...
...
@@ -16,7 +16,6 @@ import (
"golang.org/x/net/context"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/route"
)
...
...
@@ -103,7 +102,7 @@ func TestEndpoints(t *testing.T) {
ResultType
:
promql
.
ExprMatrix
,
Result
:
promql
.
Matrix
{
&
promql
.
SampleStream
{
Values
:
metric
.
Values
{
Values
:
[]
model
.
SamplePair
{
{
Value
:
0
,
Timestamp
:
start
},
{
Value
:
1
,
Timestamp
:
start
.
Add
(
1
*
time
.
Second
)},
{
Value
:
2
,
Timestamp
:
start
.
Add
(
2
*
time
.
Second
)},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录