Skip to content

Commit

Permalink
Allow log stripping to tolerate a missing stream identifier. (#444)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rabbah authored and chetanmeh committed Jul 22, 2019
1 parent 76203e8 commit d75e6d9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions commands/util.go
Expand Up @@ -273,11 +273,15 @@ func makeDefaultHeader(collection interface{}) string {
}

func stripTimestamp(log string) (strippedLog string) {
regex := regexp.MustCompile("[a-zA-Z0-9\\s]*(stdout|stderr):\\s(.*)")
// parses out the timestamp if it exists first
// the timestamp expected format is YYYY-MM-DDTHH:MM:SS.[0-9]+Z
// an optional " stdout" or " stderr" stream identifier
// and the rest as the log line
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(.*)")
match := regex.FindStringSubmatch(log)

if len(match) > 2 && len(match[2]) > 0 {
strippedLog = match[2]
if len(match) > 3 && len(match[3]) > 0 {
strippedLog = match[3]
} else {
strippedLog = log
}
Expand Down
11 changes: 6 additions & 5 deletions commands/util_test.go
Expand Up @@ -29,11 +29,12 @@ func TestStripTimestamp(t *testing.T) {
"2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout",
"2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr",
"2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout",
"2018-05-02T19:33:32.89Z stderr: this is stderr": "this is stderr",
"anything stdout: this is stdout": "this is stdout",
"anything stderr: this is stderr": "this is stderr",
"stdout: this is stdout": "this is stdout",
"stderr: this is stderr": "this is stderr",
"2018-05-02T19:33:32.89Z this is a msg": "this is a msg",
"2018-05-02T19:33:32.89Z this is a msg": " this is a msg",
"anything stdout: this is stdout": "anything stdout: this is stdout",
"anything stderr: this is stderr": "anything stderr: this is stderr",
"stdout: this is stdout": "stdout: this is stdout",
"stderr: this is stderr": "stderr: this is stderr",
"this is stdout": "this is stdout",
"this is stderr": "this is stderr",
"something": "something",
Expand Down
1 change: 1 addition & 0 deletions tools/travis/test_openwhisk.sh
Expand Up @@ -109,4 +109,5 @@ sleep 30
#
# Finally, run the integration test for the CLI
#
./gradlew --console=plain --info goTest -PgoTags=unit
./gradlew --console=plain --info goTest -PgoTags=integration

0 comments on commit d75e6d9

Please sign in to comment.