mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-12-27 09:19:06 +01:00
Change /api/query return type
This commit is contained in:
parent
407e650745
commit
15d28af12d
17
api.go
17
api.go
@ -154,6 +154,11 @@ type ApiQueryRequest struct {
|
|||||||
ForAllNodes []string `json:"for-all-nodes"`
|
ForAllNodes []string `json:"for-all-nodes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApiQueryResponse struct {
|
||||||
|
Queries []ApiQuery `json:"queries,omitempty"`
|
||||||
|
Results [][]ApiMetricData `json:"results"`
|
||||||
|
}
|
||||||
|
|
||||||
type ApiQuery struct {
|
type ApiQuery struct {
|
||||||
Metric string `json:"metric"`
|
Metric string `json:"metric"`
|
||||||
Hostname string `json:"host"`
|
Hostname string `json:"host"`
|
||||||
@ -172,19 +177,23 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response := ApiQueryResponse{
|
||||||
|
Results: make([][]ApiMetricData, 0, len(req.Queries)),
|
||||||
|
}
|
||||||
if req.ForAllNodes != nil {
|
if req.ForAllNodes != nil {
|
||||||
nodes := memoryStore.ListChildren([]string{req.Cluster})
|
nodes := memoryStore.ListChildren([]string{req.Cluster})
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
for _, metric := range req.ForAllNodes {
|
for _, metric := range req.ForAllNodes {
|
||||||
req.Queries = append(req.Queries, ApiQuery{
|
q := ApiQuery{
|
||||||
Metric: metric,
|
Metric: metric,
|
||||||
Hostname: node,
|
Hostname: node,
|
||||||
})
|
}
|
||||||
|
req.Queries = append(req.Queries, q)
|
||||||
|
response.Queries = append(response.Queries, q)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([][]ApiMetricData, 0, len(req.Queries))
|
|
||||||
for _, query := range req.Queries {
|
for _, query := range req.Queries {
|
||||||
sels := make([]Selector, 0, 1)
|
sels := make([]Selector, 0, 1)
|
||||||
if query.Aggregate || query.Type == nil {
|
if query.Aggregate || query.Type == nil {
|
||||||
@ -252,7 +261,7 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
res = append(res, data)
|
res = append(res, data)
|
||||||
}
|
}
|
||||||
response = append(response, res)
|
response.Results = append(response.Results, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
rw.Header().Set("Content-Type", "application/json")
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
45
openapi.yaml
45
openapi.yaml
@ -60,26 +60,31 @@ paths:
|
|||||||
content:
|
content:
|
||||||
'application/json':
|
'application/json':
|
||||||
schema:
|
schema:
|
||||||
description: 'Array where each element is a response to the query at that same index in the request'
|
type: object
|
||||||
type: array
|
properties:
|
||||||
items:
|
queries:
|
||||||
description: 'If `aggreg` is true, only ever has one element.'
|
description: 'Only if for-all-nodes was used, this property exists.'
|
||||||
type: array
|
results:
|
||||||
items:
|
type: array
|
||||||
type: object
|
description: 'Array where each element is a response to the query at that same index in the request'
|
||||||
properties:
|
items:
|
||||||
error:
|
description: 'If `aggreg` is true, only ever has one element.'
|
||||||
description: 'If not null or undefined, an error happend processing that query'
|
type: array
|
||||||
type: string
|
items:
|
||||||
nullable: true
|
type: object
|
||||||
data:
|
properties:
|
||||||
type: array
|
error:
|
||||||
items:
|
description: 'If not null or undefined, an error happend processing that query'
|
||||||
type: number
|
type: string
|
||||||
nullable: true
|
nullable: true
|
||||||
avg: { type: number }
|
data:
|
||||||
min: { type: number }
|
type: array
|
||||||
max: { type: number }
|
items:
|
||||||
|
type: number
|
||||||
|
nullable: true
|
||||||
|
avg: { type: number }
|
||||||
|
min: { type: number }
|
||||||
|
max: { type: number }
|
||||||
400:
|
400:
|
||||||
description: 'Bad Request'
|
description: 'Bad Request'
|
||||||
'/api/free':
|
'/api/free':
|
||||||
|
Loading…
Reference in New Issue
Block a user