Merge branch 'main' of https://cloud.o-forge.io/core/oc-monitord into main
This commit is contained in:
31
main.go
31
main.go
@@ -21,7 +21,6 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/google/uuid"
|
||||
@@ -64,13 +63,19 @@ func main() {
|
||||
loadConfig(true, nil)
|
||||
}
|
||||
|
||||
logs.SetAppName("oc-monitord")
|
||||
logger = logs.CreateLogger("oc-monitord", conf.GetConfig().LokiURL)
|
||||
logger = logs.CreateLogger("oc-monitord")
|
||||
|
||||
logger.Debug().Msg("Loki URL : " + conf.GetConfig().LokiURL)
|
||||
logger.Debug().Msg("Workflow executed : " + conf.GetConfig().ExecutionID)
|
||||
|
||||
oclib.Init("oc-monitord", "", "")
|
||||
oclib.SetConfig(
|
||||
conf.GetConfig().MongoURL,
|
||||
conf.GetConfig().Database,
|
||||
conf.GetConfig().NatsURL,
|
||||
conf.GetConfig().LokiURL,
|
||||
conf.GetConfig().Logs,
|
||||
)
|
||||
oclib.Init("oc-monitord")
|
||||
|
||||
wf_id := getWorkflowId(conf.GetConfig().ExecutionID)
|
||||
conf.GetConfig().WorkflowID = wf_id
|
||||
@@ -121,6 +126,8 @@ func getWorkflowId(exec_id string) string {
|
||||
return wf_exec.WorkflowID
|
||||
}
|
||||
|
||||
// So far we only log the output from
|
||||
|
||||
func executeWorkflow(argo_file_path string) {
|
||||
// var stdout, stderr, stdout_logs, stderr_logs io.ReadCloser
|
||||
var stdout, stderr io.ReadCloser
|
||||
@@ -187,7 +194,7 @@ func logWorkflow(pipe io.ReadCloser, wg *sync.WaitGroup) {
|
||||
|
||||
// Debug, no logs sent
|
||||
func logPods(pipe io.ReadCloser, name string) {
|
||||
pods_logger = wf_logger.With().Str("sortie name", name).Logger()
|
||||
pods_logger = wf_logger.With().Str("pod_name", name).Logger()
|
||||
scanner := bufio.NewScanner(pipe)
|
||||
for scanner.Scan() {
|
||||
log := scanner.Text()
|
||||
@@ -202,7 +209,7 @@ func loadConfig(is_k8s bool, parser *argparse.Parser) {
|
||||
|
||||
o = initOnion(o)
|
||||
// These variables can only be retrieved in the onion
|
||||
// Variables that don't depend on the environmen (from conf file), can be loaded after
|
||||
// Variables that don't depend on the environment (from conf file), can be loaded after
|
||||
// We can't use underscore in the env variable names because it's the delimitor with OCMONITOR too
|
||||
setConf(is_k8s, o, parser)
|
||||
|
||||
@@ -223,7 +230,9 @@ func setConf(is_k8s bool, o *onion.Onion, parser *argparse.Parser) {
|
||||
conf.GetConfig().ExecutionID = o.GetString("workflow")
|
||||
mongo := o.GetStringDefault("mongourl", "mongodb://127.0.0.1:27017")
|
||||
db := o.GetStringDefault("database", "DC_myDC")
|
||||
tools.SetConfig(mongo, db, "")
|
||||
|
||||
conf.GetConfig().MongoURL = mongo
|
||||
conf.GetConfig().Database = db
|
||||
} else {
|
||||
url := parser.String("u", "url", &argparse.Options{Required: true, Default: "http://127.0.0.1:3100", Help: "Url to the Loki database logs will be sent to"})
|
||||
execution := parser.String("e", "execution", &argparse.Options{Required: true, Help: "Execution ID of the workflow to request from oc-catalog API"})
|
||||
@@ -235,16 +244,20 @@ func setConf(is_k8s bool, o *onion.Onion, parser *argparse.Parser) {
|
||||
fmt.Println(parser.Usage(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
conf.GetConfig().Logs = "debug"
|
||||
|
||||
conf.GetConfig().LokiURL = *url
|
||||
conf.GetConfig().MongoURL = *mongo
|
||||
conf.GetConfig().Database = *db
|
||||
conf.GetConfig().Timeout = *timeout
|
||||
conf.GetConfig().ExecutionID = *execution
|
||||
tools.SetConfig(*mongo, *db, "")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func initOnion(o *onion.Onion) *onion.Onion {
|
||||
logger = logs.CreateLogger("oc-monitord", "")
|
||||
logger = logs.CreateLogger("oc-monitord")
|
||||
configFile := ""
|
||||
|
||||
l3 := onion.NewEnvLayerPrefix("_", "OCMONITORD")
|
||||
|
||||
Reference in New Issue
Block a user