test_class.declarator: elasticsearchReporter
test_class.modifier: private
test_class.original_string: private ElasticsearchReporter elasticsearchReporter;
test_class.type: ElasticsearchReporter
test_class.var_name: elasticsearchReporter
test_class.declarator: registry = new MetricRegistry()
test_class.modifier: private
test_class.original_string: private MetricRegistry registry = new MetricRegistry();
test_class.type: MetricRegistry
test_class.var_name: registry
test_class.declarator: index = randomAsciiOfLength(12).toLowerCase()
test_class.modifier: private
test_class.original_string: private String index = randomAsciiOfLength(12).toLowerCase();
test_class.type: String
test_class.var_name: index
test_class.declarator: indexWithDate = String.format("%s-%s-%02d", index, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH) + 1)
test_class.modifier: private
test_class.original_string: private String indexWithDate = String.format("%s-%s-%02d", index, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH) + 1);
test_class.type: String
test_class.var_name: indexWithDate
test_class.declarator: prefix = randomAsciiOfLength(12).toLowerCase()
test_class.modifier: private
test_class.original_string: private String prefix = randomAsciiOfLength(12).toLowerCase();
test_class.type: String
test_class.var_name: prefix
test_class.file: neo-starter-metrics/src/test/java/eu/neoteric/starter/metrics/report/elastic/ElasticsearchReporterTest.java
test_class.identifier: ElasticsearchReporterTest
test_class.superclass: extends ESIntegTestCase
test_case.body: @Test // issue #6
      public void testThatEmptyMetricsDoNotResultInBrokenBulkRequest() throws Exception {
          long connectionsBeforeReporting = getTotalHttpConnections();
          elasticsearchReporter.report();
          long connectionsAfterReporting = getTotalHttpConnections();
  
          org.assertj.core.api.Assertions.assertThat(connectionsAfterReporting).isEqualTo(connectionsBeforeReporting);
      }
test_case.class_method_signature: ElasticsearchReporterTest.testThatEmptyMetricsDoNotResultInBrokenBulkRequest()
test_case.full_signature: @Test // issue #6 public void testThatEmptyMetricsDoNotResultInBrokenBulkRequest()
test_case.identifier: testThatEmptyMetricsDoNotResultInBrokenBulkRequest
test_case.invocations: getTotalHttpConnections report getTotalHttpConnections isEqualTo assertThat
test_case.modifiers: @Test // issue #6 public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testThatEmptyMetricsDoNotResultInBrokenBulkRequest()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(ElasticsearchReporter.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(ElasticsearchReporter.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: DEFAULT_BULK_SIZE = 2500
focal_class.modifier: private static final
focal_class.original_string: private static final int DEFAULT_BULK_SIZE = 2500;
focal_class.type: int
focal_class.var_name: DEFAULT_BULK_SIZE
focal_class.declarator: DEFAULT_TIMEOUT = 1000
focal_class.modifier: private static final
focal_class.original_string: private static final int DEFAULT_TIMEOUT = 1000;
focal_class.type: int
focal_class.var_name: DEFAULT_TIMEOUT
focal_class.declarator: hosts
focal_class.modifier: private final
focal_class.original_string: private final String[] hosts;
focal_class.type: String[]
focal_class.var_name: hosts
focal_class.declarator: clock
focal_class.modifier: private final
focal_class.original_string: private final Clock clock;
focal_class.type: Clock
focal_class.var_name: clock
focal_class.declarator: prefix
focal_class.modifier: private final
focal_class.original_string: private final String prefix;
focal_class.type: String
focal_class.var_name: prefix
focal_class.declarator: index
focal_class.modifier: private final
focal_class.original_string: private final String index;
focal_class.type: String
focal_class.var_name: index
focal_class.declarator: bulkSize
focal_class.modifier: private final
focal_class.original_string: private final int bulkSize;
focal_class.type: int
focal_class.var_name: bulkSize
focal_class.declarator: timeout
focal_class.modifier: private final
focal_class.original_string: private final int timeout;
focal_class.type: int
focal_class.var_name: timeout
focal_class.declarator: objectMapper = new ObjectMapper()
focal_class.modifier: private final
focal_class.original_string: private final ObjectMapper objectMapper = new ObjectMapper();
focal_class.type: ObjectMapper
focal_class.var_name: objectMapper
focal_class.declarator: writer
focal_class.modifier: private final
focal_class.original_string: private final ObjectWriter writer;
focal_class.type: ObjectWriter
focal_class.var_name: writer
focal_class.declarator: percolationFilter
focal_class.modifier: private
focal_class.original_string: private MetricFilter percolationFilter;
focal_class.type: MetricFilter
focal_class.var_name: percolationFilter
focal_class.declarator: notifier
focal_class.modifier: private
focal_class.original_string: private Notifier notifier;
focal_class.type: Notifier
focal_class.var_name: notifier
focal_class.declarator: currentIndexName
focal_class.modifier: private
focal_class.original_string: private String currentIndexName;
focal_class.type: String
focal_class.var_name: currentIndexName
focal_class.declarator: indexDateFormat
focal_class.modifier: private
focal_class.original_string: private SimpleDateFormat indexDateFormat;
focal_class.type: SimpleDateFormat
focal_class.var_name: indexDateFormat
focal_class.declarator: checkedForIndexTemplate
focal_class.modifier: private
focal_class.original_string: private boolean checkedForIndexTemplate;
focal_class.type: boolean
focal_class.var_name: checkedForIndexTemplate
focal_class.file: neo-starter-metrics/src/main/java/eu/neoteric/starter/metrics/report/elastic/ElasticsearchReporter.java
focal_class.identifier: ElasticsearchReporter
focal_class.class_method_signature: ElasticsearchReporter.ElasticsearchReporter(MetricRegistry registry, String[] hosts, int timeout,
                                   String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit,
                                   MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname, Map<String, Object> additionalFields)
focal_class.full_signature: public  ElasticsearchReporter(MetricRegistry registry, String[] hosts, int timeout,
                                   String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit,
                                   MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname, Map<String, Object> additionalFields)
focal_class.identifier: ElasticsearchReporter
focal_class.modifiers: public
focal_class.parameters: (MetricRegistry registry, String[] hosts, int timeout,
                                   String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit,
                                   MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname, Map<String, Object> additionalFields)
focal_class.signature:  ElasticsearchReporter(MetricRegistry registry, String[] hosts, int timeout,
                                   String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit,
                                   MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname, Map<String, Object> additionalFields)
focal_class.class_method_signature: ElasticsearchReporter.forRegistry(MetricRegistry registry)
focal_class.full_signature: public static Builder forRegistry(MetricRegistry registry)
focal_class.identifier: forRegistry
focal_class.modifiers: public static
focal_class.parameters: (MetricRegistry registry)
focal_class.return: Builder
focal_class.signature: Builder forRegistry(MetricRegistry registry)
focal_class.class_method_signature: ElasticsearchReporter.report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_class.full_signature: @Override public void report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_class.identifier: report
focal_class.modifiers: @Override public
focal_class.parameters: (SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_class.return: void
focal_class.signature: void report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_class.class_method_signature: ElasticsearchReporter.getPercolationMatches(JsonMetric jsonMetric)
focal_class.full_signature: private List<String> getPercolationMatches(JsonMetric jsonMetric)
focal_class.identifier: getPercolationMatches
focal_class.modifiers: private
focal_class.parameters: (JsonMetric jsonMetric)
focal_class.return: List<String>
focal_class.signature: List<String> getPercolationMatches(JsonMetric jsonMetric)
focal_class.class_method_signature: ElasticsearchReporter.addJsonMetricToPercolationIfMatching(JsonMetric<? extends Metric> jsonMetric, List<JsonMetric> percolationMetrics)
focal_class.full_signature: private void addJsonMetricToPercolationIfMatching(JsonMetric<? extends Metric> jsonMetric, List<JsonMetric> percolationMetrics)
focal_class.identifier: addJsonMetricToPercolationIfMatching
focal_class.modifiers: private
focal_class.parameters: (JsonMetric<? extends Metric> jsonMetric, List<JsonMetric> percolationMetrics)
focal_class.return: void
focal_class.signature: void addJsonMetricToPercolationIfMatching(JsonMetric<? extends Metric> jsonMetric, List<JsonMetric> percolationMetrics)
focal_class.class_method_signature: ElasticsearchReporter.writeJsonMetricAndRecreateConnectionIfNeeded(JsonMetric jsonMetric, HttpURLConnection connection,
                                                                             AtomicInteger entriesWritten)
focal_class.full_signature: private HttpURLConnection writeJsonMetricAndRecreateConnectionIfNeeded(JsonMetric jsonMetric, HttpURLConnection connection,
                                                                             AtomicInteger entriesWritten)
focal_class.identifier: writeJsonMetricAndRecreateConnectionIfNeeded
focal_class.modifiers: private
focal_class.parameters: (JsonMetric jsonMetric, HttpURLConnection connection,
                                                                             AtomicInteger entriesWritten)
focal_class.return: HttpURLConnection
focal_class.signature: HttpURLConnection writeJsonMetricAndRecreateConnectionIfNeeded(JsonMetric jsonMetric, HttpURLConnection connection,
                                                                             AtomicInteger entriesWritten)
focal_class.class_method_signature: ElasticsearchReporter.closeConnection(HttpURLConnection connection)
focal_class.full_signature: private void closeConnection(HttpURLConnection connection)
focal_class.identifier: closeConnection
focal_class.modifiers: private
focal_class.parameters: (HttpURLConnection connection)
focal_class.return: void
focal_class.signature: void closeConnection(HttpURLConnection connection)
focal_class.class_method_signature: ElasticsearchReporter.createNewConnectionIfBulkSizeReached(HttpURLConnection connection, int entriesWritten)
focal_class.full_signature: private HttpURLConnection createNewConnectionIfBulkSizeReached(HttpURLConnection connection, int entriesWritten)
focal_class.identifier: createNewConnectionIfBulkSizeReached
focal_class.modifiers: private
focal_class.parameters: (HttpURLConnection connection, int entriesWritten)
focal_class.return: HttpURLConnection
focal_class.signature: HttpURLConnection createNewConnectionIfBulkSizeReached(HttpURLConnection connection, int entriesWritten)
focal_class.class_method_signature: ElasticsearchReporter.writeJsonMetric(JsonMetric jsonMetric, ObjectWriter writer, OutputStream out)
focal_class.full_signature: private void writeJsonMetric(JsonMetric jsonMetric, ObjectWriter writer, OutputStream out)
focal_class.identifier: writeJsonMetric
focal_class.modifiers: private
focal_class.parameters: (JsonMetric jsonMetric, ObjectWriter writer, OutputStream out)
focal_class.return: void
focal_class.signature: void writeJsonMetric(JsonMetric jsonMetric, ObjectWriter writer, OutputStream out)
focal_class.class_method_signature: ElasticsearchReporter.openConnection(String uri, String method)
focal_class.full_signature: private HttpURLConnection openConnection(String uri, String method)
focal_class.identifier: openConnection
focal_class.modifiers: private
focal_class.parameters: (String uri, String method)
focal_class.return: HttpURLConnection
focal_class.signature: HttpURLConnection openConnection(String uri, String method)
focal_class.class_method_signature: ElasticsearchReporter.checkForIndexTemplate()
focal_class.full_signature: private void checkForIndexTemplate()
focal_class.identifier: checkForIndexTemplate
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void checkForIndexTemplate()
focal_class.superclass: extends ScheduledReporter
focal_method.body: @Override
      public void report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers) {
  
          // nothing to do if we dont have any metrics to report
          if (gauges.isEmpty() && counters.isEmpty() && histograms.isEmpty() && meters.isEmpty() && timers.isEmpty()) {
              LOGGER.info("All metrics empty, nothing to report");
              return;
          }
  
          if (!checkedForIndexTemplate) {
              checkForIndexTemplate();
          }
          final long timestamp = clock.getTime() / 1000;
  
          currentIndexName = index;
          if (indexDateFormat != null) {
              currentIndexName += "-" + indexDateFormat.format(new Date(timestamp * 1000));
          }
  
          try {
              HttpURLConnection connection;
              try {
                  connection = openConnection("/_bulk", "POST");
              } catch (ElasticsearchConnectionException e) {
                  LOGGER.error("Could not connect to any configured elasticsearch instances: {}", Arrays.asList(hosts), e);
                  return;
              }
  
              List<JsonMetrics.JsonMetric> percolationMetrics = new ArrayList<>();
              AtomicInteger entriesWritten = new AtomicInteger(0);
  
              for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
                  if (entry.getValue().getValue() != null) {
                      JsonMetrics.JsonMetric jsonMetric = new JsonMetrics.JsonGauge(name(prefix, entry.getKey()), timestamp, entry.getValue());
                      connection = writeJsonMetricAndRecreateConnectionIfNeeded(jsonMetric, connection, entriesWritten);
                      addJsonMetricToPercolationIfMatching(jsonMetric, percolationMetrics);
                  }
              }
  
              for (Map.Entry<String, Counter> entry : counters.entrySet()) {
                  JsonCounter jsonMetric = new JsonCounter(name(prefix, entry.getKey()), timestamp, entry.getValue());
                  connection = writeJsonMetricAndRecreateConnectionIfNeeded(jsonMetric, connection, entriesWritten);
                  addJsonMetricToPercolationIfMatching(jsonMetric, percolationMetrics);
              }
  
              for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
                  JsonHistogram jsonMetric = new JsonHistogram(name(prefix, entry.getKey()), timestamp, entry.getValue());
                  connection = writeJsonMetricAndRecreateConnectionIfNeeded(jsonMetric, connection, entriesWritten);
                  addJsonMetricToPercolationIfMatching(jsonMetric, percolationMetrics);
              }
  
              for (Map.Entry<String, Meter> entry : meters.entrySet()) {
                  JsonMeter jsonMetric = new JsonMeter(name(prefix, entry.getKey()), timestamp, entry.getValue());
                  connection = writeJsonMetricAndRecreateConnectionIfNeeded(jsonMetric, connection, entriesWritten);
                  addJsonMetricToPercolationIfMatching(jsonMetric, percolationMetrics);
              }
  
              for (Map.Entry<String, Timer> entry : timers.entrySet()) {
                  JsonTimer jsonMetric = new JsonTimer(name(prefix, entry.getKey()), timestamp, entry.getValue());
                  connection = writeJsonMetricAndRecreateConnectionIfNeeded(jsonMetric, connection, entriesWritten);
                  addJsonMetricToPercolationIfMatching(jsonMetric, percolationMetrics);
              }
  
              closeConnection(connection);
  
              // execute the notifier impl, in case percolation found matches
              if (percolationMetrics.size() > 0 && notifier != null) {
                  for (JsonMetric jsonMetric : percolationMetrics) {
                      List<String> matches = getPercolationMatches(jsonMetric);
                      for (String match : matches) {
                          notifier.notify(jsonMetric, match);
                      }
                  }
              }
              // catch the exception to make sure we do not interrupt the live application
          } catch (ElasticsearchConnectionException e) {
              LOGGER.error("Couldnt report to elasticsearch server", e);
          } catch (IOException e) {
              LOGGER.error("Couldnt report to elasticsearch server", e);
          }
      }
focal_method.class_method_signature: ElasticsearchReporter.report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_method.full_signature: @Override public void report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_method.identifier: report
focal_method.invocations: isEmpty isEmpty isEmpty isEmpty isEmpty info checkForIndexTemplate getTime format openConnection error asList entrySet getValue getValue name getKey getValue writeJsonMetricAndRecreateConnectionIfNeeded addJsonMetricToPercolationIfMatching entrySet name getKey getValue writeJsonMetricAndRecreateConnectionIfNeeded addJsonMetricToPercolationIfMatching entrySet name getKey getValue writeJsonMetricAndRecreateConnectionIfNeeded addJsonMetricToPercolationIfMatching entrySet name getKey getValue writeJsonMetricAndRecreateConnectionIfNeeded addJsonMetricToPercolationIfMatching entrySet name getKey getValue writeJsonMetricAndRecreateConnectionIfNeeded addJsonMetricToPercolationIfMatching closeConnection size getPercolationMatches notify error error
focal_method.modifiers: @Override public
focal_method.parameters: (SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)
focal_method.return: void
focal_method.signature: void report(SortedMap<String, Gauge> gauges,
                         SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms,
                         SortedMap<String, Meter> meters,
                         SortedMap<String, Timer> timers)