GraphiteHttpClient { @Deprecated public JsonNode getTargetJson(String target) throws Exception { return getTargetJson(target, null, null); } @Inject  GraphiteHttpClient(SeyrenConfig seyrenConfig); @Deprecated JsonNode getTargetJson(String target); JsonNode getTargetJson(String target, String from, String until); byte[] getChart(String target, int width, int height, String from, String to, LegendState legendState, AxesState axesState); byte[] getChart(String target, int width, int height, String from, String to, LegendState legendState, AxesState axesState,
            BigDecimal warnThreshold, BigDecimal errorThreshold);  }
@Test public void requestingJsonCallsThroughToGraphiteCorrectly() throws Exception { String response = "[{\"target\": \"service.error.1MinuteRate\", \"datapoints\": [[0.06, 1337453460]]}]"; clientDriver.addExpectation( onRequestTo("/render/") .withParam("from", "-11minutes") .withParam("until", "-1minutes") .withParam("uniq", Pattern.compile("[0-9]+")) .withParam("format", "json") .withParam("target", "service.error.1MinuteRate"), giveResponse(response, "application/json")); JsonNode node = graphiteHttpClient.getTargetJson("service.error.1MinuteRate"); assertThat(node, is(MAPPER.readTree(response))); }
@Test public void requestingJsonCallsWithFromAndUntilThroughToGraphiteCorrectly() throws Exception { String response = "[{\"target\": \"service.error.count\", \"datapoints\": [[32, 1337453460]]}]"; clientDriver.addExpectation( onRequestTo("/render/") .withParam("from", "-5minutes") .withParam("until", "now") .withParam("uniq", Pattern.compile("[0-9]+")) .withParam("format", "json") .withParam("target", "service.error.count"), giveResponse(response, "application/json")); JsonNode node = graphiteHttpClient.getTargetJson("service.error.count", "-5minutes", "now"); assertThat(node, is(MAPPER.readTree(response))); }
@Test public void exceptionGettingDataFromGraphiteIsHandled() throws Exception { thrown.expect(GraphiteReadException.class); graphiteHttpClient = new GraphiteHttpClient(seyrenConfig("http: graphiteHttpClient.getTargetJson("service.*.1MinuteRate"); }
@Test public void authIsAddedWhenUsernameAndPasswordAreProvided() throws Exception { System.setProperty("GRAPHITE_USERNAME", "seyren"); System.setProperty("GRAPHITE_PASSWORD", "s3yr3N"); graphiteHttpClient = new GraphiteHttpClient(seyrenConfig(clientDriver.getBaseUrl())); String response = "[{\"target\": \"service.error.1MinuteRate\", \"datapoints\": [[0.20, 1337453460],[0.01, 1337453463]]}]"; clientDriver.addExpectation( onRequestTo("/render/") .withParam("from", "-11minutes") .withParam("until", "-1minutes") .withParam("uniq", Pattern.compile("[0-9]+")) .withParam("format", "json") .withParam("target", "service.error.1MinuteRate") .withHeader("Authorization", "Basic c2V5cmVuOnMzeXIzTg=="), giveResponse(response, "application/json")); graphiteHttpClient.getTargetJson("service.error.1MinuteRate"); System.clearProperty("GRAPHITE_USERNAME"); System.clearProperty("GRAPHITE_PASSWORD"); }