Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
3d67d759
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,发现更多精彩内容 >>
提交
3d67d759
编写于
7月 06, 2015
作者:
F
Fabian Reinartz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
promql: implement JSON array format for scalar and string
上级
834cec44
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
7 deletion
+51
-7
promql/engine.go
promql/engine.go
+18
-6
web/api/legacy/query.go
web/api/legacy/query.go
+33
-1
未找到文件。
promql/engine.go
浏览文件 @
3d67d759
...
...
@@ -19,6 +19,7 @@ import (
"math"
"runtime"
"sort"
"strconv"
"time"
"golang.org/x/net/context"
...
...
@@ -43,12 +44,6 @@ type Sample struct {
Timestamp
clientmodel
.
Timestamp
`json:"timestamp"`
}
// Scalar is a scalar value evaluated at the set timestamp.
type
Scalar
struct
{
Value
clientmodel
.
SampleValue
`json:"value"`
Timestamp
clientmodel
.
Timestamp
`json:"timestamp"`
}
// MarshalJSON implements json.Marshaler.
func
(
s
*
Sample
)
MarshalJSON
()
([]
byte
,
error
)
{
v
:=
struct
{
...
...
@@ -65,16 +60,33 @@ func (s *Sample) MarshalJSON() ([]byte, error) {
return
json
.
Marshal
(
&
v
)
}
// Scalar is a scalar value evaluated at the set timestamp.
type
Scalar
struct
{
Value
clientmodel
.
SampleValue
`json:"value"`
Timestamp
clientmodel
.
Timestamp
`json:"timestamp"`
}
func
(
s
*
Scalar
)
String
()
string
{
return
fmt
.
Sprintf
(
"scalar: %v @[%v]"
,
s
.
Value
,
s
.
Timestamp
)
}
// MarshalJSON implements json.Marshaler.
func
(
s
*
Scalar
)
MarshalJSON
()
([]
byte
,
error
)
{
v
:=
strconv
.
FormatFloat
(
float64
(
s
.
Value
),
'f'
,
-
1
,
64
)
return
json
.
Marshal
([]
interface
{}{
s
.
Timestamp
,
string
(
v
)})
}
// String is a string value evaluated at the set timestamp.
type
String
struct
{
Value
string
`json:"value"`
Timestamp
clientmodel
.
Timestamp
`json:"timestamp"`
}
// MarshalJSON implements json.Marshaler.
func
(
s
*
String
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
([]
interface
{}{
s
.
Timestamp
,
s
.
Value
})
}
func
(
s
*
String
)
String
()
string
{
return
s
.
Value
}
...
...
web/api/legacy/query.go
浏览文件 @
3d67d759
...
...
@@ -94,11 +94,19 @@ func (api *API) Query(w http.ResponseWriter, r *http.Request) {
respondJSON
(
w
,
plainVec
(
vec
))
return
}
if
sca
,
ok
:=
res
.
Value
.
(
*
promql
.
Scalar
);
ok
{
respondJSON
(
w
,
(
*
plainScalar
)(
sca
))
return
}
if
str
,
ok
:=
res
.
Value
.
(
*
promql
.
String
);
ok
{
respondJSON
(
w
,
(
*
plainString
)(
str
))
return
}
respondJSON
(
w
,
res
.
Value
)
}
// plainVec is an indirection that hides the original MarshalJSON method
s
// plainVec is an indirection that hides the original MarshalJSON method
// which does not fit the response format for the legacy API.
type
plainVec
promql
.
Vector
...
...
@@ -121,6 +129,30 @@ func (pv plainVec) String() string {
return
""
}
// plainScalar is an indirection that hides the original MarshalJSON method
// which does not fit the response format for the legacy API.
type
plainScalar
promql
.
Scalar
func
(
pv
plainScalar
)
Type
()
promql
.
ExprType
{
return
promql
.
ExprScalar
}
func
(
pv
plainScalar
)
String
()
string
{
return
""
}
// plainString is an indirection that hides the original MarshalJSON method
// which does not fit the response format for the legacy API.
type
plainString
promql
.
String
func
(
pv
plainString
)
Type
()
promql
.
ExprType
{
return
promql
.
ExprString
}
func
(
pv
plainString
)
String
()
string
{
return
""
}
// QueryRange handles the /api/query_range endpoint.
func
(
api
*
API
)
QueryRange
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
setAccessControlHeaders
(
w
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录