Skip to content

Commit

Permalink
Merge pull request #321 from richardstartin/rgs/remove-jackson-databind
Browse files Browse the repository at this point in the history
Replace jackson databind with lightweight jackson-jr-objects
richardstartin authored Sep 3, 2020

Verified

This commit was signed with the committer’s verified signature.
derekcollison Derek Collison
2 parents 271bbeb + ec67741 commit d7e2966
Showing 4 changed files with 10 additions and 33 deletions.
16 changes: 2 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -94,20 +94,8 @@
<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>
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-objects</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
7 changes: 2 additions & 5 deletions src/main/java/org/datadog/jmxfetch/JsonParser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.datadog.jmxfetch;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jr.ob.JSON;

import java.io.IOException;
import java.io.InputStream;
@@ -15,9 +14,7 @@ class JsonParser {
private Map<String, Object> parsedJson;

public JsonParser(InputStream jsonInputStream) throws IOException {
ObjectMapper mapper = new ObjectMapper();
InputStreamReader jsonInputStreamReader = new InputStreamReader(jsonInputStream);
parsedJson = mapper.readValue(jsonInputStreamReader, new TypeReference<Map>() {});
parsedJson = JSON.std.mapFrom(new InputStreamReader(jsonInputStream));
}

public JsonParser(JsonParser other) {
10 changes: 4 additions & 6 deletions src/main/java/org/datadog/jmxfetch/Status.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.datadog.jmxfetch;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jr.ob.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -22,7 +22,6 @@ public class Status {
private static final String FAILED_CHECKS = "failed_checks";
private static final String API_STATUS_PATH = "agent/jmx/status";
private Map<String, Object> instanceStats;
private ObjectMapper mapper;
private String statusFileLocation;
private HttpClient client;
private boolean isEnabled;
@@ -34,7 +33,6 @@ public Status() {

/** Status constructor for remote configuration host. */
public Status(String host, int port) {
mapper = new ObjectMapper();
client = new HttpClient(host, port, false);
configure(null, host, port);
}
@@ -122,11 +120,11 @@ private String generateYaml() {
return yaml.dump(status);
}

private String generateJson() throws JsonProcessingException {
private String generateJson() throws IOException {
Map<String, Object> status = new HashMap<String, Object>();
status.put("timestamp", System.currentTimeMillis());
status.put("checks", this.instanceStats);
return mapper.writeValueAsString(status);
return JSON.std.asString(status);
}

/** Flushes current status. */
10 changes: 2 additions & 8 deletions src/main/java/org/datadog/jmxfetch/reporter/JsonReporter.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.datadog.jmxfetch.reporter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jr.ob.JSON;
import lombok.extern.slf4j.Slf4j;

import org.datadog.jmxfetch.Instance;
import org.datadog.jmxfetch.JmxAttribute;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -61,15 +59,11 @@ public void doSendServiceCheck(
series.add(serie);

System.out.println("=== JSON ===");
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
StringWriter writer = new StringWriter();
try {
mapper.writeValue(writer, series);
System.out.println(JSON.std.with(JSON.Feature.PRETTY_PRINT_OUTPUT).asString(series));
} catch (IOException e) {
log.error("Couln't produce JSON output");
}
System.out.println(writer.toString());
metrics.clear();
}

0 comments on commit d7e2966

Please sign in to comment.