Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GP-4352] Standard Output Logger plugin #1309

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/add_stdout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add Standard Output Logger as debugging alternative to Loki plugin.

1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/plugin-loki.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions docs/plugin-stdout.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions install-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
<artifactId>shesmu-plugin-sftp</artifactId>
<version>${VERSION}</version>
</dependency>
<dependency>
<groupId>ca.on.oicr.gsi</groupId>
<artifactId>shesmu-plugin-stdout</artifactId>
<version>${VERSION}</version>
</dependency>
<dependency>
<groupId>ca.on.oicr.gsi</groupId>
<artifactId>shesmu-plugin-tsv</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ boolean transition(
.append(commentResult.body());
Map<String, String> lokiLabels = new HashMap<>();
lokiLabels.put("issue", issue.getKey());
((Definer<JiraConnection>) definer).log(errorBuilder.toString(), lokiLabels);
((Definer<JiraConnection>) definer)
.log(errorBuilder.toString(), LogLevel.ERROR, lokiLabels);
}
return isGood;
}
Expand Down
33 changes: 33 additions & 0 deletions plugin-stdout/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ca.on.oicr.gsi</groupId>
<artifactId>shesmu</artifactId>
<version>1.33.1-SNAPSHOT</version>
</parent>
<artifactId>shesmu-plugin-stdout</artifactId>
<packaging>jar</packaging>
<name>Shesmu Decision-Action Server - Standard Output Logger</name>
<url>https://github.com/oicr-gsi/shesmu</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ca.on.oicr.gsi</groupId>
<artifactId>shesmu-pluginapi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>shesmu-plugin-stdout</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ca.on.oicr.gsi.shesmu.stdout;

import ca.on.oicr.gsi.shesmu.plugin.LogLevel;

public record Configuration(LogLevel level) {}
Original file line number Diff line number Diff line change
@@ -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<Configuration> {
private final Definer<StdoutPlugin> definer;
private static final ObjectMapper MAPPER = new ObjectMapper();
private Optional<Configuration> configuration = Optional.empty();

public StdoutPlugin(Path fileName, String instanceName, Definer<StdoutPlugin> 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<Integer> update(Configuration value) {
this.configuration = Optional.of(value);
return Optional.empty();
}

@Override
public synchronized void writeLog(
String message, LogLevel level, Map<String, String> attributes) {
if (level.compareTo(this.configuration.get().level()) >= 0) {
StringBuilder writeOut = new StringBuilder();
writeOut.append(message);
for (Map.Entry<String, String> e : attributes.entrySet()) {
writeOut.append(", ").append(e.getKey()).append(": ").append(e.getValue());
}
System.out.println(writeOut);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<StdoutPlugin> {
public StdoutPluginType() {
super(MethodHandles.lookup(), StdoutPlugin.class, ".stdout", "stdout");
}

@Override
public StdoutPlugin create(Path filePath, String instanceName, Definer<StdoutPlugin> definer) {
return new StdoutPlugin(filePath, instanceName, definer);
}
}
13 changes: 13 additions & 0 deletions plugin-stdout/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<module>plugin-prometheus</module>
<module>plugin-ratelimit</module>
<module>plugin-sftp</module>
<module>plugin-stdout</module>
<module>plugin-tsv</module>
<module>plugin-vidarr</module>
<module>maintenance-editor</module>
Expand Down
Loading