From 3fced135b82f69a1d96902c9c5687e6e697e2872 Mon Sep 17 00:00:00 2001
From: Matthew McGill <mhollismcgill@gmail.com>
Date: Mon, 22 Oct 2018 15:59:23 +0000
Subject: [PATCH] thanos integration

Former-commit-id: 1bb613c9fd782df42ad8202f82afb75b921f94c8
---
 tools/ps_analyze.sh | 48 ++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/tools/ps_analyze.sh b/tools/ps_analyze.sh
index 3d21488dc..f3ec92ab8 100755
--- a/tools/ps_analyze.sh
+++ b/tools/ps_analyze.sh
@@ -543,24 +543,36 @@ perform_step()
 	echo -n Performing step "$step" [dependencies=$mandatory] ...
 	starttime=`$PS_DATE`
 
-	# If verbose is on, tee to a file 
-	if [ ! -z "$DEBUG_STEPS" ]; then
-		$command 
-		command_exit=$?
-	elif [ ! -z "$VERBOSE" ]; then
-		$command 2>&1 | tee $logfile
-		command_exit=${PIPESTATUS[0]} # this funkiness gets the exit code of $command, not tee
-	else
-		echo "$command"|grep "lib$step\.so " > /dev/null
-		grep_res=$?
-		if [ $grep_res -eq 0 ] ; then
-			if [[ "$(stop_if_error $step)" != "0" ]]; then
-				echo "EXECUTE_STEP CRITICAL $command" > $input_pipe
-			else
-				echo "EXECUTE_STEP OPTIONAL $command" > $input_pipe
-			fi	
-			read -r thanos_res < $output_pipe
-			echo "Response was $thanos_res"
+	# First, check if using Transform_Step plugin architecture
+	echo "$command"|grep "lib$step\.so " > /dev/null
+        grep_res=$?
+        if [ $grep_res -eq 0 ] ; then
+                if [[ "$(stop_if_error $step)" != "0" ]]; then
+                        echo "EXECUTE_STEP CRITICAL $command" > $input_pipe
+                else
+                        echo "EXECUTE_STEP OPTIONAL $command" > $input_pipe
+                fi
+
+                read -r thanos_res < $output_pipe
+
+                if [ "$thanos_res" = "ERR_INVALID_CMD"  ]; then
+                        echo Internal Transform_Step plugin architecture error.
+                        echo Exiting ps_analyze early.
+                        exit -1
+                elif [ "$thanos_res" = "STEP_UNSUPPORTED" ]; then
+                        command_exit=127 # command not found
+                else
+                        command_exit=$thanos_res
+		fi
+        else
+		# Otherwise, do things the old way (step is its own process)
+		# If verbose is on, tee to a file 
+		if [ ! -z "$DEBUG_STEPS" ]; then
+			$command 
+			command_exit=$?
+		elif [ ! -z "$VERBOSE" ]; then
+			$command 2>&1 | tee $logfile
+			command_exit=${PIPESTATUS[0]} # this funkiness gets the exit code of $command, not tee
 		else
 			$command > $logfile 2>&1 
 			command_exit=$?
-- 
GitLab