Skip to content

Commit

Permalink
Merge pull request #634 from jshaughn/hwkmetrics-501
Browse files Browse the repository at this point in the history
HWKMETRICS-501 Fix
  • Loading branch information
Stefan Negrea committed Oct 10, 2016
2 parents d67fca9 + 23988fe commit 702876a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@

import org.hawkular.metrics.core.service.DelegatingDataAccess;
import org.hawkular.metrics.core.service.Order;
import org.hawkular.metrics.datetime.DateTimeService;
import org.hawkular.metrics.model.AvailabilityType;
import org.hawkular.metrics.model.DataPoint;
import org.hawkular.metrics.model.Metric;
import org.hawkular.metrics.model.MetricId;
import org.hawkular.metrics.model.Tenant;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.joda.time.Duration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
Expand All @@ -58,6 +60,7 @@ public class AvailabilityITest extends BaseMetricsITest {

protected PreparedStatement insertAvailabilityDateWithTimestamp;

@Override
@BeforeClass
public void initClass() {
super.initClass();
Expand Down Expand Up @@ -197,6 +200,53 @@ public void verifyTTLsSetOnAvailabilityData() throws Exception {
metricsService.addDataPoints(AVAILABILITY, Observable.just(m3)).toBlocking();
}

@Test
public void addAndCompressData() throws Exception {
DateTime dt = new DateTime(2016, 9, 2, 14, 15); // Causes writes to go to compressed and one uncompressed row
DateTimeUtils.setCurrentMillisFixed(dt.getMillis());

DateTime start = dt.minusMinutes(30);
DateTime end = start.plusMinutes(20);
String tenantId = "t1";

MetricId<AvailabilityType> mId = new MetricId<>(tenantId, AVAILABILITY, "m1");

metricsService.createTenant(new Tenant(tenantId), false).toBlocking().lastOrDefault(null);

Metric<AvailabilityType> m1 = new Metric<>(mId, asList(
new DataPoint<>(start.getMillis(), UP),
new DataPoint<>(start.plusMinutes(2).getMillis(), DOWN),
new DataPoint<>(start.plusMinutes(4).getMillis(), UP),
new DataPoint<>(end.getMillis(), DOWN)));

Observable<Void> insertObservable = metricsService.addDataPoints(AVAILABILITY, Observable.just(m1));
insertObservable.toBlocking().lastOrDefault(null);

metricsService.compressBlock(Observable.just(mId), DateTimeService.getTimeSlice(start.getMillis(), Duration
.standardHours(2)))
.doOnError(Throwable::printStackTrace).toBlocking().lastOrDefault(null);

Observable<DataPoint<AvailabilityType>> observable = metricsService.findDataPoints(mId, start.getMillis(),
end.getMillis() + 1, 0, Order.DESC);
List<DataPoint<AvailabilityType>> actual = toList(observable);
List<DataPoint<AvailabilityType>> expected = asList(
new DataPoint<>(end.getMillis(), DOWN),
new DataPoint<>(start.plusMinutes(4).getMillis(), UP),
new DataPoint<>(start.plusMinutes(2).getMillis(), DOWN),
new DataPoint<>(start.getMillis(), UP));

assertEquals(actual, expected, "The data does not match the expected values");
assertMetricIndexMatches("t1", AVAILABILITY,
singletonList(new Metric<>(m1.getMetricId(), m1.getDataPoints(), 7)));

observable = metricsService.findDataPoints(mId, start.getMillis(),
end.getMillis(), 0, Order.DESC);
actual = toList(observable);
assertEquals(3, actual.size(), "Last datapoint should be missing (<)");

DateTimeUtils.setCurrentMillisSystem();
}

private void addAvailabilityDataInThePast(Metric<AvailabilityType> metric, final Duration duration)
throws Exception {
try {
Expand Down
2 changes: 1 addition & 1 deletion dist/component-ear/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerter-metrics</artifactId>
<version>${version.org.hawkular.alerts}</version>
<version>${version.org.hawkular.alerter}</version>
<type>war</type>
</dependency>
<!-- Because metrics war has a dependency on alerting war (to inject AlertsService) and both components
Expand Down
2 changes: 1 addition & 1 deletion dist/standalone-ear/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerter-metrics</artifactId>
<version>${version.org.hawkular.alerts}</version>
<version>${version.org.hawkular.alerter}</version>
<type>war</type>
</dependency>
<!-- Because metrics war has a dependency on alerting war (to inject AlertsService) and both components
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/rest-tests-jaxrs-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>org.hawkular.alerts</groupId>
<artifactId>hawkular-alerter-metrics</artifactId>
<version>${version.org.hawkular.alerts}</version>
<version>${version.org.hawkular.alerter}</version>
<type>war</type>
</dependency>
<!-- Because metrics war has a dependency on alerting war (to inject AlertsService) and both components
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
<!-- Dependencies versions -->
<version.org.cassalog>0.3.1</version.org.cassalog>
<version.org.hawkular.accounts>2.0.26.Final</version.org.hawkular.accounts>
<version.org.hawkular.alerts>1.2.1.Final</version.org.hawkular.alerts>
<version.org.hawkular.alerts>1.2.2.Final</version.org.hawkular.alerts>
<version.org.hawkular.alerter>1.2.1.Final</version.org.hawkular.alerter>
<version.org.hawkular.commons>0.7.1.Final</version.org.hawkular.commons>
<version.javax.enterprise.cdi-api>1.2</version.javax.enterprise.cdi-api>
<version.joda-time>2.7</version.joda-time>
Expand Down

0 comments on commit 702876a

Please sign in to comment.