Skip to content

Commit d75e6d9

Browse files
rabbahchetanmeh
authored andcommitted
Allow log stripping to tolerate a missing stream identifier. (#444)
Allows log stripping to tolerate a missing stream identifier. This enables the log parsing to work cases like with standalone OpenWhisk the emitted log entries do not contain the stream info. Also enables unit test on travis
1 parent 76203e8 commit d75e6d9

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

commands/util.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,15 @@ func makeDefaultHeader(collection interface{}) string {
273273
}
274274

275275
func stripTimestamp(log string) (strippedLog string) {
276-
regex := regexp.MustCompile("[a-zA-Z0-9\\s]*(stdout|stderr):\\s(.*)")
276+
// parses out the timestamp if it exists first
277+
// the timestamp expected format is YYYY-MM-DDTHH:MM:SS.[0-9]+Z
278+
// an optional " stdout" or " stderr" stream identifier
279+
// and the rest as the log line
280+
regex := regexp.MustCompile("\\d{4}-[01]{1}\\d{1}-[0-3]{1}\\d{1}T[0-2]{1}\\d{1}:[0-6]{1}\\d{1}:[0-6]{1}\\d{1}.\\d+Z( (stdout|stderr):)?\\s(.*)")
277281
match := regex.FindStringSubmatch(log)
278282

279-
if len(match) > 2 && len(match[2]) > 0 {
280-
strippedLog = match[2]
283+
if len(match) > 3 && len(match[3]) > 0 {
284+
strippedLog = match[3]
281285
} else {
282286
strippedLog = log
283287
}

commands/util_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ func TestStripTimestamp(t *testing.T) {
2929
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
3030
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
3131
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
32-
"2018-05-02T19:33:32.89Z stderr: this is stderr": "this is stderr",
33-
"anything stdout: this is stdout": "this is stdout",
34-
"anything stderr: this is stderr": "this is stderr",
35-
"stdout: this is stdout": "this is stdout",
36-
"stderr: this is stderr": "this is stderr",
32+
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
33+
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
34+
"anything stdout: this is stdout": "anything stdout: this is stdout",
35+
"anything stderr: this is stderr": "anything stderr: this is stderr",
36+
"stdout: this is stdout": "stdout: this is stdout",
37+
"stderr: this is stderr": "stderr: this is stderr",
3738
"this is stdout": "this is stdout",
3839
"this is stderr": "this is stderr",
3940
"something": "something",

tools/travis/test_openwhisk.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ sleep 30
109109
#
110110
# Finally, run the integration test for the CLI
111111
#
112+
./gradlew --console=plain --info goTest -PgoTags=unit
112113
./gradlew --console=plain --info goTest -PgoTags=integration

0 commit comments

Comments
 (0)