-
Notifications
You must be signed in to change notification settings - Fork 156
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
Support Diagnostics Tool consumed as a Java library #485
Comments
Grooming notes: |
@brunofarache |
I was able to get the person with Maven Central access to give me approval to create packages in the https://issues.sonatype.org/browse/OSSRH-70696 They literally gave me permissions as I was posting this. I'll be trying it out soon. |
@brunofarache I was able to get this deployed to Maven Central: version 8.2.0. Gradle dependency:
|
I was able to confirm this works locally with my own cluster: // ./src/main/java/org/elastic/Test.java
package org.elastic;
import co.elastic.support.Constants;
import co.elastic.support.diagnostics.DiagConfig;
import co.elastic.support.diagnostics.DiagnosticInputs;
import co.elastic.support.diagnostics.DiagnosticService;
import java.util.HashMap;
public class Test {
private static DiagConfig createDiagConfig() {
final var map = new HashMap<String, Integer>();
map.put("connectTimeout", 60);
map.put("requestTimeout", 60);
map.put("socketTimeout", 120);
map.put("maxTotalConn", 100);
map.put("maxConnPerRoute", 10);
final var logMap = new HashMap<String, Integer>();
logMap.put("maxGcLogs", 0);
logMap.put("maxLogs", 0);
final var config = new HashMap<String, Object>();
config.put("docker-container", new HashMap<String, String>());
config.put("docker-container-ids", "");
config.put("docker-executable-location", "");
config.put("docker-global", new HashMap<String, String>());
config.put("rest-config", map);
config.put("call-retries", 3);
config.put("pause-retries", 5000);
config.put("log-settings", logMap);
return new DiagConfig(config);
}
private static DiagnosticInputs createDiagnosticInputs() {
final var inputs = new DiagnosticInputs();
inputs.bypassDiagVerify = true;
inputs.isSudo = true;
inputs.archiveType = "zip";
// inputs.outputDir = outputDir; // by not setting this, it writes in pwd
inputs.scheme = "https";
inputs.isSsl = true;
inputs.host = "my-host";
inputs.port = 9243;
inputs.user = "elastic";
inputs.password = "my_password";
inputs.diagType = Constants.api;
return inputs;
}
public static void main(String[] args) {
System.out.println("Running diagnostic...");
try {
final var service = new DiagnosticService();
service.exec(Test.createDiagnosticInputs(), Test.createDiagConfig());
} catch (Exception e) {
System.out.println("Failed to run diagnostic: " + e.getMessage());
System.exit(1);
}
System.out.println("Done running diagnostic");
System.exit(0);
}
} Gradle build // ./build.gradle
apply plugin: 'application'
apply plugin: 'java'
mainClassName = 'org.elastic.Test'
sourceCompatibility = 11
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
compile 'co.elastic.support:diagnostics:8.2.0'
} |
The Support Diagnostics Tool was designed to be used from the command line.
The objective of this issue is to also make it possible to consume this tool as a Java library.
Here are the changes to make that happen:
*.yaml
config files in released jars. Instead of distributing*.yaml
separately from the jar file, it would be better to include them in the binary, this way, developers can just drop the jar in their projects without having to include a separateconfig
folder in the classpath. (Include *.yml files in jar file #488)DiagnosticService#exec
should returnjava.io.File
instead ofvoid
. This makes it easier for callers to know where the zip file was saved, otherwise they would need to list which files are present in theoutputDir
after the tool is finished. (DiagnosticService and ScrubService should return File and throw checked Exception #486)DiagnosticService#exec
should throwDiagnosticException
instead of logging and swallowing errors.DiagnosticException
is aRuntimeException
which makes harder for consumers be aware of errors and catch them properly. (DiagnosticService and ScrubService should return File and throw checked Exception #486)OutputStream
correctly to avoid memory leaks. I noticed someOutputStream
instances are not being closed properly, while that's fine when running the tool in the command line, it may leak memory when being used many times by the same process. (Close streams properly #487)diagnostics.log
.The text was updated successfully, but these errors were encountered: