static String getTodaysIndexName() { return "stagemonitor-spans-" + StringUtils.getLogstashStyleDate(); }
public static String getTodaysIndexName() { return STAGEMONITOR_METRICS_INDEX_PREFIX + StringUtils.getLogstashStyleDate(); }
public static String getLogstashStyleDate() { return getLogstashStyleDate(System.currentTimeMillis()); }
private void excludeDays(String prefix, StringBuilder sb, GregorianCalendar lastDayToExclude, GregorianCalendar alreadyExcluded) { for (; alreadyExcluded.after(lastDayToExclude) || alreadyExcluded.equals(lastDayToExclude); alreadyExcluded.add(Calendar.DAY_OF_YEAR, -1)) { sb.append(",-").append(prefix).append(StringUtils.getLogstashStyleDate(alreadyExcluded.getTimeInMillis())); } }
@Override public void report(SpanContextInformation spanContext, final SpanWrapper spanWrapper) { logger.debug("Reporting span"); if (elasticsearchTracingPlugin.isOnlyLogElasticsearchSpanReports()) { final String spansIndex = "stagemonitor-spans-" + StringUtils.getLogstashStyleDate(); spanLogger.info(ElasticsearchClient.getBulkHeader("index", spansIndex, SPANS_TYPE) + JsonUtils.toJson(spanWrapper)); } else { scheduleSendBulk(new SpanBulkIndexOutputStreamHandler(spanWrapper)); } }
@Test public void testLogReportSpan() throws Exception { Mockito.when(elasticsearchTracingPlugin.isOnlyLogElasticsearchSpanReports()).thenReturn(true); final SpanContextInformation spanContext = reportSpanWithCallTree(1000, "Report Me"); final List<MockSpan> sampledSpans = getSampledSpans(); assertThat(sampledSpans).hasSize(1); Mockito.verify(httpClient, Mockito.times(0)).send(any(), any(), any(), any(), any()); Mockito.verify(spanLogger).info(ArgumentMatchers.startsWith("{\"index\":{\"_index\":\"stagemonitor-spans-" + StringUtils.getLogstashStyleDate() + "\",\"_type\":\"spans\"}}\n")); Assert.assertTrue(reporter.isActive(spanContext)); }
@Test public void testSchedule() throws Exception { when(corePlugin.isOnlyLogElasticsearchMetricReports()).thenReturn(true); // this clock starts at 0 and then progresses normally when(clock.getTime()).then(new Answer<Long>() { long firstTimestamp; @Override public Long answer(InvocationOnMock invocation) throws Throwable { final long time = System.currentTimeMillis(); if (firstTimestamp == 0) { firstTimestamp = time; } return (time - firstTimestamp); } }); registry.register(name("test").build(), new Gauge<Integer>() { @Override public Integer getValue() { return 1; } }); elasticsearchReporter.start(100, TimeUnit.MILLISECONDS); Thread.sleep(300); verify(metricsLogger).info(eq(String.format("{\"index\":{\"_index\":\"stagemonitor-metrics-%s\",\"_type\":\"metrics\"}}\n" + "{\"@timestamp\":100,\"name\":\"test\",\"app\":\"test\",\"value\":1.0}\n", StringUtils.getLogstashStyleDate()))); verify(metricsLogger).info(eq(String.format("{\"index\":{\"_index\":\"stagemonitor-metrics-%s\",\"_type\":\"metrics\"}}\n" + "{\"@timestamp\":200,\"name\":\"test\",\"app\":\"test\",\"value\":1.0}\n", StringUtils.getLogstashStyleDate()))); }
@Test public void testReportToLog() throws Exception { when(corePlugin.isOnlyLogElasticsearchMetricReports()).thenReturn(true); elasticsearchReporter.reportMetrics( metricNameMap(name("gauge").build(), gauge(1)), metricNameMap(Counter.class), metricNameMap(Histogram.class), metricNameMap(Meter.class), metricNameMap(Timer.class)); verify(metricsLogger).info(eq(String.format("{\"index\":{\"_index\":\"stagemonitor-metrics-%s\",\"_type\":\"metrics\"}}\n" + "{\"@timestamp\":%d,\"name\":\"gauge\",\"app\":\"test\",\"value\":1.0}\n", StringUtils.getLogstashStyleDate(), timestamp))); }
@Test public void testReportGauges() throws Exception { elasticsearchReporter.reportMetrics( metricNameMap( name("cpu_usage").type("user").tag("core", "1").build(), gauge(3) ), metricNameMap(Counter.class), metricNameMap(Histogram.class), metricNameMap(Meter.class), metricNameMap(Timer.class)); final String jsons = new String(out.toByteArray()); assertEquals(jsons, 2, jsons.split("\n").length); assertEquals( objectMap("index", map("_type", "metrics") .add("_index", "stagemonitor-metrics-" + StringUtils.getLogstashStyleDate())), asMap(jsons.split("\n")[0])); assertEquals( objectMap("@timestamp", timestamp) .add("name", "cpu_usage") .add("app", "test") .add("type", "user") .add("core", "1") .add("value", 3.0), asMap(jsons.split("\n")[1])); }
static String getTodaysIndexName() { return "stagemonitor-spans-" + StringUtils.getLogstashStyleDate(); }
@Override public void report(SpanContextInformation spanContext, final SpanWrapper spanWrapper) { logger.debug("Reporting span"); if (elasticsearchTracingPlugin.isOnlyLogElasticsearchSpanReports()) { final String spansIndex = "stagemonitor-spans-" + StringUtils.getLogstashStyleDate(); spanLogger.info(ElasticsearchClient.getBulkHeader("index", spansIndex, SPANS_TYPE) + JsonUtils.toJson(spanWrapper)); } else { scheduleSendBulk(new SpanBulkIndexOutputStreamHandler(spanWrapper)); } }