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

Support Diagnostics Tool consumed as a Java library #485

Closed
9 tasks done
brunofarache opened this issue Apr 26, 2021 · 6 comments
Closed
9 tasks done

Support Diagnostics Tool consumed as a Java library #485

brunofarache opened this issue Apr 26, 2021 · 6 comments

Comments

@brunofarache
Copy link
Contributor

brunofarache commented Apr 26, 2021

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:

@CBlaisure
Copy link

Grooming notes:
Support Development to investigate github actions to deploy Maven automatically.

@shasts
Copy link
Member

shasts commented May 4, 2021

@brunofarache
Just so you know, we have a few internal libraries published in our artifactory.

@pickypg
Copy link
Member

pickypg commented Jul 13, 2021

I was able to get the person with Maven Central access to give me approval to create packages in the co.elastic.* groupId. They were on vacation until today. Now we wait for Sonatype.

https://issues.sonatype.org/browse/OSSRH-70696

They literally gave me permissions as I was posting this. I'll be trying it out soon.

@pickypg
Copy link
Member

pickypg commented Jul 20, 2021

@brunofarache I was able to get this deployed to Maven Central: version 8.2.0. Gradle dependency:

dependencies {
  compile 'co.elastic.support:diagnostics:8.2.0'
}

@pickypg
Copy link
Member

pickypg commented Jul 21, 2021

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'
}

@brunofarache
Copy link
Contributor Author

Awesome, thanks @pickypg. cc @gmarz

@zube zube bot removed the [zube]: Done label Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants