adjustment
This commit is contained in:
parent
e7f8518f34
commit
af6aa9e17f
11
Makefile
11
Makefile
@ -6,8 +6,13 @@ build: clean
|
||||
run:
|
||||
bee run -gendoc=true -downdoc=true
|
||||
|
||||
dev:
|
||||
bee generate routers && HTTPPORT=8090 bee run -gendoc=true -downdoc=true
|
||||
purge:
|
||||
lsof -t -i:8090 | xargs kill | true
|
||||
|
||||
run-dev:
|
||||
bee generate routers && bee run -gendoc=true -downdoc=true -runmode=prod
|
||||
|
||||
dev: purge run-dev
|
||||
|
||||
debug:
|
||||
bee run -downdebug -gendebug
|
||||
@ -27,4 +32,4 @@ publish-registry:
|
||||
|
||||
all: docker publish-kind publish-registry
|
||||
|
||||
.PHONY: build run clean docker publish-kind publish-registry
|
||||
.PHONY: build run clean docker publish-kind publish-registry
|
||||
|
@ -1,5 +1,5 @@
|
||||
appname = oc-scheduler
|
||||
httpport = 8080
|
||||
httpport = 8090
|
||||
runmode = dev
|
||||
autorender = false
|
||||
copyrequestbody = true
|
||||
|
72
controllers/loki.go
Normal file
72
controllers/loki.go
Normal file
@ -0,0 +1,72 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about workflow
|
||||
type LokiController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
type LokiInfo struct {
|
||||
Start string `json:"start"`
|
||||
End string `json:"end"`
|
||||
}
|
||||
|
||||
// @Title GetLogs
|
||||
// @Description get logs
|
||||
// @Param body body models.compute true "The compute content"
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router / [post]
|
||||
func (o *LokiController) GetLogs() {
|
||||
path := "/loki/api/v1/query_range"
|
||||
var resp map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
|
||||
if len(resp) > 0 {
|
||||
start := fmt.Sprintf("%v", resp["start"])
|
||||
if len(start) > 10 {
|
||||
start = start[0:10]
|
||||
}
|
||||
end := fmt.Sprintf("%v", resp["end"])
|
||||
if len(end) > 10 {
|
||||
end = end[0:10]
|
||||
}
|
||||
query := []string{}
|
||||
for k, v := range resp {
|
||||
if k == "start" || k == "end" {
|
||||
continue
|
||||
}
|
||||
query = append(query, fmt.Sprintf("%v=\"%v\"", k, v))
|
||||
}
|
||||
if len(query) == 0 || len(start) < 10 || len(end) < 10 {
|
||||
o.Ctx.ResponseWriter.WriteHeader(403)
|
||||
o.Data["json"] = map[string]string{"error": "Query error, missing data : start, end or query"}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
path += "?query={" + strings.Join(query, ", ") + "}&start=" + start + "&end=" + end
|
||||
resp, err := http.Get(config.GetConfig().LokiUrl + path) // CALL
|
||||
if err != nil {
|
||||
o.Ctx.ResponseWriter.WriteHeader(422)
|
||||
o.Data["json"] = map[string]string{"error": err.Error()}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
o.Data["json"] = body
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
o.Ctx.ResponseWriter.WriteHeader(403)
|
||||
o.Data["json"] = map[string]string{"error": "Query error"}
|
||||
o.ServeJSON()
|
||||
}
|
@ -15,7 +15,10 @@ type VersionController struct {
|
||||
// @Success 200
|
||||
// @router / [get]
|
||||
func (c *VersionController) GetAll() {
|
||||
c.Data["json"] = map[string]string{"version": "1"}
|
||||
c.Data["json"] = map[string]string{
|
||||
"service": "oc-scheduler",
|
||||
"version": "1",
|
||||
}
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
version: '3.4'
|
||||
|
||||
services:
|
||||
mongo:
|
||||
image: 'mongo:latest'
|
||||
networks:
|
||||
- catalog
|
||||
ports:
|
||||
- 27017:27017
|
||||
container_name: mongo
|
||||
volumes:
|
||||
- oc-catalog-data:/data/db
|
||||
- oc-catalog-data:/data/configdb
|
||||
|
||||
mongo-express:
|
||||
image: "mongo-express:latest"
|
||||
restart: always
|
||||
depends_on:
|
||||
- mongo
|
||||
networks:
|
||||
- catalog
|
||||
ports:
|
||||
- 8081:8081
|
||||
environment:
|
||||
- ME_CONFIG_BASICAUTH_USERNAME=test
|
||||
- ME_CONFIG_BASICAUTH_PASSWORD=test
|
||||
|
||||
volumes:
|
||||
oc-catalog-data:
|
||||
|
||||
networks:
|
||||
catalog:
|
||||
# name: catalog
|
@ -18,8 +18,8 @@ services:
|
||||
- 8090:8080
|
||||
container_name: oc-scheduler
|
||||
networks:
|
||||
- catalog
|
||||
- oc
|
||||
|
||||
networks:
|
||||
catalog:
|
||||
oc:
|
||||
external: true
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"MONGO_URL":"mongodb://mongo:27017/",
|
||||
"NATS_URL":"nats://nats:4222",
|
||||
"MONGO_DATABASE":"DC_myDC"
|
||||
"MONGO_DATABASE":"DC_myDC",
|
||||
"LOKI_URL": "http://loki:3100"
|
||||
}
|
2
main.go
2
main.go
@ -24,7 +24,7 @@ func main() {
|
||||
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
|
||||
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
|
||||
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
|
||||
o.GetStringDefault("LOKI_URL", ""),
|
||||
o.GetStringDefault("LOKI_URL", "loki://localhost:3100"),
|
||||
o.GetStringDefault("LOG_LEVEL", "info"),
|
||||
)
|
||||
|
||||
|
BIN
oc-scheduler
Executable file
BIN
oc-scheduler
Executable file
Binary file not shown.
@ -7,6 +7,15 @@ import (
|
||||
|
||||
func init() {
|
||||
|
||||
beego.GlobalControllerRouter["oc-scheduler/controllers:LokiController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:LokiController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetLogs",
|
||||
Router: `/`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["oc-scheduler/controllers:VersionController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:VersionController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetAll",
|
||||
|
@ -18,6 +18,11 @@ func init() {
|
||||
beego.NSInclude(
|
||||
&controllers.WorkflowSchedulerController{},
|
||||
),
|
||||
beego.NSNamespace("/loki",
|
||||
beego.NSInclude(
|
||||
&controllers.LokiController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/execution",
|
||||
beego.NSInclude(
|
||||
&controllers.WorkflowExecutionController{},
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"port":8080,
|
||||
"port":8090,
|
||||
"MONGO_URL":"mongodb://localhost:27017/",
|
||||
"MONGO_DATABASE":"DC_myDC"
|
||||
"MONGO_DATABASE":"DC_myDC",
|
||||
"LOKI_URL": "http://localhost:3100"
|
||||
}
|
@ -125,6 +125,31 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/loki/": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"loki"
|
||||
],
|
||||
"description": "get logs\n\u003cbr\u003e",
|
||||
"operationId": "LokiController.GetLogs",
|
||||
"parameters": [
|
||||
{
|
||||
"in": "body",
|
||||
"name": "body",
|
||||
"description": "The compute content",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.compute"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "{workspace} models.workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/version/": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -250,6 +275,10 @@
|
||||
"name": "oc-scheduler/controllersWorkflowSchedulerController",
|
||||
"description": "Operations about workflow\n"
|
||||
},
|
||||
{
|
||||
"name": "loki",
|
||||
"description": "Operations about workflow\n"
|
||||
},
|
||||
{
|
||||
"name": "execution",
|
||||
"description": "Operations about workflow\n"
|
||||
|
@ -154,6 +154,24 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: '{workspace} models.workspace'
|
||||
/loki/:
|
||||
post:
|
||||
tags:
|
||||
- loki
|
||||
description: |-
|
||||
get logs
|
||||
<br>
|
||||
operationId: LokiController.GetLogs
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: The compute content
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.compute'
|
||||
responses:
|
||||
"200":
|
||||
description: '{workspace} models.workspace'
|
||||
/version/:
|
||||
get:
|
||||
tags:
|
||||
@ -184,6 +202,9 @@ tags:
|
||||
- name: oc-scheduler/controllersWorkflowSchedulerController
|
||||
description: |
|
||||
Operations about workflow
|
||||
- name: loki
|
||||
description: |
|
||||
Operations about workflow
|
||||
- name: execution
|
||||
description: |
|
||||
Operations about workflow
|
||||
|
Loading…
Reference in New Issue
Block a user