Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
28629380
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,发现更多精彩内容 >>
提交
28629380
编写于
12月 28, 2016
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add merge postings
上级
ab7fbc05
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
145 addition
and
17 deletion
+145
-17
labels/selector.go
labels/selector.go
+5
-7
postings.go
postings.go
+54
-7
postings_test.go
postings_test.go
+65
-1
querier.go
querier.go
+2
-2
test/conv_test.go
test/conv_test.go
+19
-0
未找到文件。
labels/selector.go
浏览文件 @
28629380
...
...
@@ -24,15 +24,15 @@ type Matcher interface {
}
type
EqualMatcher
struct
{
LabelName
,
V
alue
string
name
,
v
alue
string
}
func
(
m
*
EqualMatcher
)
Name
()
string
{
return
m
.
LabelN
ame
}
func
(
m
*
EqualMatcher
)
Matches
(
v
string
)
bool
{
return
v
==
m
.
V
alue
}
func
(
m
*
EqualMatcher
)
Name
()
string
{
return
m
.
n
ame
}
func
(
m
*
EqualMatcher
)
Matches
(
v
string
)
bool
{
return
v
==
m
.
v
alue
}
// NewEqualMatcher returns a new matcher matching an exact label value.
func
NewEqualMatcher
(
name
,
value
string
)
Matcher
{
return
&
EqualMatcher
{
LabelName
:
name
,
V
alue
:
value
}
return
&
EqualMatcher
{
name
:
name
,
v
alue
:
value
}
}
type
regexpMatcher
struct
{
...
...
@@ -58,9 +58,7 @@ type notMatcher struct {
Matcher
}
func
(
m
*
notMatcher
)
Matches
(
v
string
)
bool
{
return
!
m
.
Matcher
.
Matches
(
v
)
}
func
(
m
*
notMatcher
)
Matches
(
v
string
)
bool
{
return
!
m
.
Matcher
.
Matches
(
v
)
}
// Not inverts the matcher's matching result.
func
Not
(
m
Matcher
)
Matcher
{
...
...
postings.go
浏览文件 @
28629380
...
...
@@ -73,9 +73,10 @@ func Intersect(its ...Postings) Postings {
return
a
}
var
emptyPostings
=
errPostings
{}
type
intersectPostings
struct
{
a
,
b
Postings
av
,
bc
uint32
aok
,
bok
bool
cur
uint32
}
...
...
@@ -133,29 +134,75 @@ func Merge(its ...Postings) Postings {
a
:=
its
[
0
]
for
_
,
b
:=
range
its
[
1
:
]
{
a
=
&
mergePostings
{
a
:
a
,
b
:
b
}
a
=
newMergePostings
(
a
,
b
)
}
return
a
}
type
mergePostings
struct
{
a
,
b
Postings
a
,
b
Postings
aok
,
bok
bool
cur
uint32
}
func
newMergePostings
(
a
,
b
Postings
)
*
mergePostings
{
it
:=
&
mergePostings
{
a
:
a
,
b
:
b
}
it
.
aok
=
it
.
a
.
Next
()
it
.
bok
=
it
.
b
.
Next
()
return
it
}
func
(
it
*
mergePostings
)
Value
()
uint32
{
return
0
return
it
.
cur
}
func
(
it
*
mergePostings
)
Next
()
bool
{
return
false
if
!
it
.
aok
&&
!
it
.
bok
{
return
false
}
if
!
it
.
aok
{
it
.
cur
=
it
.
b
.
Value
()
it
.
bok
=
it
.
b
.
Next
()
return
true
}
if
!
it
.
bok
{
it
.
cur
=
it
.
a
.
Value
()
it
.
aok
=
it
.
a
.
Next
()
return
true
}
acur
,
bcur
:=
it
.
a
.
Value
(),
it
.
b
.
Value
()
if
acur
<
bcur
{
it
.
cur
=
acur
it
.
aok
=
it
.
a
.
Next
()
return
true
}
if
bcur
<
acur
{
it
.
cur
=
bcur
it
.
bok
=
it
.
b
.
Next
()
return
true
}
it
.
cur
=
acur
it
.
aok
=
it
.
a
.
Next
()
it
.
bok
=
it
.
b
.
Next
()
return
true
}
func
(
it
*
mergePostings
)
Seek
(
id
uint32
)
bool
{
return
false
it
.
aok
=
it
.
a
.
Seek
(
id
)
it
.
bok
=
it
.
b
.
Seek
(
id
)
return
it
.
Next
()
}
func
(
it
*
mergePostings
)
Err
()
error
{
return
nil
if
it
.
a
.
Err
()
!=
nil
{
return
it
.
a
.
Err
()
}
return
it
.
b
.
Err
()
}
// listPostings implements the Postings interface over a plain list.
...
...
postings_test.go
浏览文件 @
28629380
...
...
@@ -17,7 +17,7 @@ func (m *mockPostings) Seek(v uint32) bool { return m.seek(v) }
func
(
m
*
mockPostings
)
Value
()
uint32
{
return
m
.
value
()
}
func
(
m
*
mockPostings
)
Err
()
error
{
return
m
.
err
()
}
func
TestIntersect
Iterator
(
t
*
testing
.
T
)
{
func
TestIntersect
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
[]
uint32
res
[]
uint32
...
...
@@ -117,3 +117,67 @@ func BenchmarkIntersect(t *testing.B) {
}
}
}
func
TestMultiMerge
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
,
c
[]
uint32
res
[]
uint32
}{
{
a
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
,
6
,
1000
,
1001
},
b
:
[]
uint32
{
2
,
4
,
5
,
6
,
7
,
8
,
999
,
1001
},
c
:
[]
uint32
{
1
,
2
,
5
,
6
,
7
,
8
,
1001
,
1200
},
res
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
999
,
1000
,
1001
,
1200
},
},
}
for
_
,
c
:=
range
cases
{
i1
:=
newListPostings
(
c
.
a
)
i2
:=
newListPostings
(
c
.
b
)
i3
:=
newListPostings
(
c
.
c
)
res
,
err
:=
expandPostings
(
Merge
(
i1
,
i2
,
i3
))
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
res
,
c
.
res
)
{
t
.
Fatalf
(
"Expected %v but got %v"
,
c
.
res
,
res
)
}
}
}
func
TestMerge
(
t
*
testing
.
T
)
{
var
cases
=
[]
struct
{
a
,
b
[]
uint32
res
[]
uint32
}{
{
a
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint32
{
6
,
7
,
8
,
9
,
10
},
res
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
},
},
{
a
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
},
b
:
[]
uint32
{
4
,
5
,
6
,
7
,
8
},
res
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
},
},
{
a
:
[]
uint32
{
1
,
2
,
3
,
4
,
9
,
10
},
b
:
[]
uint32
{
1
,
4
,
5
,
6
,
7
,
8
,
10
,
11
},
res
:
[]
uint32
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
},
},
}
for
_
,
c
:=
range
cases
{
a
:=
newListPostings
(
c
.
a
)
b
:=
newListPostings
(
c
.
b
)
res
,
err
:=
expandPostings
(
newMergePostings
(
a
,
b
))
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
res
,
c
.
res
)
{
t
.
Fatalf
(
"Expected %v but got %v"
,
c
.
res
,
res
)
}
}
}
querier.go
浏览文件 @
28629380
...
...
@@ -236,7 +236,7 @@ func (q *blockQuerier) selectSingle(m labels.Matcher) Postings {
}
if
len
(
res
)
==
0
{
return
e
rrPostings
{
err
:
nil
}
return
e
mptyPostings
}
var
rit
[]
Postings
...
...
@@ -249,7 +249,7 @@ func (q *blockQuerier) selectSingle(m labels.Matcher) Postings {
rit
=
append
(
rit
,
it
)
}
return
Intersect
(
rit
...
)
return
Merge
(
rit
...
)
}
func
(
q
*
blockQuerier
)
LabelValues
(
name
string
)
([]
string
,
error
)
{
...
...
test/conv_test.go
浏览文件 @
28629380
...
...
@@ -24,3 +24,22 @@ func BenchmarkMapConversion(b *testing.B) {
}
}
}
func
BenchmarkListIter
(
b
*
testing
.
B
)
{
var
list
[]
uint32
for
i
:=
0
;
i
<
1e4
;
i
++
{
list
=
append
(
list
,
uint32
(
i
))
}
b
.
ResetTimer
()
total
:=
uint32
(
0
)
for
j
:=
0
;
j
<
b
.
N
;
j
++
{
sum
:=
uint32
(
0
)
for
_
,
k
:=
range
list
{
sum
+=
k
}
total
+=
sum
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录