This is an automated email from the ASF dual-hosted git repository.
chetanm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 3927828 Fixes the issue of failing to read empty Splunk JSON objects
(#4348)
3927828 is described below
commit 39278289d9d907146347c517a238d2ce3bc18491
Author: Cosmin Stanciu <[email protected]>
AuthorDate: Fri Mar 15 01:32:29 2019 -0700
Fixes the issue of failing to read empty Splunk JSON objects (#4348)
Ignores the json records which have some of the required fields missing and
replaces them with the error message from the parsing
---
.../containerpool/logging/SplunkLogStore.scala | 28 +++++++++++++++-------
.../logging/SplunkLogStoreTests.scala | 6 +++--
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git
a/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStore.scala
b/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStore.scala
index d550f8c..5c7768b 100644
---
a/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStore.scala
+++
b/common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStore.scala
@@ -133,18 +133,28 @@ class SplunkLogStore(
logging.debug(this, s"splunk API response ${response}")
Unmarshal(response.entity)
.to[SplunkResponse]
- .map(r => {
- ActivationLogs(
- r.results
- .map(l =>
- //format same as
org.apache.openwhisk.core.containerpool.logging.LogLine.toFormattedString
-
f"${l.fields(splunkConfig.logTimestampField).convertTo[String]}%-30s ${l
- .fields(splunkConfig.logStreamField)
- .convertTo[String]}:
${l.fields(splunkConfig.logMessageField).convertTo[String].trim}"))
- })
+ .map(
+ r =>
+ ActivationLogs(
+ r.results
+ .map(js => Try(toLogLine(js)))
+ .map {
+ case Success(s) => s
+ case Failure(t) =>
+ logging.debug(
+ this,
+ s"The log message might have been too large " +
+ s"for '${splunkConfig.index}' Splunk index and can't
be retrieved, ${t.getMessage}")
+ s"The log message can't be retrieved, ${t.getMessage}"
+ }))
})
}
+ private def toLogLine(l: JsObject) = //format same as
org.apache.openwhisk.core.containerpool.logging.LogLine.toFormattedString
+ f"${l.fields(splunkConfig.logTimestampField).convertTo[String]}%-30s ${l
+ .fields(splunkConfig.logStreamField)
+ .convertTo[String]}:
${l.fields(splunkConfig.logMessageField).convertTo[String].trim}"
+
//based on
http://doc.akka.io/docs/akka-http/10.0.6/scala/http/client-side/host-level.html
val queue =
Source
diff --git
a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStoreTests.scala
b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStoreTests.scala
index 7582606..e7a1567 100644
---
a/tests/src/test/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStoreTests.scala
+++
b/tests/src/test/scala/org/apache/openwhisk/core/containerpool/logging/SplunkLogStoreTests.scala
@@ -128,7 +128,7 @@ class SplunkLogStoreTests
StatusCodes.OK,
entity = HttpEntity(
ContentTypes.`application/json`,
-
"""{"preview":false,"init_offset":0,"messages":[],"fields":[{"name":"log_message"}],"results":[{"log_timestamp":
"2007-12-03T10:15:30Z", "log_stream":"stdout", "log_message":"some log
message"},{"log_timestamp": "2007-12-03T10:15:31Z", "log_stream":"stderr",
"log_message":"some other log message"}], "highlighted":{}}"""))),
+
"""{"preview":false,"init_offset":0,"messages":[],"fields":[{"name":"log_message"}],"results":[{"log_timestamp":
"2007-12-03T10:15:30Z", "log_stream":"stdout", "log_message":"some log
message"},{"log_timestamp": "2007-12-03T10:15:31Z", "log_stream":"stderr",
"log_message":"some other log message"},{},{"log_timestamp":
"2007-12-03T10:15:32Z", "log_stream":"stderr"}], "highlighted":{}}"""))),
userContext)
}
.recover {
@@ -156,7 +156,9 @@ class SplunkLogStoreTests
result shouldBe ActivationLogs(
Vector(
"2007-12-03T10:15:30Z stdout: some log message",
- "2007-12-03T10:15:31Z stderr: some other log message"))
+ "2007-12-03T10:15:31Z stderr: some other log message",
+ "The log message can't be retrieved, key not found: log_timestamp",
+ "The log message can't be retrieved, key not found: log_message"))
}
it should "fail to connect to bogus host" in {