Skip to content

Commit

Permalink
Fix imports in MetricsServiceImpl, filter nonUserDefinable types from…
Browse files Browse the repository at this point in the history
… findMetricsWithTags and add a test for tags+type filtering
  • Loading branch information
Michael Burman committed Jul 9, 2015
1 parent aeaafcf commit dad3564
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Session;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import org.hawkular.metrics.core.api.AvailabilityBucketDataPoint;
import org.hawkular.metrics.core.api.AvailabilityType;
import org.hawkular.metrics.core.api.BucketedOutput;
Expand All @@ -80,10 +68,26 @@
import org.joda.time.Hours;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.Session;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

import rx.Observable;
import rx.functions.Func1;
import rx.subjects.PublishSubject;

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

/**
* @author John Sanda
*/
Expand Down Expand Up @@ -472,7 +476,8 @@ public Observable<Metric> findMetrics(String tenantId, MetricType type) {
public Observable<Metric> findMetricsWithTags(String tenantId, Map<String, String> tags, MetricType type) {
return dataAccess.findMetricsFromTagsIndex(tenantId, tags)
.flatMap(Observable::from)
.filter(r -> (type == null || MetricType.fromCode(r.getInt(0)) == type))
.filter(r -> ((type == null && MetricType.userTypes().contains(MetricType.fromCode(r.getInt(0))))
|| MetricType.fromCode(r.getInt(0)) == type))
.distinct(r -> Integer.valueOf(r.getInt(0)).toString() + r.getString(1) + r.getString(2))
.flatMap(r -> findMetric(tenantId, MetricType.fromCode(r.getInt(0)), new MetricId(r.getString
(1), Interval.parse(r.getString(2)))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ public void createAndFindMetrics() throws Exception {
.toList().toBlocking().lastOrDefault(null);
assertEquals(metrics.size(), 3, "The returned size does not match expected");

metrics = metricsService.findMetricsWithTags("t1", tagMap, AVAILABILITY).toList().toBlocking()
.lastOrDefault(null);
assertEquals(metrics.size(), 1, "The returned size does not match expected, only m2 is expected");

Metric actualAvail = metricsService.findMetric(m2.getTenantId(), m2.getType(), m2.getId()).toBlocking()
.last();
assertEquals(actualAvail, m2, "The metric does not match the expected value");
Expand Down

0 comments on commit dad3564

Please sign in to comment.