From d51a65ac9f9f802da020dde82c0c49ca992c45f2 Mon Sep 17 00:00:00 2001 From: re-Tick Date: Thu, 2 Nov 2023 06:17:47 +0000 Subject: [PATCH 1/2] fix: updates the decode function for OpMsg section the decode function is not able to distinguish the closing braces of the string json and sectionSingle, so used the prefix and suffix in place of regex to extract the document correctly Signed-off-by: re-Tick --- .../integrations/mongoparser/mongoparser.go | 4 +- .../integrations/mongoparser/operation.go | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pkg/proxy/integrations/mongoparser/mongoparser.go b/pkg/proxy/integrations/mongoparser/mongoparser.go index f3cbf5137..03e71c784 100755 --- a/pkg/proxy/integrations/mongoparser/mongoparser.go +++ b/pkg/proxy/integrations/mongoparser/mongoparser.go @@ -689,7 +689,7 @@ func compareOpMsgSection(expectedSection, actualSection string, logger *zap.Logg return score case strings.HasPrefix(expectedSection, "{ SectionSingle msg:"): var expectedMsgsStr string - expectedMsgsStr, err := decodeOpMsgSectionSingle(actualSection) + expectedMsgsStr, err := extractSectionSingle(actualSection) if err != nil { logger.Error("failed to fetch the msgs from the single section of recorded OpMsg", zap.Error(err)) return 0 @@ -699,7 +699,7 @@ func compareOpMsgSection(expectedSection, actualSection string, logger *zap.Logg // // Find submatches using the regular expression var actualMsgsStr string - actualMsgsStr, err = decodeOpMsgSectionSingle(actualSection) + actualMsgsStr, err = extractSectionSingle(actualSection) if err != nil { logger.Error("failed to fetch the msgs from the single section of incoming OpMsg", zap.Error(err)) return 0 diff --git a/pkg/proxy/integrations/mongoparser/operation.go b/pkg/proxy/integrations/mongoparser/operation.go index da76dc4aa..d8c627123 100755 --- a/pkg/proxy/integrations/mongoparser/operation.go +++ b/pkg/proxy/integrations/mongoparser/operation.go @@ -442,25 +442,36 @@ func decodeOpMsgSectionSequence(section string) (string, string, error) { } -func decodeOpMsgSectionSingle(section string) (string, error) { - var message = "" - - // Define the regular expression pattern - pattern := `\{ SectionSingle msg: (.+?) \}` +func extractSectionSingle(data string) (string, error) { + // Look for the prefix before the actual content + prefix := "{ SectionSingle msg: " + startIndex := strings.Index(data, prefix) + if startIndex == -1 { + return "", fmt.Errorf("start not found") + } - // Compile the regular expression - regex := regexp.MustCompile(pattern) + // Adjust the start index to skip the prefix + startIndex += len(prefix) - // Find submatches using the regular expression - submatches := regex.FindStringSubmatch(section) - if submatches == nil || len(submatches) != 2 { - return message, errors.New("invalid format of message section single") + // We'll assume the content ends with " }" that closes the sectionSingle + endIndex := strings.LastIndex(data[startIndex:], " }") + if endIndex == -1 { + return "", fmt.Errorf("end not found") } - // expectedIdentifier = submatches[1] - message = submatches[1] - return message, nil + + // Adjust the end index relative to the entire string + endIndex += startIndex + + // Extract the content between the start and end indexes + content := data[startIndex:endIndex] + + // Clean up the extracted content + content = strings.Trim(content, " ") + + return content, nil } + func encodeOpMsg(responseOpMsg *models.MongoOpMessage, logger *zap.Logger) (*opMsg, error) { message := &opMsg{ flags: wiremessage.MsgFlag(responseOpMsg.FlagBits), @@ -491,7 +502,7 @@ func encodeOpMsg(responseOpMsg *models.MongoOpMessage, logger *zap.Logger) (*opM msgs: docs, }) case strings.HasPrefix(messageValue, "{ SectionSingle msg:"): - sectionStr, err := decodeOpMsgSectionSingle(responseOpMsg.Sections[messageIndex]) + sectionStr, err := extractSectionSingle(responseOpMsg.Sections[messageIndex]) if err != nil { logger.Error("failed to extract the msg section from recorded message single section", zap.Error(err)) return nil, err From 438934398fb977a75aa2498c348f00dedf7474cf Mon Sep 17 00:00:00 2001 From: re-Tick Date: Sun, 31 Dec 2023 06:09:14 +0000 Subject: [PATCH 2/2] fix: runs the commands using the -c flag of sh the sh shell provides a flag to run multiple commands from a single shell cmd. So using this we will be able to use the parsing of script cmds of shell Signed-off-by: re-Tick --- pkg/hooks/launch.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/hooks/launch.go b/pkg/hooks/launch.go index ebf202892..206a98149 100755 --- a/pkg/hooks/launch.go +++ b/pkg/hooks/launch.go @@ -471,8 +471,7 @@ func (h *Hook) processDockerEnv(appCmd, appContainer, appNetwork string, buildDe // It runs the application using the given command func (h *Hook) runApp(appCmd string, isUnitTestIntegration bool) error { // Create a new command with your appCmd - parts := strings.Fields(appCmd) - cmd := exec.Command(parts[0], parts[1:]...) + cmd := exec.Command("sh", "-c", appCmd) cmd.SysProcAttr = &syscall.SysProcAttr{ Setpgid: true,