@Test public void sendPayloadShouldLogSuccessfulSending() { Logger.getRootLogger().addAppender(appender); mockResponse(202); DatadogHttpClient ddClient = new DatadogHttpClient(ApiSite.US, "foo", true, httpClient); ddClient.send("{}"); verify(appender).doAppend(logCaptor.capture()); assertTrue(logCaptor.getValue().getRenderedMessage().startsWith("Sent metrics data")); assertEquals(Level.DEBUG, logCaptor.getValue().getLevel()); }
public void send(String payload) { HttpPost request = new HttpPost(seriesUrl); request.setHeader(HEADER_KEY_API_KEY, apiKey); request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { LOG.warn(String.format("Failed to send to Datadog. Response was %s", response)); } else { LOG.debug(String.format("Sent metrics data (size: %d) to %s", payload.length(), seriesUrl)); } } catch (IOException e) { LOG.warn("Failed to send to Datadog.", e); } }
DatadogHttpClient implements Closeable { public void send(String payload) { HttpPost request = new HttpPost(seriesUrl); request.setHeader(HEADER_KEY_API_KEY, apiKey); request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { LOG.warn(String.format("Failed to send to Datadog. Response was %s", response)); } else { LOG.debug(String.format("Sent metrics data (size: %d) to %s", payload.length(), seriesUrl)); } } catch (IOException e) { LOG.warn("Failed to send to Datadog.", e); } } }
DatadogHttpClient implements Closeable { public void send(String payload) { HttpPost request = new HttpPost(seriesUrl); request.setHeader(HEADER_KEY_API_KEY, apiKey); request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { LOG.warn(String.format("Failed to send to Datadog. Response was %s", response)); } else { LOG.debug(String.format("Sent metrics data (size: %d) to %s", payload.length(), seriesUrl)); } } catch (IOException e) { LOG.warn("Failed to send to Datadog.", e); } } DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, CloseableHttpClient client);  DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, int timeoutSeconds); }
DatadogHttpClient implements Closeable { public void send(String payload) { HttpPost request = new HttpPost(seriesUrl); request.setHeader(HEADER_KEY_API_KEY, apiKey); request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { LOG.warn(String.format("Failed to send to Datadog. Response was %s", response)); } else { LOG.debug(String.format("Sent metrics data (size: %d) to %s", payload.length(), seriesUrl)); } } catch (IOException e) { LOG.warn("Failed to send to Datadog.", e); } } DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, CloseableHttpClient client);  DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, int timeoutSeconds); void send(String payload); @Override void close(); }
DatadogHttpClient implements Closeable { public void send(String payload) { HttpPost request = new HttpPost(seriesUrl); request.setHeader(HEADER_KEY_API_KEY, apiKey); request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); request.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON)); try (CloseableHttpResponse response = client.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { LOG.warn(String.format("Failed to send to Datadog. Response was %s", response)); } else { LOG.debug(String.format("Sent metrics data (size: %d) to %s", payload.length(), seriesUrl)); } } catch (IOException e) { LOG.warn("Failed to send to Datadog.", e); } } DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, CloseableHttpClient client);  DatadogHttpClient(ApiSite apiSite, String apiKey, boolean skipValidation, int timeoutSeconds); void send(String payload); @Override void close();  }