Skip to content

health-report: link to major.minor-versioned help docs on 9.0+ #17626

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 35 additions & 8 deletions logstash-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,49 @@ artifacts {
}
}

task generateVersionInfoResources(type: DefaultTask) {
ext.outDir = layout.buildDirectory.dir("generated-resources/version-info").get()

task generateHealthcheckResources(type: DefaultTask) {
Directory outDir = layout.buildDirectory.dir("generated-resources/main/org/logstash/health").get()
File outFile = outDir.file("help.url").asFile

// builds are considered "snapshot" unless the env has
// either `WORKFLOW_TYPE=staging` OR `RELEASE=1`
boolean isSnapshot = !("${System.env.WORKFLOW_TYPE}" == "staging" || "${System.env.RELEASE}" == "1")

inputs.property("version-info:logstash-core", logstashCoreVersion)
outputs.dir(ext.outDir)
inputs.property("BUILD_ENV:IS_SNAPSHOT", isSnapshot)
outputs.dir outDir

// don't reuse outputs if they are missing
outputs.upToDateWhen { outFile.exists() }

doLast {
mkdir outDir;
def resourceFile = outDir.file('version-info.properties').asFile
resourceFile.text = "logstash-core: ${logstashCoreVersion}"
def (majorVersion, minorVersion, patchVersion) = logstashCoreVersion.tokenize('.').subList(0,3)

String versionAnchor;
if (isSnapshot && patchVersion == "0") {
// snapshot builds on unreleased minors
if (majorVersion == "9") {
versionAnchor = "master"
} else {
versionAnchor = "${majorVersion}.x"
}
} else {
// otherwise we target MAJOR.MINOR
versionAnchor = "${majorVersion}.${minorVersion}"
}
def helpUrl = "https://www.elastic.co/guide/en/logstash/${versionAnchor}/"

mkdir outDir
outFile.text = helpUrl

logger.info("Health API HelpUrl base: FOR(${logstashCoreVersion}${isSnapshot ? "-SNAPSHOT" : ""}) WRITE(${helpUrl}) TO(${outFile.path})")
}
}
sourceSets {
main { output.dir(generateVersionInfoResources.outputs.files) }
main { resources { output.dir(generateHealthcheckResources.outputs.files) } }
}
processResources.dependsOn generateVersionInfoResources
processResources.dependsOn generateHealthcheckResources

configurations {
provided
Expand Down
19 changes: 0 additions & 19 deletions logstash-core/src/main/java/org/logstash/Logstash.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@
*/
public final class Logstash implements Runnable, AutoCloseable {

public static final String VERSION_FULL;
public static final String VERSION_MAJOR;
public static final String VERSION_MINOR;
public static final String VERSION_PATCH;

static {
final Properties properties = new Properties();
try {
properties.load(Logstash.class.getResourceAsStream("/version-info.properties"));
VERSION_FULL = properties.getProperty("logstash-core");
final String[] versions = VERSION_FULL.split("\\.");
VERSION_MAJOR = versions[0];
VERSION_MINOR = versions[1];
VERSION_PATCH = versions[2];
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static final Logger LOGGER = LogManager.getLogger(Logstash.class);

/**
Expand Down
19 changes: 13 additions & 6 deletions logstash-core/src/main/java/org/logstash/health/HelpUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
*/
package org.logstash.health;

import com.google.common.io.Resources;
import org.logstash.Logstash;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

public class HelpUrl {
static final String BASE_URL;
static {
final String versionAnchor;
if (Integer.parseInt(Logstash.VERSION_MAJOR) >= 9) {
versionAnchor = "master";
} else {
versionAnchor = String.format("%s.%s", Logstash.VERSION_MAJOR, Logstash.VERSION_MINOR);
try {
final URL url = HelpUrl.class.getResource("/help.url");
if (url == null) {
throw new IllegalStateException("Unable to locate 'help.url' resource");
}
BASE_URL = Resources.toString(url, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new IllegalStateException("Failed to load help.url resource", e);
}
BASE_URL = String.format("https://www.elastic.co/guide/en/logstash/%s/", versionAnchor);
}

public HelpUrl(final String page) {
Expand Down