Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
5efe1d17
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,发现更多精彩内容 >>
提交
5efe1d17
编写于
12月 24, 2016
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
labels: add Compare and String methods
上级
0d0c5cfa
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
42 addition
and
74 deletion
+42
-74
labels/labels.go
labels/labels.go
+40
-0
querier.go
querier.go
+1
-21
querier_test.go
querier_test.go
+0
-52
writer.go
writer.go
+1
-1
未找到文件。
labels/labels.go
浏览文件 @
5efe1d17
package
labels
import
(
"bytes"
"sort"
"strconv"
"strings"
"github.com/cespare/xxhash"
)
...
...
@@ -21,6 +24,23 @@ func (ls Labels) Len() int { return len(ls) }
func
(
ls
Labels
)
Swap
(
i
,
j
int
)
{
ls
[
i
],
ls
[
j
]
=
ls
[
j
],
ls
[
i
]
}
func
(
ls
Labels
)
Less
(
i
,
j
int
)
bool
{
return
ls
[
i
]
.
Name
<
ls
[
j
]
.
Name
}
func
(
ls
Labels
)
String
()
string
{
var
b
bytes
.
Buffer
b
.
WriteByte
(
'{'
)
for
i
,
l
:=
range
ls
{
if
i
>
0
{
b
.
WriteByte
(
','
)
}
b
.
WriteString
(
l
.
Name
)
b
.
WriteByte
(
'='
)
b
.
WriteString
(
strconv
.
Quote
(
l
.
Value
))
}
b
.
WriteByte
(
'}'
)
return
b
.
String
()
}
// Hash returns a hash value for the label set.
func
(
ls
Labels
)
Hash
()
uint64
{
b
:=
make
([]
byte
,
0
,
1024
)
...
...
@@ -101,3 +121,23 @@ func FromStrings(ss ...string) Labels {
sort
.
Sort
(
res
)
return
res
}
// Compare compares the two label sets.
// The result will be 0 if a==b, <0 if a < b, and >0 if a > b.
func
Compare
(
a
,
b
Labels
)
int
{
l
:=
len
(
a
)
if
len
(
b
)
<
l
{
l
=
len
(
b
)
}
for
i
:=
0
;
i
<
l
;
i
++
{
if
d
:=
strings
.
Compare
(
a
[
i
]
.
Name
,
b
[
i
]
.
Name
);
d
!=
0
{
return
d
}
if
d
:=
strings
.
Compare
(
a
[
i
]
.
Value
,
b
[
i
]
.
Value
);
d
!=
0
{
return
d
}
}
// If all labels so far were in common, the set with fewer labels comes first.
return
len
(
a
)
-
len
(
b
)
}
querier.go
浏览文件 @
5efe1d17
...
...
@@ -340,26 +340,6 @@ func newShardSeriesSet(a, b SeriesSet) *shardSeriesSet {
return
s
}
// compareLabels compares the two label sets.
// The result will be 0 if a==b, <0 if a < b, and >0 if a > b.
func
compareLabels
(
a
,
b
labels
.
Labels
)
int
{
l
:=
len
(
a
)
if
len
(
b
)
<
l
{
l
=
len
(
b
)
}
for
i
:=
0
;
i
<
l
;
i
++
{
if
d
:=
strings
.
Compare
(
a
[
i
]
.
Name
,
b
[
i
]
.
Name
);
d
!=
0
{
return
d
}
if
d
:=
strings
.
Compare
(
a
[
i
]
.
Value
,
b
[
i
]
.
Value
);
d
!=
0
{
return
d
}
}
// If all labels so far were in common, the set with fewer labels comes first.
return
len
(
a
)
-
len
(
b
)
}
func
(
s
*
shardSeriesSet
)
Series
()
Series
{
return
s
.
cur
}
...
...
@@ -378,7 +358,7 @@ func (s *shardSeriesSet) compare() int {
if
s
.
bs
==
nil
{
return
-
1
}
return
compareLabels
(
s
.
as
.
Labels
(),
s
.
bs
.
Labels
())
return
labels
.
Compare
(
s
.
as
.
Labels
(),
s
.
bs
.
Labels
())
}
func
(
s
*
shardSeriesSet
)
advanceA
()
{
...
...
querier_test.go
浏览文件 @
5efe1d17
...
...
@@ -175,58 +175,6 @@ func expandSeriesIterator(it SeriesIterator) (r []sample, err error) {
return
r
,
it
.
Err
()
}
func
TestCompareLabels
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
a
,
b
[]
labels
.
Label
res
int
}{
{
a
:
[]
labels
.
Label
{},
b
:
[]
labels
.
Label
{},
res
:
0
,
},
{
a
:
[]
labels
.
Label
{{
"a"
,
""
}},
b
:
[]
labels
.
Label
{{
"a"
,
""
},
{
"b"
,
""
}},
res
:
-
1
,
},
{
a
:
[]
labels
.
Label
{{
"a"
,
""
}},
b
:
[]
labels
.
Label
{{
"a"
,
""
}},
res
:
0
,
},
{
a
:
[]
labels
.
Label
{{
"aa"
,
""
},
{
"aa"
,
""
}},
b
:
[]
labels
.
Label
{{
"aa"
,
""
},
{
"ab"
,
""
}},
res
:
-
1
,
},
{
a
:
[]
labels
.
Label
{{
"aa"
,
""
},
{
"abb"
,
""
}},
b
:
[]
labels
.
Label
{{
"aa"
,
""
},
{
"ab"
,
""
}},
res
:
1
,
},
{
a
:
[]
labels
.
Label
{
{
"__name__"
,
"go_gc_duration_seconds"
},
{
"job"
,
"prometheus"
},
{
"quantile"
,
"0.75"
},
},
b
:
[]
labels
.
Label
{
{
"__name__"
,
"go_gc_duration_seconds"
},
{
"job"
,
"prometheus"
},
{
"quantile"
,
"1"
},
},
res
:
-
1
,
},
}
for
_
,
c
:=
range
cases
{
// Use constructor to ensure sortedness.
a
,
b
:=
labels
.
New
(
c
.
a
...
),
labels
.
New
(
c
.
b
...
)
require
.
Equal
(
t
,
c
.
res
,
compareLabels
(
a
,
b
))
}
}
func
TestSampleRing
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
[]
int64
...
...
writer.go
浏览文件 @
5efe1d17
...
...
@@ -325,7 +325,7 @@ func (w *indexWriter) writeSeries() error {
series
=
append
(
series
,
s
)
}
slice
.
Sort
(
series
,
func
(
i
,
j
int
)
bool
{
return
compareLabels
(
series
[
i
]
.
labels
,
series
[
j
]
.
labels
)
<
0
return
labels
.
Compare
(
series
[
i
]
.
labels
,
series
[
j
]
.
labels
)
<
0
})
// Current end of file plus 5 bytes for section header.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录