Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
d6841c52
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,发现更多精彩内容 >>
提交
d6841c52
编写于
1月 08, 2019
作者:
B
beorn7
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'release-2.6'
上级
fae49ab7
d7225ac4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
160 addition
and
0 deletion
+160
-0
promql/test.go
promql/test.go
+3
-0
promql/test_test.go
promql/test_test.go
+157
-0
未找到文件。
promql/test.go
浏览文件 @
d6841c52
...
...
@@ -654,6 +654,9 @@ func (ll *LazyLoader) appendTill(ts int64) error {
if
_
,
err
:=
app
.
Add
(
m
,
s
.
T
,
s
.
V
);
err
!=
nil
{
return
err
}
if
i
==
len
(
smpls
)
-
1
{
ll
.
loadCmd
.
defs
[
h
]
=
nil
}
}
}
return
app
.
Commit
()
...
...
promql/test_test.go
0 → 100644
浏览文件 @
d6841c52
// Copyright 2019 The Prometheus Authors
// 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
promql
import
(
"github.com/prometheus/prometheus/pkg/labels"
"math"
"testing"
"time"
"github.com/prometheus/prometheus/util/testutil"
)
func
TestLazyLoader_WithSamplesTill
(
t
*
testing
.
T
)
{
type
testCase
struct
{
ts
time
.
Time
series
[]
Series
// Each series is checked separately. Need not mention all series here.
checkOnlyError
bool
// If this is true, series is not checked.
}
cases
:=
[]
struct
{
loadString
string
// These testCases are run in sequence. So the testCase being run is dependant on the previous testCase.
testCases
[]
testCase
}{
{
loadString
:
`
load 10s
metric1 1+1x10
`
,
testCases
:
[]
testCase
{
testCase
{
ts
:
time
.
Unix
(
40
,
0
),
series
:
[]
Series
{
Series
{
Metric
:
labels
.
FromStrings
(
"__name__"
,
"metric1"
),
Points
:
[]
Point
{
{
0
,
1
},
{
10000
,
2
},
{
20000
,
3
},
{
30000
,
4
},
{
40000
,
5
},
},
},
},
},
testCase
{
ts
:
time
.
Unix
(
10
,
0
),
series
:
[]
Series
{
Series
{
Metric
:
labels
.
FromStrings
(
"__name__"
,
"metric1"
),
Points
:
[]
Point
{
{
0
,
1
},
{
10000
,
2
},
{
20000
,
3
},
{
30000
,
4
},
{
40000
,
5
},
},
},
},
},
testCase
{
ts
:
time
.
Unix
(
60
,
0
),
series
:
[]
Series
{
Series
{
Metric
:
labels
.
FromStrings
(
"__name__"
,
"metric1"
),
Points
:
[]
Point
{
{
0
,
1
},
{
10000
,
2
},
{
20000
,
3
},
{
30000
,
4
},
{
40000
,
5
},
{
50000
,
6
},
{
60000
,
7
},
},
},
},
},
},
},
{
loadString
:
`
load 10s
metric1 1+0x5
metric2 1+1x100
`
,
testCases
:
[]
testCase
{
testCase
{
// Adds all samples of metric1.
ts
:
time
.
Unix
(
70
,
0
),
series
:
[]
Series
{
Series
{
Metric
:
labels
.
FromStrings
(
"__name__"
,
"metric1"
),
Points
:
[]
Point
{
{
0
,
1
},
{
10000
,
1
},
{
20000
,
1
},
{
30000
,
1
},
{
40000
,
1
},
{
50000
,
1
},
},
},
Series
{
Metric
:
labels
.
FromStrings
(
"__name__"
,
"metric2"
),
Points
:
[]
Point
{
{
0
,
1
},
{
10000
,
2
},
{
20000
,
3
},
{
30000
,
4
},
{
40000
,
5
},
{
50000
,
6
},
{
60000
,
7
},
{
70000
,
8
},
},
},
},
},
testCase
{
// This tests fix for https://github.com/prometheus/prometheus/issues/5064.
ts
:
time
.
Unix
(
300
,
0
),
checkOnlyError
:
true
,
},
},
},
}
for
_
,
c
:=
range
cases
{
suite
,
err
:=
NewLazyLoader
(
t
,
c
.
loadString
)
testutil
.
Ok
(
t
,
err
)
defer
suite
.
Close
()
for
_
,
tc
:=
range
c
.
testCases
{
suite
.
WithSamplesTill
(
tc
.
ts
,
func
(
err
error
)
{
testutil
.
Ok
(
t
,
err
)
if
tc
.
checkOnlyError
{
return
}
// Check the series.
queryable
:=
suite
.
Queryable
()
querier
,
err
:=
queryable
.
Querier
(
suite
.
Context
(),
math
.
MinInt64
,
math
.
MaxInt64
)
testutil
.
Ok
(
t
,
err
)
for
_
,
s
:=
range
tc
.
series
{
var
matchers
[]
*
labels
.
Matcher
for
_
,
label
:=
range
s
.
Metric
{
m
,
err
:=
labels
.
NewMatcher
(
labels
.
MatchEqual
,
label
.
Name
,
label
.
Value
)
testutil
.
Ok
(
t
,
err
)
matchers
=
append
(
matchers
,
m
)
}
// Get the series for the matcher.
ss
,
err
,
_
:=
querier
.
Select
(
nil
,
matchers
...
)
testutil
.
Ok
(
t
,
err
)
testutil
.
Assert
(
t
,
ss
.
Next
(),
""
)
storageSeries
:=
ss
.
At
()
testutil
.
Assert
(
t
,
!
ss
.
Next
(),
"Expecting only 1 series"
)
// Convert `storage.Series` to `promql.Series`.
got
:=
Series
{
Metric
:
storageSeries
.
Labels
(),
}
it
:=
storageSeries
.
Iterator
()
for
it
.
Next
()
{
t
,
v
:=
it
.
At
()
got
.
Points
=
append
(
got
.
Points
,
Point
{
T
:
t
,
V
:
v
})
}
testutil
.
Ok
(
t
,
it
.
Err
())
testutil
.
Equals
(
t
,
s
,
got
)
}
})
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录