2024-07-29 15:46:44 +02:00
|
|
|
package daemons
|
|
|
|
|
2024-08-09 18:44:33 +02:00
|
|
|
import (
|
2024-08-20 15:24:46 +02:00
|
|
|
"fmt"
|
2024-08-19 11:42:26 +02:00
|
|
|
"oc-schedulerd/conf"
|
2024-08-09 18:44:33 +02:00
|
|
|
"os/exec"
|
2024-08-19 11:42:26 +02:00
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
2024-08-09 18:44:33 +02:00
|
|
|
)
|
2024-07-29 15:46:44 +02:00
|
|
|
|
2024-08-19 11:42:26 +02:00
|
|
|
type LocalMonitor struct {
|
|
|
|
LokiURL string
|
|
|
|
KubeURL string
|
|
|
|
WorkflowName string
|
|
|
|
Logger zerolog.Logger
|
2024-07-29 15:46:44 +02:00
|
|
|
}
|
|
|
|
|
2024-08-19 11:42:26 +02:00
|
|
|
func (lm *LocalMonitor) LaunchLocalMonitor() {
|
|
|
|
if lm.LokiURL == "" || lm.KubeURL == "" || lm.WorkflowName == "" {
|
|
|
|
lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
|
2024-07-29 15:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// For dev purposes, in prod KubeURL must be a kube API's URL
|
2024-08-20 15:24:46 +02:00
|
|
|
if lm.KubeURL != "localhost" {
|
2024-08-09 18:44:33 +02:00
|
|
|
lm.execRemoteKube()
|
2024-08-20 15:24:46 +02:00
|
|
|
} else {
|
|
|
|
lm.execLocalKube()
|
2024-07-29 15:46:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-19 11:42:26 +02:00
|
|
|
func (lm *LocalMonitor) execLocalKube() {
|
|
|
|
cmd := exec.Command(conf.GetConfig().MonitorPath, "-w", lm.WorkflowName, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName)
|
2024-08-20 15:24:46 +02:00
|
|
|
fmt.Println("CMD", cmd)
|
2024-08-12 16:09:30 +02:00
|
|
|
err := cmd.Start()
|
2024-08-19 11:42:26 +02:00
|
|
|
if err != nil {
|
|
|
|
lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.WorkflowName + " : " + err.Error())
|
2024-08-09 18:44:33 +02:00
|
|
|
}
|
2024-07-29 15:46:44 +02:00
|
|
|
}
|
|
|
|
|
2024-08-19 11:42:26 +02:00
|
|
|
// TODO : implement this
|
|
|
|
func (lm *LocalMonitor) execRemoteKube() {
|
2024-07-29 15:46:44 +02:00
|
|
|
|
|
|
|
}
|