adjustment

This commit is contained in:
mr 2025-03-28 08:47:44 +01:00
parent e7f8518f34
commit af6aa9e17f
14 changed files with 157 additions and 44 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
appname = oc-scheduler
httpport = 8080
httpport = 8090
runmode = dev
autorender = false
copyrequestbody = true

72
controllers/loki.go Normal file
View 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()
}

View File

@ -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()
}

View File

@ -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

View File

@ -18,8 +18,8 @@ services:
- 8090:8080
container_name: oc-scheduler
networks:
- catalog
- oc
networks:
catalog:
oc:
external: true

View File

@ -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"
}

View File

@ -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

Binary file not shown.

View File

@ -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",

View File

@ -18,6 +18,11 @@ func init() {
beego.NSInclude(
&controllers.WorkflowSchedulerController{},
),
beego.NSNamespace("/loki",
beego.NSInclude(
&controllers.LokiController{},
),
),
beego.NSNamespace("/execution",
beego.NSInclude(
&controllers.WorkflowExecutionController{},

View File

@ -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"
}

View File

@ -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"

View File

@ -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