changed the return of POST /loki from bytes[] to map[string]interface{}, now logs are displayed in oc-front
This commit is contained in:
parent
922ca1d013
commit
a1256ee331
@ -27,9 +27,12 @@ type LokiInfo struct {
|
|||||||
// @Success 200 {workspace} models.workspace
|
// @Success 200 {workspace} models.workspace
|
||||||
// @router / [post]
|
// @router / [post]
|
||||||
func (o *LokiController) GetLogs() {
|
func (o *LokiController) GetLogs() {
|
||||||
path := "/loki/api/v1/query_range"
|
|
||||||
var resp map[string]interface{}
|
var resp map[string]interface{}
|
||||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
|
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
|
||||||
|
|
||||||
|
path := "/loki/api/v1/query_range"
|
||||||
|
|
||||||
if len(resp) > 0 {
|
if len(resp) > 0 {
|
||||||
start := fmt.Sprintf("%v", resp["start"])
|
start := fmt.Sprintf("%v", resp["start"])
|
||||||
if len(start) > 10 {
|
if len(start) > 10 {
|
||||||
@ -53,6 +56,7 @@ func (o *LokiController) GetLogs() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
path += "?query={" + strings.Join(query, ", ") + "}&start=" + start + "&end=" + end
|
path += "?query={" + strings.Join(query, ", ") + "}&start=" + start + "&end=" + end
|
||||||
|
|
||||||
resp, err := http.Get(config.GetConfig().LokiUrl + path) // CALL
|
resp, err := http.Get(config.GetConfig().LokiUrl + path) // CALL
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.Ctx.ResponseWriter.WriteHeader(422)
|
o.Ctx.ResponseWriter.WriteHeader(422)
|
||||||
@ -62,10 +66,19 @@ func (o *LokiController) GetLogs() {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
o.Data["json"] = body
|
|
||||||
|
var data map[string]interface{}
|
||||||
|
err = json.Unmarshal(body,&data)
|
||||||
|
if err != nil {
|
||||||
|
o.Ctx.ResponseWriter.WriteHeader(500)
|
||||||
|
o.Data["json"] = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
o.Data["json"] = data
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Ctx.ResponseWriter.WriteHeader(403)
|
o.Ctx.ResponseWriter.WriteHeader(403)
|
||||||
o.Data["json"] = map[string]string{"error": "Query error"}
|
o.Data["json"] = map[string]string{"error": "Query error"}
|
||||||
o.ServeJSON()
|
o.ServeJSON()
|
||||||
|
Loading…
Reference in New Issue
Block a user