Confirmation + Controlling API add

This commit is contained in:
mr
2026-04-10 15:16:29 +02:00
parent da4d4bd546
commit 4b9b1b8b91
13 changed files with 116 additions and 17 deletions

View File

@@ -27,14 +27,13 @@ type LokiInfo struct {
// @Description get logs
// @Param body body models.compute true "The compute content"
// @Success 200 {workspace} models.workspace
// @router / [post]
// @router /:id [post]
func (o *LokiController) GetLogs() {
id := o.Ctx.Input.Param(":id")
var resp map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &resp)
path := "/loki/api/v1/query_range"
if len(resp) > 0 {
start := fmt.Sprintf("%v", resp["start"])
if len(start) > 10 {
@@ -44,7 +43,9 @@ func (o *LokiController) GetLogs() {
if len(end) > 10 {
end = end[0:10]
}
query := []string{}
query := []string{
"workflow_execution_id=\"" + id + "\"",
}
for k, v := range resp {
if k == "start" || k == "end" {
continue
@@ -96,6 +97,10 @@ func (o *LokiController) GetLogs() {
// The server connects to Loki's /loki/api/v1/tail WebSocket endpoint and
// forwards every message it receives until the client disconnects.
func LogsStreamHandler(w http.ResponseWriter, r *http.Request) {
execID := strings.TrimSuffix(
strings.TrimPrefix(r.URL.Path, "/oc/logs/"),
"",
)
conn, err := wsUpgrader.Upgrade(w, r, nil)
if err != nil {
return
@@ -112,7 +117,9 @@ func LogsStreamHandler(w http.ResponseWriter, r *http.Request) {
start = start[:10]
}
var labels []string
labels := []string{
"workflow_execution_id=\"" + execID + "\"",
}
for k, v := range query {
if k == "start" || k == "end" {
continue