Updated pod logs to fetch argo and experiment logs independently (#2815)

* updated pod logs to fetch argo and experiment logs independently

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>
This commit is contained in:
Soumya Ghosh Dastidar 2021-05-18 11:22:38 +05:30 committed by GitHub
parent 2252c2e08e
commit 5abf1cfc2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -93,7 +93,7 @@ func ClusterConnect(clusterData map[string]string) {
continue
}
// send pod logs
logrus.Print("LOG REQUEST ", podRequest)
logrus.Print("LOG REQUEST ", r.Payload.Data.ClusterConnect.Action.ExternalData.(string))
SendPodLogs(clusterData, podRequest)
} else if strings.Index("create update delete get", strings.ToLower(r.Payload.Data.ClusterConnect.Action.RequestType)) >= 0 {
logrus.Print("WORKFLOW REQUEST ", r.Payload.Data.ClusterConnect.Action)

View File

@ -5,10 +5,10 @@ import (
"strconv"
"strings"
"github.com/litmuschaos/litmus/litmus-portal/cluster-agents/subscriber/pkg/cluster/objects"
"github.com/litmuschaos/litmus/litmus-portal/cluster-agents/subscriber/pkg/cluster/logs"
"github.com/litmuschaos/litmus/litmus-portal/cluster-agents/subscriber/pkg/cluster/objects"
"github.com/litmuschaos/litmus/litmus-portal/cluster-agents/subscriber/pkg/types"
"github.com/sirupsen/logrus"
)
// process event data into proper format acceptable by gql
@ -45,11 +45,15 @@ func GenerateWorkflowPayload(cid, accessKey, completed string, wfEvent types.Wor
func CreatePodLog(podLog types.PodLogRequest) (types.PodLog, error) {
logDetails := types.PodLog{}
mainLog, err := logs.GetLogs(podLog.PodName, podLog.PodNamespace, "main")
// try getting argo pod logs
if err != nil {
return logDetails, err
logrus.Errorf("failed to get argo pod %v logs, err: %v", podLog.PodName, err)
logDetails.MainPod = "Failed to get argo pod logs"
} else {
logDetails.MainPod = strconv.Quote(strings.Replace(mainLog, `"`, `'`, -1))
logDetails.MainPod = logDetails.MainPod[1 : len(logDetails.MainPod)-1]
}
logDetails.MainPod = strconv.Quote(strings.Replace(mainLog, `"`, `'`, -1))
logDetails.MainPod = logDetails.MainPod[1 : len(logDetails.MainPod)-1]
// try getting experiment pod logs if requested
if strings.ToLower(podLog.PodType) == "chaosengine" && podLog.ChaosNamespace != nil {
chaosLog := make(map[string]string)
if podLog.ExpPod != nil {
@ -57,6 +61,8 @@ func CreatePodLog(podLog types.PodLogRequest) (types.PodLog, error) {
if err == nil {
chaosLog[*podLog.ExpPod] = strconv.Quote(strings.Replace(expLog, `"`, `'`, -1))
chaosLog[*podLog.ExpPod] = chaosLog[*podLog.ExpPod][1 : len(chaosLog[*podLog.ExpPod])-1]
} else {
logrus.Errorf("failed to get experiment pod %v logs, err: %v", *podLog.ExpPod, err)
}
}
if podLog.RunnerPod != nil {
@ -64,6 +70,8 @@ func CreatePodLog(podLog types.PodLogRequest) (types.PodLog, error) {
if err == nil {
chaosLog[*podLog.RunnerPod] = strconv.Quote(strings.Replace(runnerLog, `"`, `'`, -1))
chaosLog[*podLog.RunnerPod] = chaosLog[*podLog.RunnerPod][1 : len(chaosLog[*podLog.RunnerPod])-1]
} else {
logrus.Errorf("failed to get runner pod %v logs, err: %v", *podLog.RunnerPod, err)
}
}
if podLog.ExpPod == nil && podLog.RunnerPod == nil {