Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
87bdbfaa
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
87bdbfaa
编写于
6月 24, 2019
作者:
H
huanggze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
apis: unify http response format
Signed-off-by:
N
huanggze
<
loganhuang@yunify.com
>
上级
5910ef45
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
74 addition
and
3 deletion
+74
-3
pkg/apiserver/logging/logging.go
pkg/apiserver/logging/logging.go
+52
-0
pkg/models/log/logcrd.go
pkg/models/log/logcrd.go
+9
-0
pkg/models/log/types.go
pkg/models/log/types.go
+1
-0
pkg/simple/client/elasticsearch/esclient.go
pkg/simple/client/elasticsearch/esclient.go
+12
-3
未找到文件。
pkg/apiserver/logging/logging.go
浏览文件 @
87bdbfaa
...
...
@@ -30,31 +30,63 @@ import (
func
LoggingQueryCluster
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelCluster
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
func
LoggingQueryWorkspace
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelWorkspace
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
func
LoggingQueryNamespace
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelNamespace
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
func
LoggingQueryWorkload
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelWorkload
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
func
LoggingQueryPod
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelPod
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
func
LoggingQueryContainer
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
logQuery
(
log
.
QueryLevelContainer
,
request
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
...
...
@@ -81,6 +113,10 @@ func LoggingUpdateFluentbitFilters(request *restful.Request, response *restful.R
func
LoggingQueryFluentbitOutputs
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
res
:=
log
.
FluentbitOutputsQuery
()
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
...
...
@@ -97,6 +133,11 @@ func LoggingInsertFluentbitOutput(request *restful.Request, response *restful.Re
res
=
log
.
FluentbitOutputInsert
(
output
)
}
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
...
...
@@ -115,6 +156,12 @@ func LoggingUpdateFluentbitOutput(request *restful.Request, response *restful.Re
}
res
:=
log
.
FluentbitOutputUpdate
(
output
,
id
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
...
...
@@ -125,6 +172,11 @@ func LoggingDeleteFluentbitOutput(request *restful.Request, response *restful.Re
id
:=
request
.
PathParameter
(
"output"
)
res
=
log
.
FluentbitOutputDelete
(
id
)
if
res
.
Status
!=
http
.
StatusOK
{
response
.
WriteHeaderAndEntity
(
res
.
Status
,
res
.
Error
)
return
}
response
.
WriteAsJson
(
res
)
}
...
...
pkg/models/log/logcrd.go
浏览文件 @
87bdbfaa
...
...
@@ -233,6 +233,7 @@ func FluentbitOutputsQuery() *FluentbitOutputsResult {
outputs
,
err
:=
GetFluentbitOutputFromConfigMap
()
if
err
!=
nil
{
result
.
Status
=
http
.
StatusNotFound
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -263,6 +264,7 @@ func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
err
=
updateFluentbitOutputConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -270,6 +272,7 @@ func FluentbitOutputInsert(output fb.OutputPlugin) *FluentbitOutputsResult {
err
=
syncFluentbitCRDOutputWithConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -304,6 +307,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
if
index
>=
len
(
outputs
)
{
result
.
Status
=
http
.
StatusNotFound
result
.
Error
=
"The output plugin to update doesn't exist. Please check the output id you provide."
return
&
result
}
...
...
@@ -313,6 +317,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
err
=
updateFluentbitOutputConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -320,6 +325,7 @@ func FluentbitOutputUpdate(output fb.OutputPlugin, id string) *FluentbitOutputsR
err
=
syncFluentbitCRDOutputWithConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -350,6 +356,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
if
index
>=
len
(
outputs
)
{
result
.
Status
=
http
.
StatusNotFound
result
.
Error
=
"The output plugin to delete doesn't exist. Please check the output id you provide."
return
&
result
}
...
...
@@ -358,6 +365,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
err
:=
updateFluentbitOutputConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
@@ -365,6 +373,7 @@ func FluentbitOutputDelete(id string) *FluentbitOutputsResult {
err
=
syncFluentbitCRDOutputWithConfigMap
(
outputs
)
if
err
!=
nil
{
result
.
Status
=
http
.
StatusInternalServerError
result
.
Error
=
err
.
Error
()
return
&
result
}
...
...
pkg/models/log/types.go
浏览文件 @
87bdbfaa
...
...
@@ -49,5 +49,6 @@ type FluentbitFiltersResult struct {
type
FluentbitOutputsResult
struct
{
Status
int
`json:"status" description:"response status"`
Error
string
`json:"error,omitempty" description:"debug information"`
Outputs
[]
fb
.
OutputPlugin
`json:"outputs,omitempty" description:"array of fluent bit output plugins"`
}
pkg/simple/client/elasticsearch/esclient.go
浏览文件 @
87bdbfaa
...
...
@@ -393,6 +393,7 @@ type HistogramResult struct {
// Wrap elasticsearch response
type
QueryResult
struct
{
Status
int
`json:"status,omitempty" description:"query status"`
Error
string
`json:"error,omitempty" description:"debug information"`
Workspace
string
`json:"workspace,omitempty" description:"workspace the query was performed against"`
Read
*
ReadResult
`json:"query,omitempty" description:"query results"`
Statistics
*
StatisticsResult
`json:"statistics,omitempty" description:"statistics results"`
...
...
@@ -428,21 +429,22 @@ func calcTimestamp(input string) int64 {
func
parseQueryResult
(
operation
int
,
param
QueryParameters
,
body
[]
byte
,
query
[]
byte
)
*
QueryResult
{
var
queryResult
QueryResult
//queryResult.Request = string(query)
//queryResult.Response = string(body)
var
response
Response
err
:=
jsonIter
.
Unmarshal
(
body
,
&
response
)
if
err
!=
nil
{
glog
.
Errorln
(
err
)
queryResult
.
Status
=
http
.
StatusInternalServerError
queryResult
.
Error
=
err
.
Error
()
return
&
queryResult
}
if
response
.
Status
!=
0
{
//Elastic error, eg, es_rejected_execute_exception
err
:=
"The query failed with no response"
queryResult
.
Status
=
response
.
Status
glog
.
Errorln
(
"The query failed with no response"
)
queryResult
.
Error
=
err
glog
.
Errorln
(
err
)
return
&
queryResult
}
...
...
@@ -477,6 +479,7 @@ func parseQueryResult(operation int, param QueryParameters, body []byte, query [
if
err
!=
nil
{
glog
.
Errorln
(
err
)
queryResult
.
Status
=
http
.
StatusInternalServerError
queryResult
.
Error
=
err
.
Error
()
return
&
queryResult
}
queryResult
.
Statistics
=
&
StatisticsResult
{
Containers
:
statisticsResponse
.
ContainerCount
.
Value
,
Logs
:
response
.
Hits
.
Total
}
...
...
@@ -493,6 +496,7 @@ func parseQueryResult(operation int, param QueryParameters, body []byte, query [
if
err
!=
nil
{
glog
.
Errorln
(
err
)
queryResult
.
Status
=
http
.
StatusInternalServerError
queryResult
.
Error
=
err
.
Error
()
return
&
queryResult
}
for
_
,
histogram
:=
range
histogramAggregations
.
HistogramAggregation
.
Histograms
{
...
...
@@ -554,6 +558,7 @@ func Query(param QueryParameters) *QueryResult {
if
err
!=
nil
{
queryResult
=
new
(
QueryResult
)
queryResult
.
Status
=
http
.
StatusNotFound
queryResult
.
Error
=
err
.
Error
()
return
queryResult
}
...
...
@@ -561,6 +566,7 @@ func Query(param QueryParameters) *QueryResult {
if
es
==
nil
{
queryResult
=
new
(
QueryResult
)
queryResult
.
Status
=
http
.
StatusNotFound
queryResult
.
Error
=
"Elasticsearch configurations not found. Please check if they are properly configured."
return
queryResult
}
...
...
@@ -571,6 +577,7 @@ func Query(param QueryParameters) *QueryResult {
glog
.
Errorln
(
err
)
queryResult
=
new
(
QueryResult
)
queryResult
.
Status
=
http
.
StatusNotFound
queryResult
.
Error
=
err
.
Error
()
return
queryResult
}
request
.
Header
.
Set
(
"Content-Type"
,
"application/json; charset=utf-8"
)
...
...
@@ -580,6 +587,7 @@ func Query(param QueryParameters) *QueryResult {
glog
.
Errorln
(
err
)
queryResult
=
new
(
QueryResult
)
queryResult
.
Status
=
http
.
StatusNotFound
queryResult
.
Error
=
err
.
Error
()
return
queryResult
}
defer
response
.
Body
.
Close
()
...
...
@@ -589,6 +597,7 @@ func Query(param QueryParameters) *QueryResult {
glog
.
Errorln
(
err
)
queryResult
=
new
(
QueryResult
)
queryResult
.
Status
=
http
.
StatusNotFound
queryResult
.
Error
=
err
.
Error
()
return
queryResult
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录