Merge pull request #105 from DataDog/gpolaert/msgpack
Send traces as msgpack instead of json
This commit is contained in:
commit
797332caeb
|
@ -16,7 +16,6 @@ whitelistedInstructionClasses += whitelistedBranchClasses += [
|
||||||
'com.datadoghq.trace.DDTags',
|
'com.datadoghq.trace.DDTags',
|
||||||
'com.datadoghq.trace.DDTraceInfo',
|
'com.datadoghq.trace.DDTraceInfo',
|
||||||
'com.datadoghq.trace.util.Clock',
|
'com.datadoghq.trace.util.Clock',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -29,6 +28,7 @@ dependencies {
|
||||||
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.8.8'
|
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.8.8'
|
||||||
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
|
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
|
||||||
compile group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc3'
|
compile group: 'com.google.auto.service', name: 'auto-service', version: '1.0-rc3'
|
||||||
|
compile group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.8.13'
|
||||||
|
|
||||||
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,15 @@ package com.datadoghq.trace.writer;
|
||||||
import com.datadoghq.trace.DDBaseSpan;
|
import com.datadoghq.trace.DDBaseSpan;
|
||||||
import com.datadoghq.trace.DDTraceInfo;
|
import com.datadoghq.trace.DDTraceInfo;
|
||||||
import com.datadoghq.trace.Service;
|
import com.datadoghq.trace.Service;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.msgpack.jackson.dataformat.MessagePackFactory;
|
||||||
|
|
||||||
/** The API pointing to a DD agent */
|
/** The API pointing to a DD agent */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -24,8 +23,7 @@ public class DDApi {
|
||||||
private final String tracesEndpoint;
|
private final String tracesEndpoint;
|
||||||
private final String servicesEndpoint;
|
private final String servicesEndpoint;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
|
||||||
private final JsonFactory jsonFactory = objectMapper.getFactory();
|
|
||||||
|
|
||||||
public DDApi(final String host, final int port) {
|
public DDApi(final String host, final int port) {
|
||||||
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
|
this.tracesEndpoint = "http://" + host + ":" + port + TRACES_ENDPOINT;
|
||||||
|
@ -72,7 +70,6 @@ public class DDApi {
|
||||||
/**
|
/**
|
||||||
* PUT to an endpoint the provided JSON content
|
* PUT to an endpoint the provided JSON content
|
||||||
*
|
*
|
||||||
* @param endpoint
|
|
||||||
* @param content
|
* @param content
|
||||||
* @return the status code
|
* @return the status code
|
||||||
*/
|
*/
|
||||||
|
@ -86,11 +83,10 @@ public class DDApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
|
final OutputStream out = httpCon.getOutputStream();
|
||||||
final JsonGenerator jsonGen = jsonFactory.createGenerator(out);
|
objectMapper.writeValue(out, content);
|
||||||
objectMapper.writeValue(jsonGen, content);
|
out.flush();
|
||||||
jsonGen.flush();
|
out.close();
|
||||||
jsonGen.close();
|
|
||||||
final int responseCode = httpCon.getResponseCode();
|
final int responseCode = httpCon.getResponseCode();
|
||||||
if (responseCode == 200) {
|
if (responseCode == 200) {
|
||||||
log.debug("Sent the payload to the DD agent.");
|
log.debug("Sent the payload to the DD agent.");
|
||||||
|
@ -113,7 +109,7 @@ public class DDApi {
|
||||||
httpCon = (HttpURLConnection) url.openConnection();
|
httpCon = (HttpURLConnection) url.openConnection();
|
||||||
httpCon.setDoOutput(true);
|
httpCon.setDoOutput(true);
|
||||||
httpCon.setRequestMethod("PUT");
|
httpCon.setRequestMethod("PUT");
|
||||||
httpCon.setRequestProperty("Content-Type", "application/json");
|
httpCon.setRequestProperty("Content-Type", "application/msgpack");
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
|
httpCon.setRequestProperty("Datadog-Meta-Lang", "java");
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTraceInfo.JAVA_VERSION);
|
httpCon.setRequestProperty("Datadog-Meta-Lang-Version", DDTraceInfo.JAVA_VERSION);
|
||||||
httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
|
httpCon.setRequestProperty("Datadog-Meta-Lang-Interpreter", DDTraceInfo.JAVA_VM_NAME);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.datadoghq.trace.Service
|
||||||
import com.datadoghq.trace.SpanFactory
|
import com.datadoghq.trace.SpanFactory
|
||||||
import com.fasterxml.jackson.core.type.TypeReference
|
import com.fasterxml.jackson.core.type.TypeReference
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import org.msgpack.jackson.dataformat.MessagePackFactory
|
||||||
import ratpack.http.Headers
|
import ratpack.http.Headers
|
||||||
import ratpack.http.MediaType
|
import ratpack.http.MediaType
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
|
@ -11,10 +12,9 @@ import spock.lang.Specification
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
import static ratpack.groovy.test.embed.GroovyEmbeddedApp.ratpack
|
import static ratpack.groovy.test.embed.GroovyEmbeddedApp.ratpack
|
||||||
import static ratpack.http.MediaType.APPLICATION_JSON
|
|
||||||
|
|
||||||
class DDApiTest extends Specification {
|
class DDApiTest extends Specification {
|
||||||
static mapper = new ObjectMapper()
|
static mapper = new ObjectMapper(new MessagePackFactory())
|
||||||
|
|
||||||
def "sending an empty list of traces returns no errors"() {
|
def "sending an empty list of traces returns no errors"() {
|
||||||
setup:
|
setup:
|
||||||
|
@ -52,18 +52,18 @@ class DDApiTest extends Specification {
|
||||||
agent.close()
|
agent.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
def "content is sent as JSON"() {
|
def "content is sent as MSGPACK"() {
|
||||||
setup:
|
setup:
|
||||||
def requestContentType = new AtomicReference<MediaType>()
|
def requestContentType = new AtomicReference<MediaType>()
|
||||||
def requestHeaders = new AtomicReference<Headers>()
|
def requestHeaders = new AtomicReference<Headers>()
|
||||||
def requestBody = new AtomicReference<String>()
|
def requestBody = new AtomicReference<byte[]>()
|
||||||
def agent = ratpack {
|
def agent = ratpack {
|
||||||
handlers {
|
handlers {
|
||||||
put("v0.3/traces") {
|
put("v0.3/traces") {
|
||||||
requestContentType.set(request.contentType)
|
requestContentType.set(request.contentType)
|
||||||
requestHeaders.set(request.headers)
|
requestHeaders.set(request.headers)
|
||||||
request.body.then {
|
request.body.then {
|
||||||
requestBody.set(it.text)
|
requestBody.set(it.bytes)
|
||||||
response.send()
|
response.send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class DDApiTest extends Specification {
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
client.sendTraces(traces)
|
client.sendTraces(traces)
|
||||||
requestContentType.get().type == APPLICATION_JSON
|
requestContentType.get().type == "application/msgpack"
|
||||||
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
|
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
|
||||||
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
|
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
|
||||||
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
|
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
|
||||||
|
@ -151,18 +151,18 @@ class DDApiTest extends Specification {
|
||||||
agent.close()
|
agent.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
def "services content is sent as JSON"() {
|
def "services content is sent as MSGPACK"() {
|
||||||
setup:
|
setup:
|
||||||
def requestContentType = new AtomicReference<MediaType>()
|
def requestContentType = new AtomicReference<MediaType>()
|
||||||
def requestHeaders = new AtomicReference<Headers>()
|
def requestHeaders = new AtomicReference<Headers>()
|
||||||
def requestBody = new AtomicReference<String>()
|
def requestBody = new AtomicReference<byte[]>()
|
||||||
def agent = ratpack {
|
def agent = ratpack {
|
||||||
handlers {
|
handlers {
|
||||||
put("v0.3/services") {
|
put("v0.3/services") {
|
||||||
requestContentType.set(request.contentType)
|
requestContentType.set(request.contentType)
|
||||||
requestHeaders.set(request.headers)
|
requestHeaders.set(request.headers)
|
||||||
request.body.then {
|
request.body.then {
|
||||||
requestBody.set(it.text)
|
requestBody.set(it.bytes)
|
||||||
response.send()
|
response.send()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ class DDApiTest extends Specification {
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
client.sendServices(services)
|
client.sendServices(services)
|
||||||
requestContentType.get().type == APPLICATION_JSON
|
requestContentType.get().type == "application/msgpack"
|
||||||
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
|
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
|
||||||
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
|
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
|
||||||
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
|
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
|
||||||
|
@ -191,11 +191,11 @@ class DDApiTest extends Specification {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<TreeMap<String, Object>> convertList(String json) {
|
static List<TreeMap<String, Object>> convertList(byte[] bytes) {
|
||||||
return mapper.readValue(json, new TypeReference<List<TreeMap<String, Object>>>() {})
|
return mapper.readValue(bytes, new TypeReference<List<TreeMap<String, Object>>>() {})
|
||||||
}
|
}
|
||||||
|
|
||||||
static TreeMap<String, Object> convertMap(String json) {
|
static TreeMap<String, Object> convertMap(byte[] bytes) {
|
||||||
return mapper.readValue(json, new TypeReference<TreeMap<String, Object>>() {})
|
return mapper.readValue(bytes, new TypeReference<TreeMap<String, Object>>() {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue