You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/08/30 10:28:31 UTC
[brooklyn-server] 01/02: more flexible task tree inference from log messages
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 4e356132366f6fccc59bff21ea82295d4124afa4
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Mon Aug 29 16:28:32 2022 +0100
more flexible task tree inference from log messages
---
.../util/core/logbook/file/FileLogStore.java | 44 ++++++++++++----------
.../brooklyn/util/core/logbook/file/log-sample.txt | 2 +-
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/logbook/file/FileLogStore.java b/core/src/main/java/org/apache/brooklyn/util/core/logbook/file/FileLogStore.java
index c0fe838785..5857364ce1 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/logbook/file/FileLogStore.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/logbook/file/FileLogStore.java
@@ -247,6 +247,15 @@ public class FileLogStore implements LogStore {
return entry;
}
+ private static boolean entryMessageIsStartingTaskFromKnownTask(BrooklynLogEntry entry, Set<String> knownTasks) {
+ if (entry==null || entry.getMessage()==null || !entry.getMessage().startsWith("Starting task ")) return false;
+ String msg = entry.getMessage();
+ int fromTaskIndex = msg.lastIndexOf("from task ");
+ if (fromTaskIndex<0) return false;
+ String fromTask = Strings.getFirstWord(msg.substring(fromTaskIndex + 10));
+ return (knownTasks.contains(fromTask));
+ }
+
private static final boolean STARTING_TASK_MESSAGE_IS_ALWAYS_THE_FIRST_MESSAGE_FOR_THAT_TASK = true;
@Override
public Set<String> enumerateTaskIds(Task<?> parent, int maxTasks) {
@@ -262,25 +271,22 @@ public class FileLogStore implements LogStore {
try (Stream<String> stream = Files.lines(path)) {
stream.forEach(line -> {
BrooklynLogEntry entry = parseLogLine(line, lineCount);
- if (entry!=null && entry.getMessage()!=null && entry.getMessage().startsWith("Starting task ")) {
- if (current.stream().anyMatch(possibleParent -> entry.getMessage().endsWith(possibleParent)) || next.stream().anyMatch(possibleParent -> entry.getMessage().endsWith(possibleParent))) {
- String newTaskId = entry.getMessage();
- newTaskId = Strings.removeFromStart(newTaskId, "Starting task ");
- int nextWord = newTaskId.indexOf(' ');
- if (nextWord>0) {
- newTaskId = newTaskId.substring(0, nextWord);
- if (all.add(newTaskId)) {
- if (all.size()>=maxTasks) {
- return;
- }
-
- // this is a newly found task
- if (STARTING_TASK_MESSAGE_IS_ALWAYS_THE_FIRST_MESSAGE_FOR_THAT_TASK) {
- current.add(newTaskId);
- } else {
- // we don't actually need a multi-pass strategy
- next.add(newTaskId);
- }
+ if (entryMessageIsStartingTaskFromKnownTask(entry, current)) {
+ String newTaskId = entry.getMessage();
+ newTaskId = Strings.removeFromStart(newTaskId, "Starting task ");
+ int nextWord = newTaskId.indexOf(' ');
+ if (nextWord>0) {
+ newTaskId = newTaskId.substring(0, nextWord);
+ if (all.add(newTaskId)) {
+ if (all.size()>=maxTasks) {
+ return;
+ }
+
+ // this is a newly found task
+ current.add(newTaskId);
+ if (!STARTING_TASK_MESSAGE_IS_ALWAYS_THE_FIRST_MESSAGE_FOR_THAT_TASK) {
+ // we don't actually need a multi-pass strategy unless the above is true
+ next.add(newTaskId);
}
}
}
diff --git a/core/src/test/resources/brooklyn/util/core/logbook/file/log-sample.txt b/core/src/test/resources/brooklyn/util/core/logbook/file/log-sample.txt
index a6b86e32ef..108a3a7a76 100644
--- a/core/src/test/resources/brooklyn/util/core/logbook/file/log-sample.txt
+++ b/core/src/test/resources/brooklyn/util/core/logbook/file/log-sample.txt
@@ -28,5 +28,5 @@ org.osgi.service.component.ComponentException: The component name 'org.apache.br
2021-08-30T11:28:26,764Z CMeSRJNF-[l8442kq0zu,iffj68b370] INFO 237 i.c.b.t.c.AbstractToscaYamlConverter [ger-rhkc5jtA-351] for testing
2021-08-30T11:28:27,764Z CMeSRJNX-[l8442kq0zu,iffj68b370] INFO 237 i.c.b.t.c.AbstractToscaYamlConverter [ger-rhkc5jtA-351] for testing
2021-08-30T11:28:28,764Z CMeSRJNX-[l8442kq0zx,iffj68b370] WARN 237 i.c.b.t.c.AbstractToscaYamlConverter [ger-rhkc5jtA-351] key 'brooklyn.locations' not supported
-2021-08-30T11:28:54,464Z THGMmYiu-[l8442kq0zx,iffj68b370] DEBUG 282 o.a.b.x.x.BasicTask [ger-rhkc5jtA-360] Starting task THGMmYiu (...) on entity xxx from task CMeSRJNF
+2021-08-30T11:28:54,464Z THGMmYiu-[l8442kq0zx,iffj68b370] DEBUG 282 o.a.b.x.x.BasicTask [ger-rhkc5jtA-360] Starting task THGMmYiu (...) on entity xxx from task CMeSRJNF for user blah
2021-08-30T11:28:54,466Z THGMmYiu-[l8442kq0zx,iffj68b370] INFO 282 o.a.b.e.s.b.l.MachineLifecycleEffectorTasks [ger-rhkc5jtA-360] Starting ToscaComputeNodeEntityImpl{id=iffj68b370} on machine SshMachineLocation[cloudsoft-ubuntu:cloudsoft@135.181.244.108/135.181.244.108:22(id=dr6f7lah7i)]