Source:
private List<Point> getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); urlConnection.setRequestProperty("tenantId", tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { String msg = "Could not get metrics list from server: %s, %d"; fail(String.format(Locale.ROOT, msg, findGaugeMetricsUrl, responseCode)); } List<String> metricNames; try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricName.class); List<MetricName> value = objectMapper.readValue(inputStream, valueType); metricNames = value.stream().map(MetricName::getId).collect(toList()); } Stream<Point> points = Stream.empty(); for (String metricName : metricNames) { String[] split = metricName.split("\\."); String type = split[split.length - 1]; urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); urlConnection.setRequestProperty("tenantId", tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { fail("Could not load metric data from server: " + responseCode); } try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricData.class); List<MetricData> data = objectMapper.readValue(inputStream, valueType); Stream<Point> metricPoints = data.stream().map( metricData -> new Point(type, metricData.timestamp, metricData.value)); points = Stream.concat(points, metricPoints); } } return points.sorted(Comparator.comparing(Point::getType).thenComparing(Point::getTimestamp)).collect(toList()); }

Target:
private List<Point> getServerData() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeMetricsUrl).openConnection(); urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { String msg = "Could not get metrics list from server: %s, %d"; fail(String.format(Locale.ROOT, msg, findGaugeMetricsUrl, responseCode)); } List<String> metricNames; try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricName.class); List<MetricName> value = objectMapper.readValue(inputStream, valueType); metricNames = value.stream().map(MetricName::getId).collect(toList()); } Stream<Point> points = Stream.empty(); for (String metricName : metricNames) { String[] split = metricName.split("\\."); String type = split[split.length - 1]; urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection(); urlConnection.setRequestProperty(HAWKULAR_TENANT_HEADER, tenant); urlConnection.connect(); responseCode = urlConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { fail("Could not load metric data from server: " + responseCode); } try (InputStream inputStream = urlConnection.getInputStream()) { TypeFactory typeFactory = objectMapper.getTypeFactory(); CollectionType valueType = typeFactory.constructCollectionType(List.class, MetricData.class); List<MetricData> data = objectMapper.readValue(inputStream, valueType); Stream<Point> metricPoints = data.stream().map( metricData -> new Point(type, metricData.timestamp, metricData.value)); points = Stream.concat(points, metricPoints); } } return points.sorted(Comparator.comparing(Point::getType).thenComparing(Point::getTimestamp)).collect(toList()); }