Skip to content

Commit

Permalink
Add type to the MetricDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Burman committed Aug 26, 2015
1 parent ed8b2c0 commit ee9f169
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Objects;

import org.hawkular.metrics.core.api.Metric;
import org.hawkular.metrics.core.api.MetricType;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -59,17 +60,25 @@ public class MetricDefinition {
include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY)
private Integer dataRetention;

@JsonProperty
@org.codehaus.jackson.annotate.JsonProperty
@org.codehaus.jackson.map.annotate.JsonSerialize(
include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY)
private MetricType type;

public MetricDefinition() {
}

@JsonCreator
public MetricDefinition(
@JsonProperty("id") String id,
@JsonProperty(value = "tags") Map<String, String> tags,
@JsonProperty("dataRetention") Integer dataRetention) {
@JsonProperty("dataRetention") Integer dataRetention,
@JsonProperty("type") MetricType type) {
this.id = id;
this.tags = tags == null ? emptyMap() : unmodifiableMap(tags);
this.dataRetention = dataRetention;
this.type = type;
}

public String getTenantId() {
Expand All @@ -91,10 +100,15 @@ public Integer getDataRetention() {
return dataRetention;
}

public MetricType getType() {
return type;
}

@SuppressWarnings("unchecked")
public MetricDefinition(Metric metric) {
this.tenantId = metric.getTenantId();
this.tenantId = metric.getId().getTenantId();
this.id = metric.getId().getName();
this.type = metric.getId().getType();
this.tags = metric.getTags();
this.dataRetention = metric.getDataRetention();
}
Expand All @@ -104,7 +118,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MetricDefinition gauge = (MetricDefinition) o;
return Objects.equals(id, gauge.id);
return Objects.equals(id, gauge.getId()) && Objects.equals(type, gauge.getType());
}

@Override
Expand All @@ -119,6 +133,7 @@ public String toString() {
", id='" + id + '\'' +
", tags=" + tags +
", dataRetention=" + dataRetention +
", type=" + type.toString() +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class CORSITest extends RESTTest {
assertEquals(200, response.status)
assertEquals(
[
[tenantId: tenantId, id: 'm11'],
[tenantId: tenantId, id: 'm12'],
[tenantId: tenantId, id: 'm11', type: 'GAUGE'],
[tenantId: tenantId, id: 'm12', type: 'GAUGE'],
],
response.data
)
Expand Down Expand Up @@ -145,8 +145,8 @@ class CORSITest extends RESTTest {
assertEquals(200, response.status)
assertEquals(
[
[tenantId: tenantId, id: 'm11'],
[tenantId: tenantId, id: 'm12'],
[tenantId: tenantId, id: 'm11', type: 'GAUGE'],
[tenantId: tenantId, id: 'm12', type: 'GAUGE'],
],
response.data
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ class CassandraBackendITest extends RESTTest {
assertEquals(200, response.status)
assertEquals(
[
[tenantId: tenantId, id: 'm11'],
[tenantId: tenantId, id: 'm12'],
[tenantId: tenantId, id: 'm13', tags: [a1: 'A', B1: 'B'], dataRetention: 32]
[tenantId: tenantId, id: 'm11', type: 'GAUGE'],
[tenantId: tenantId, id: 'm12', type: 'GAUGE'],
[tenantId: tenantId, id: 'm13', tags: [a1: 'A', B1: 'B'], dataRetention: 32, type: 'GAUGE']
],
response.data
)
Expand Down Expand Up @@ -454,9 +454,9 @@ class CassandraBackendITest extends RESTTest {
assertEquals(200, response.status)
assertEquals(
[
[tenantId: tenantId, id: 'm14'],
[tenantId: tenantId, id: 'm15'],
[tenantId: tenantId, id: 'm16', tags: [a10: '10', a11: '11'], dataRetention: 7]
[tenantId: tenantId, id: 'm14', type: 'AVAILABILITY'],
[tenantId: tenantId, id: 'm15', type: 'AVAILABILITY'],
[tenantId: tenantId, id: 'm16', tags: [a10: '10', a11: '11'], dataRetention: 7, type: 'AVAILABILITY']
],
response.data
)
Expand Down Expand Up @@ -561,7 +561,8 @@ class CassandraBackendITest extends RESTTest {
assertEquals(200, response.status)
assertEquals([
tenantId: tenantId,
id: 'Empty1'
id: 'Empty1',
type: 'GAUGE'
], response.data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.hawkular.metrics.rest

import groovy.json.JsonOutput
import org.hawkular.metrics.core.impl.DateTimeService
import org.joda.time.DateTime
import org.junit.Test
Expand All @@ -25,6 +24,7 @@ import static java.lang.Double.NaN
import static org.joda.time.DateTime.now
import static org.joda.time.Duration.standardMinutes
import static org.junit.Assert.assertEquals

/**
* @author John Sanda
*/
Expand Down Expand Up @@ -84,7 +84,7 @@ class CountersITest extends RESTTest {
response = hawkularMetrics.get(path: "counters/$id", headers: [(tenantHeaderName): tenantId])
assertEquals(200, response.status)

def expectedData = [tenantId: tenantId, id: id]
def expectedData = [tenantId: tenantId, id: id, type: 'COUNTER']
assertEquals(expectedData, response.data)
}

Expand Down Expand Up @@ -128,7 +128,8 @@ class CountersITest extends RESTTest {
tenantId: tenantId,
id: id,
tags: [tag1: 'one', tag2: 'two'],
dataRetention: 100
dataRetention: 100,
type: 'COUNTER'
]
assertEquals(expectedData, response.data)
}
Expand Down Expand Up @@ -166,15 +167,17 @@ class CountersITest extends RESTTest {
def expectedData = [
[
tenantId: tenantId,
id: counter1
id: counter1,
type: 'COUNTER'
],
[
tenantId: tenantId,
id: counter2,
tags: [
tag1: 'one',
tag2: 'two'
]
],
type: 'COUNTER'
]
]
assertEquals(expectedData, response.data)
Expand Down Expand Up @@ -368,8 +371,6 @@ class CountersITest extends RESTTest {
]
]

println "RESPONSE = ${JsonOutput.toJson(response.data)}"

assertEquals("Expected to get back three data points", 5, response.data.size())
assertRateEquals(expectedData[0], response.data[0])
assertRateEquals(expectedData[1], response.data[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class TagsITest extends RESTTest {
assertEquals([
tenantId: tenantId,
id : 'N1',
tags: [' a 1 ': ' A', 'bsq d1': 'B ']
tags: [' a 1 ': ' A', 'bsq d1': 'B '],
type: 'GAUGE'
], response.data)

// Make sure we do not allow duplicates
Expand Down Expand Up @@ -215,13 +216,15 @@ class TagsITest extends RESTTest {
assertTrue(response.data.contains([
tenantId: tenantId,
id : 'N1',
tags : ['a1': 'A', 'd1': 'B']
tags : ['a1': 'A', 'd1': 'B'],
type: 'GAUGE'
]))
assertTrue(response.data.contains([
tenantId : tenantId,
id : 'A2',
tags : [a1: 'A2', a22: '22', b22: '22'],
dataRetention: 48
dataRetention: 48,
type: 'AVAILABILITY'
]))

// Fetch with tags & type
Expand All @@ -232,7 +235,8 @@ class TagsITest extends RESTTest {
assertEquals([[
tenantId: tenantId,
id : 'N1',
tags : ['a1': 'A', 'd1': 'B']
tags : ['a1': 'A', 'd1': 'B'],
type: 'GAUGE'
]], response.data)

// Fetch with incorrect regexp
Expand Down

0 comments on commit ee9f169

Please sign in to comment.