Skip to content

Commit

Permalink
Revert "[api] collect instance configurations via API (#156)"
Browse files Browse the repository at this point in the history
This reverts commit c36514e.
  • Loading branch information
truthbk committed Sep 14, 2020
1 parent cbd0034 commit f36e09c
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 698 deletions.
30 changes: 9 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<java-dogstatsd-client.version>2.1.0</java-dogstatsd-client.version>
<jcommander.version>1.35</jcommander.version>
<log4j.version>1.2.17</log4j.version>
<jackson.version>2.10.0</jackson.version>
<gson.version>1.4</gson.version>
<snakeyaml.version>1.13</snakeyaml.version>
<!-- Note: using project checkstyle with AOSP style
find the default google java checkstyle config here -
Expand Down Expand Up @@ -92,27 +92,15 @@
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>com.datadoghq</groupId>
<artifactId>java-dogstatsd-client</artifactId>
<version>${java-dogstatsd-client.version}</version>
</dependency>
<dependency>
<groupId>com.datadoghq</groupId>
<artifactId>java-dogstatsd-client</artifactId>
<version>${java-dogstatsd-client.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<!-- Note: core-annotations version x.y.0 is generally compatible with
(identical to) version x.y.1, x.y.2, etc. -->
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
Expand Down
69 changes: 7 additions & 62 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
Expand Down Expand Up @@ -65,7 +64,6 @@ public class App {
private static final Charset UTF_8 = Charset.forName("UTF-8");

private static int loopCounter;
private int lastJsonConfigTs;
private HashMap<String, Object> adJsonConfigs;
private ConcurrentHashMap<String, YamlParser> configs;
private ConcurrentHashMap<String, YamlParser> adPipeConfigs =
Expand All @@ -78,7 +76,6 @@ public class App {
private TaskProcessor recoveryProcessor;

private AppConfig appConfig;
private HttpClient client;

/** Application constructor. */
public App(AppConfig appConfig) {
Expand Down Expand Up @@ -332,7 +329,7 @@ void start() {
// Main Loop that will periodically collect metrics from the JMX Server
FileInputStream adPipe = null;

if (appConfig.getAutoDiscoveryPipeEnabled()) {
if (appConfig.getAutoDiscoveryEnabled()) {
LOGGER.info("Auto Discovery enabled");
adPipe = newAutoDiscoveryPipe();
try {
Expand All @@ -351,11 +348,11 @@ void start() {
return;
}

if (adPipe == null && appConfig.getAutoDiscoveryPipeEnabled()) {
// any SD configs waiting in pipe?
if (adPipe == null && appConfig.getAutoDiscoveryEnabled()) {
// If SD is enabled and the pipe is not open, retry opening pipe
adPipe = newAutoDiscoveryPipe();
}
// any AutoDiscovery configs waiting?
try {
if (adPipe != null && adPipe.available() > 0) {
byte[] buffer = new byte[0];
Expand Down Expand Up @@ -386,10 +383,6 @@ void start() {
}
setReinit(processAutoDiscovery(buffer));
}

if (appConfig.remoteEnabled()) {
setReinit(getJsonConfigs());
}
} catch (IOException e) {
LOGGER.warn(
"Unable to read from pipe"
Expand All @@ -408,8 +401,7 @@ void start() {
doIteration();
} else {
LOGGER.warn("No instance could be initiated. Retrying initialization.");
lastJsonConfigTs = 0; // reset TS to get AC instances
appConfig.getStatus().flush();
appConfig.getStatus().flush(appConfig.getIPCPort());
configs = getConfigs(appConfig);
init(true);
}
Expand Down Expand Up @@ -560,8 +552,10 @@ public TaskStatusHandler invoke(
processFixedStatus(fixInstanceTasks, statuses);

// update with statuses
processStatus(fixInstanceTasks, statuses);
// REVERT: open question???
// processStatus(fixInstanceTasks, statuses);

appConfig.getStatus().flush(appConfig.getIPCPort());
} catch (Exception e) {
// NADA
}
Expand Down Expand Up @@ -612,11 +606,6 @@ public boolean addConfig(String name, YamlParser config) {
return true;
}

/** Adds a configuration to the auto-discovery HTTP collected configuration list (JSON). */
public boolean addJsonConfig(String name, String json) {
return false;
}

private ConcurrentHashMap<String, YamlParser> getConfigs(AppConfig config) {
ConcurrentHashMap<String, YamlParser> configs = new ConcurrentHashMap<String, YamlParser>();

Expand Down Expand Up @@ -684,50 +673,6 @@ private void loadResourceConfigs(
}
}

private boolean getJsonConfigs() {
HttpClient.HttpResponse response;
boolean update = false;

if (this.client == null) {
return update;
}

try {
String uripath = "agent/jmx/configs?timestamp=" + lastJsonConfigTs;
response = client.request("GET", "", uripath);
if (!response.isResponse2xx()) {
LOGGER.warn(
"Failed collecting JSON configs: ["
+ response.getResponseCode()
+ "] "
+ response.getResponseBody());
return update;
} else if (response.getResponseCode() == 204) {
LOGGER.debug("No configuration changes...");
return update;
}

InputStream jsonInputStream = IOUtils.toInputStream(response.getResponseBody(), UTF_8);
JsonParser parser = new JsonParser(jsonInputStream);
int timestamp = ((Integer) parser.getJsonTimestamp()).intValue();
if (timestamp > lastJsonConfigTs) {
adJsonConfigs = (HashMap<String, Object>) parser.getJsonConfigs();
lastJsonConfigTs = timestamp;
update = true;
LOGGER.info("update is in order - updating timestamp: " + lastJsonConfigTs);
for (String checkName : adJsonConfigs.keySet()) {
LOGGER.debug("received config for check '" + checkName + "'");
}
}
} catch (JsonProcessingException e) {
LOGGER.error("error processing JSON response: " + e);
} catch (IOException e) {
LOGGER.error("unable to collect remote JMX configs: " + e);
}

return update;
}

private void reportStatus(
AppConfig appConfig,
Reporter reporter,
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.datadog.jmxfetch.converter.ExitWatcherConverter;
import org.datadog.jmxfetch.converter.ReporterConverter;
import org.datadog.jmxfetch.converter.StatusConverter;
import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.reporter.ReporterFactory;
Expand Down Expand Up @@ -150,7 +151,7 @@ public class AppConfig {
description =
"Absolute path of the status file. (default to null = no status file written)",
required = false)
private String statusLocation;
private Status status = new Status();

@Parameter(
names = {"--exit_file_location", "-e"},
Expand All @@ -169,12 +170,6 @@ public class AppConfig {
required = true)
private List<String> action = null;

@Parameter(
names = {"--ipc_host", "-H"},
description = "IPC host",
required = false)
private String ipcHost;

@Parameter(
names = {"--ipc_port", "-I"},
description = "IPC port",
Expand All @@ -200,18 +195,11 @@ public boolean updateStatus() {
if (statusLocation != null) {
status = new Status(statusLocation);
return true;
} else if (ipcHost != null && ipcPort > 0) {
status = new Status(ipcHost, ipcPort);
return true;
}

return false;
}

public boolean remoteEnabled() {
return (ipcHost != null && ipcPort > 0);
}

public String getStatusLocation() {
return this.statusLocation;
}
Expand Down Expand Up @@ -264,7 +252,7 @@ public int getIpcPort() {
return ipcPort;
}

public boolean getAutoDiscoveryPipeEnabled() {
public boolean getAutoDiscoveryEnabled() {
return adEnabled;
}

Expand Down
143 changes: 0 additions & 143 deletions src/main/java/org/datadog/jmxfetch/HttpClient.java

This file was deleted.

Loading

0 comments on commit f36e09c

Please sign in to comment.