Skip to content

Commit

Permalink
Final changes to rename existing numeric naming to gauge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Negrea committed Apr 22, 2015
1 parent e6a9be1 commit 810813c
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 214 deletions.
10 changes: 5 additions & 5 deletions api/metrics-api-jaxrs/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ PUT /hawkular/metrics/{tenantId}/gauge/{id}/meta
*Example Request*

----
curl -X PUT http://localhost:8080/hawkular/metrics/{tenantId}/numeric -d@request.json -HContent-Type:application/json
curl -X PUT http://localhost:8080/hawkular/metrics/{tenantId}/gauge -d@request.json -HContent-Type:application/json
----

*Description*
Expand Down Expand Up @@ -281,11 +281,11 @@ curl -X POST http://localhost:8080/hawkular/metrics/{tenantId}/availability/{id}
Inserts data for a single availablity metric. Accepted values are the strings
`up` and `down`.

=== Insert Data for Multiple Numeric Metrics
=== Insert Data for Multiple Gauge Metrics

*Request URI*

POST /hawkular/metrics/{tenantId}/numeric/data
POST /hawkular/metrics/{tenantId}/gauge/data

*Request Body*

Expand All @@ -312,12 +312,12 @@ POST /hawkular/metrics/{tenantId}/numeric/data
*Example Request*

----
curl -X POST http://localhost:8080/hawkular/metrics/{tenantId}/numeric/data -d@request.json -HContent-Type:application/json
curl -X POST http://localhost:8080/hawkular/metrics/{tenantId}/gauge/data -d@request.json -HContent-Type:application/json
----

*Description*

Insert data for multiple numeric metrics.
Insert data for multiple gauge metrics.

=== Insert Data for Multiple Availability Metrics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class AvailabilityHandler {

@POST
@Path("/{tenantId}/availability")
@ApiOperation(value = "Create availability metric definition. Same notes as creating numeric metric apply.")
@ApiOperation(value = "Create availability metric definition. Same notes as creating gauge metric apply.")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Metric definition created successfully"),
@ApiResponse(code = 400, message = "Missing or invalid payload", response = ApiError.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public void write(@Suspended AsyncResponse asyncResponse, @PathParam("tenantId")
} catch (InvalidObjectException e) {
return ApiUtils.badRequest(new ApiError(e.getMessage()));
}
List<Gauge> numericMetrics = FluentIterable.from(influxObjects) //
List<Gauge> gaugeMetrics = FluentIterable.from(influxObjects) //
.transform(influxObject -> {
List<String> influxObjectColumns = influxObject.getColumns();
int valueColumnIndex = influxObjectColumns.indexOf("value");
List<List<?>> influxObjectPoints = influxObject.getPoints();
Gauge numericMetric = new Gauge(tenantId, new MetricId(influxObject.getName()));
Gauge gaugeMetric = new Gauge(tenantId, new MetricId(influxObject.getName()));
for (List<?> point : influxObjectPoints) {
double value;
long timestamp;
Expand All @@ -141,11 +141,11 @@ public void write(@Suspended AsyncResponse asyncResponse, @PathParam("tenantId")
timestamp = ((Number) point.get((valueColumnIndex + 1) % 2)).longValue();
value = ((Number) point.get(valueColumnIndex)).doubleValue();
}
numericMetric.addData(new GaugeData(timestamp, value));
gaugeMetric.addData(new GaugeData(timestamp, value));
}
return numericMetric;
return gaugeMetric;
}).toList();
ListenableFuture<Void> future = metricsService.addGaugeData(numericMetrics);
ListenableFuture<Void> future = metricsService.addGaugeData(gaugeMetrics);
return Futures.transform(future, ApiUtils.MAP_VOID);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class RestForwardingHandlerITest {
@Mock
private ChannelHandlerContext channelHandlerContext;
private RestForwardingHandler restForwardingHandler;
private String findGuageDataUrl;
private String findGaugeDataUrl;

@Before
public void setUp() throws Exception {
Expand All @@ -79,7 +79,7 @@ public void setUp() throws Exception {

restForwardingHandler = new RestForwardingHandler(configuration);

findGuageDataUrl = "http://" + BASE_URI + "/" + TENANT + "/gauge/" + METRIC_NAME + "/data";
findGaugeDataUrl = "http://" + BASE_URI + "/" + TENANT + "/gauge/" + METRIC_NAME + "/data";
}

@Test
Expand All @@ -90,7 +90,7 @@ public void shouldForwardMetrics() throws Exception {
boolean foundMetricOnServer = false;
for (int i = 0; i < 20; i++) {
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
JsonNode jsonNode = findNumericDataOnServer();
JsonNode jsonNode = findGaugeDataOnServer();
if (jsonNode != null && expectedMetricIsPresent(metric, jsonNode)) {
foundMetricOnServer = true;
break;
Expand All @@ -99,8 +99,8 @@ public void shouldForwardMetrics() throws Exception {
assertTrue("Did not find expected metric on server", foundMetricOnServer);
}

private JsonNode findNumericDataOnServer() throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGuageDataUrl).openConnection();
private JsonNode findGaugeDataOnServer() throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl).openConnection();
urlConnection.connect();
int responseCode = urlConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
Expand All @@ -115,12 +115,12 @@ private JsonNode findNumericDataOnServer() throws IOException {
private boolean expectedMetricIsPresent(SingleMetric metric, JsonNode jsonNode) {
assertTrue("Data is not an array", jsonNode.isArray());

for (JsonNode numericData : jsonNode) {
JsonNode timestamp = numericData.get("timestamp");
assertNotNull("Numeric data has no timestamp attribute", timestamp);
for (JsonNode gaugeData : jsonNode) {
JsonNode timestamp = gaugeData.get("timestamp");
assertNotNull("Gauge data has no timestamp attribute", timestamp);
assertTrue("Timestamp is not a number", timestamp.isNumber());
JsonNode value = numericData.get("value");
assertNotNull("Numeric data has no value attribute", value);
JsonNode value = gaugeData.get("value");
assertNotNull("Gauge data has no value attribute", value);
assertTrue("Value is not a floating point number", value.isFloatingPointNumber());

if (timestamp.asLong() == metric.getTimestamp() && value.asDouble() == metric.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class CollectdITest extends ExecutableITestBase {
@Before
public void setUp() throws Exception {
tenant = getRandomTenantId();
findGuageMetricsUrl = "http://" + BASE_URI + "/" + tenant + "/metrics?type=guage";
findGuageMetricsUrl = "http://" + BASE_URI + "/" + tenant + "/metrics?type=gauge";
assumeCollectdIsPresent();
configureCollectd();
assertCollectdConfIsValid();
Expand Down Expand Up @@ -263,7 +263,7 @@ private List<Point> getServerData() throws Exception {
String[] split = metricName.split("\\.");
String type = split[split.length - 1];

urlConnection = (HttpURLConnection) new URL(findNumericDataUrl(metricName)).openConnection();
urlConnection = (HttpURLConnection) new URL(findGaugeDataUrl(metricName)).openConnection();
urlConnection.connect();
responseCode = urlConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
Expand All @@ -289,7 +289,7 @@ private List<Point> getServerData() throws Exception {
return points.sorted(Comparator.comparing(Point::getType).thenComparing(Point::getTimestamp)).collect(toList());
}

private String findNumericDataUrl(String metricName) {
private String findGaugeDataUrl(String metricName) {
return "http://" + BASE_URI + "/" + tenant + "/gauge/" + metricName + "/data";
}

Expand Down

0 comments on commit 810813c

Please sign in to comment.