From 19288304d7e6a29678f3cfc7aa42c53a50bbc8c3 Mon Sep 17 00:00:00 2001 From: Alexis Varsava Date: Thu, 27 Jun 2024 10:18:24 -0400 Subject: [PATCH 1/4] stdout logger --- docs/plugin-stdout.md | 19 ++++++++ install-pom.xml | 5 +++ .../oicr/gsi/shesmu/jira/JiraConnection.java | 3 +- plugin-stdout/pom.xml | 33 ++++++++++++++ .../oicr/gsi/shesmu/stdout/Configuration.java | 5 +++ .../oicr/gsi/shesmu/stdout/StdoutPlugin.java | 45 +++++++++++++++++++ .../gsi/shesmu/stdout/StdoutPluginType.java | 18 ++++++++ plugin-stdout/src/main/java/module-info.java | 13 ++++++ pom.xml | 1 + 9 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 docs/plugin-stdout.md create mode 100644 plugin-stdout/pom.xml create mode 100644 plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/Configuration.java create mode 100644 plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPlugin.java create mode 100644 plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPluginType.java create mode 100644 plugin-stdout/src/main/java/module-info.java diff --git a/docs/plugin-stdout.md b/docs/plugin-stdout.md new file mode 100644 index 000000000..bc3ee7daa --- /dev/null +++ b/docs/plugin-stdout.md @@ -0,0 +1,19 @@ +# Standard Output Logger +The Standard Output Logger plugin provides an alternative to the [Loki plugin](plugin-loki.md) +which is useful in debugging scenarios where sending a development environment's logging output to Loki +would be too noisy. **This plugin is not meant for production use.** + +To configure the Standard Output Logger, create a file ending with `.stdout` as follows: + + { + "level": "INFO" + } + +The `"level"` property is one of: +1. FATAL +2. ERROR +3. WARN +4. INFO +5. DEBUG + +All messages at or above the setting in severity will be logged to standard output. \ No newline at end of file diff --git a/install-pom.xml b/install-pom.xml index d0615138e..9972f2d59 100644 --- a/install-pom.xml +++ b/install-pom.xml @@ -104,6 +104,11 @@ shesmu-plugin-sftp ${VERSION} + + ca.on.oicr.gsi + shesmu-plugin-stdout + ${VERSION} + ca.on.oicr.gsi shesmu-plugin-tsv diff --git a/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java b/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java index 26a76d61b..cf4f5debf 100644 --- a/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java +++ b/plugin-jira/src/main/java/ca/on/oicr/gsi/shesmu/jira/JiraConnection.java @@ -475,7 +475,8 @@ boolean transition( .append(commentResult.body()); Map lokiLabels = new HashMap<>(); lokiLabels.put("issue", issue.getKey()); - ((Definer) definer).log(errorBuilder.toString(), lokiLabels); + ((Definer) definer) + .log(errorBuilder.toString(), LogLevel.ERROR, lokiLabels); } return isGood; } diff --git a/plugin-stdout/pom.xml b/plugin-stdout/pom.xml new file mode 100644 index 000000000..35e64fe4d --- /dev/null +++ b/plugin-stdout/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + ca.on.oicr.gsi + shesmu + 1.33.1-SNAPSHOT + + shesmu-plugin-stdout + jar + Shesmu Decision-Action Server - Standard Output Logger + https://github.com/oicr-gsi/shesmu + + UTF-8 + + + + ca.on.oicr.gsi + shesmu-pluginapi + provided + + + io.prometheus + simpleclient + provided + + + + shesmu-plugin-stdout + + \ No newline at end of file diff --git a/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/Configuration.java b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/Configuration.java new file mode 100644 index 000000000..48c170108 --- /dev/null +++ b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/Configuration.java @@ -0,0 +1,5 @@ +package ca.on.oicr.gsi.shesmu.stdout; + +import ca.on.oicr.gsi.shesmu.plugin.LogLevel; + +public record Configuration(LogLevel level) {} diff --git a/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPlugin.java b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPlugin.java new file mode 100644 index 000000000..7eac69ed7 --- /dev/null +++ b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPlugin.java @@ -0,0 +1,45 @@ +package ca.on.oicr.gsi.shesmu.stdout; + +import ca.on.oicr.gsi.shesmu.plugin.Definer; +import ca.on.oicr.gsi.shesmu.plugin.LogLevel; +import ca.on.oicr.gsi.shesmu.plugin.json.JsonPluginFile; +import ca.on.oicr.gsi.status.SectionRenderer; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.nio.file.Path; +import java.util.Map; +import java.util.Optional; + +public class StdoutPlugin extends JsonPluginFile { + private final Definer definer; + private static final ObjectMapper MAPPER = new ObjectMapper(); + private Optional configuration = Optional.empty(); + + public StdoutPlugin(Path fileName, String instanceName, Definer definer) { + super(fileName, instanceName, MAPPER, Configuration.class); + this.definer = definer; + } + + @Override + public void configuration(SectionRenderer renderer) { + configuration.ifPresent(value -> renderer.line("Level", value.level().toString())); + } + + @Override + protected Optional update(Configuration value) { + this.configuration = Optional.of(value); + return Optional.empty(); + } + + @Override + public synchronized void writeLog( + String message, LogLevel level, Map attributes) { + if (level.compareTo(this.configuration.get().level()) >= 0) { + StringBuilder writeOut = new StringBuilder(); + writeOut.append(message); + for (Map.Entry e : attributes.entrySet()) { + writeOut.append(", ").append(e.getKey()).append(": ").append(e.getValue()); + } + System.out.println(writeOut); + } + } +} diff --git a/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPluginType.java b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPluginType.java new file mode 100644 index 000000000..2be62f219 --- /dev/null +++ b/plugin-stdout/src/main/java/ca/on/oicr/gsi/shesmu/stdout/StdoutPluginType.java @@ -0,0 +1,18 @@ +package ca.on.oicr.gsi.shesmu.stdout; + +import ca.on.oicr.gsi.shesmu.plugin.Definer; +import ca.on.oicr.gsi.shesmu.plugin.PluginFileType; +import java.lang.invoke.MethodHandles; +import java.nio.file.Path; + +/** Allows logging through the Definer to stdout */ +public class StdoutPluginType extends PluginFileType { + public StdoutPluginType() { + super(MethodHandles.lookup(), StdoutPlugin.class, ".stdout", "stdout"); + } + + @Override + public StdoutPlugin create(Path filePath, String instanceName, Definer definer) { + return new StdoutPlugin(filePath, instanceName, definer); + } +} diff --git a/plugin-stdout/src/main/java/module-info.java b/plugin-stdout/src/main/java/module-info.java new file mode 100644 index 000000000..0df240080 --- /dev/null +++ b/plugin-stdout/src/main/java/module-info.java @@ -0,0 +1,13 @@ +import ca.on.oicr.gsi.shesmu.plugin.PluginFileType; +import ca.on.oicr.gsi.shesmu.stdout.StdoutPluginType; + +module plugin.stdout { + exports ca.on.oicr.gsi.shesmu.stdout; + + requires ca.on.oicr.gsi.shesmu; + requires ca.on.oicr.gsi.serverutils; + requires com.fasterxml.jackson.databind; + + provides PluginFileType with + StdoutPluginType; +} diff --git a/pom.xml b/pom.xml index 9abf8b599..14c9dd51f 100644 --- a/pom.xml +++ b/pom.xml @@ -180,6 +180,7 @@ plugin-prometheus plugin-ratelimit plugin-sftp + plugin-stdout plugin-tsv plugin-vidarr maintenance-editor From 677975f3a7cb719775ef126787a2d00cd1479a8b Mon Sep 17 00:00:00 2001 From: Alexis Varsava Date: Thu, 27 Jun 2024 14:01:08 -0400 Subject: [PATCH 2/4] Correct formatting error --- docs/plugin-loki.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugin-loki.md b/docs/plugin-loki.md index 3352ba7c7..07001cab3 100644 --- a/docs/plugin-loki.md +++ b/docs/plugin-loki.md @@ -8,7 +8,7 @@ ending `.loki` with the following: "labels": { "environment": "foo" }, - "level": INFO + "level": "INFO" } The `"url"` property is the URL of the Loki server to push logs into. The From 33c72706727d58b84f5f5e3f6e6d0ce0c66766a2 Mon Sep 17 00:00:00 2001 From: Alexis Varsava Date: Thu, 27 Jun 2024 14:01:50 -0400 Subject: [PATCH 3/4] changelog --- changes/add_stdout.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/add_stdout.md diff --git a/changes/add_stdout.md b/changes/add_stdout.md new file mode 100644 index 000000000..64664de89 --- /dev/null +++ b/changes/add_stdout.md @@ -0,0 +1,2 @@ +Add Standard Output Logger as debugging alternative to Loki plugin. + From ce1a22045200b4121e18d283cabffd80a687665c Mon Sep 17 00:00:00 2001 From: Alexis Varsava Date: Thu, 27 Jun 2024 14:05:38 -0400 Subject: [PATCH 4/4] add stdout plugin to index listing --- docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.md b/docs/index.md index 611e11269..150045ba3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -73,6 +73,7 @@ information about how to extend the system. The plugins available are: - [Token Bucket Throttling](plugin-ratelimit.md) - [Run Scanner](plugin-runscanner.md) - [SFTP servers](plugin-sftp.md) +- [Standard Output Logger](plugin-stdout.md) - [Tab-separated files](plugin-tsv.md) - [Víðarr](plugin-vidarr.md)