The timestamp on MetricEnvelope was changed to be seconds not milliseconds to be more consistent with other timestamps used across components. Changed the code and tests to adapt to this change.

Update to the build 51 of mon-common that has this change
This commit is contained in:
Craig Bryant 2014-05-06 16:36:38 -06:00
parent 74bde59399
commit 57a2012792
5 changed files with 23 additions and 23 deletions

View File

@ -14,7 +14,7 @@
</prerequisites> </prerequisites>
<properties> <properties>
<mon.common.version>1.0.0.49</mon.common.version> <mon.common.version>1.0.0.51</mon.common.version>
<storm.version>0.9.1-incubating</storm.version> <storm.version>0.9.1-incubating</storm.version>
<skipITs>true</skipITs> <skipITs>true</skipITs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -84,9 +84,9 @@ public class MetricFilteringBolt extends BaseRichBolt {
public static final int LAG_MESSAGE_PERIOD_DEFAULT = 30; public static final int LAG_MESSAGE_PERIOD_DEFAULT = 30;
public static final String[] FIELDS = new String[] { "metricDefinitionAndTenantId", "metric" }; public static final String[] FIELDS = new String[] { "metricDefinitionAndTenantId", "metric" };
private static final int MIN_LAG_VALUE = 1000 * PropertyFinder.getIntProperty(MIN_LAG_VALUE_KEY, MIN_LAG_VALUE_DEFAULT, 0, Integer.MAX_VALUE); private static final int MIN_LAG_VALUE = PropertyFinder.getIntProperty(MIN_LAG_VALUE_KEY, MIN_LAG_VALUE_DEFAULT, 0, Integer.MAX_VALUE);
private static final int MAX_LAG_MESSAGES = PropertyFinder.getIntProperty(MAX_LAG_MESSAGES_KEY, MAX_LAG_MESSAGES_DEFAULT, 0, Integer.MAX_VALUE); private static final int MAX_LAG_MESSAGES = PropertyFinder.getIntProperty(MAX_LAG_MESSAGES_KEY, MAX_LAG_MESSAGES_DEFAULT, 0, Integer.MAX_VALUE);
private static final int LAG_MESSAGE_PERIOD = 1000 * PropertyFinder.getIntProperty(LAG_MESSAGE_PERIOD_KEY, LAG_MESSAGE_PERIOD_DEFAULT, 1, 600); private static final int LAG_MESSAGE_PERIOD = PropertyFinder.getIntProperty(LAG_MESSAGE_PERIOD_KEY, LAG_MESSAGE_PERIOD_DEFAULT, 1, 600);
private static final Map<MetricDefinitionAndTenantId, List<String>> METRIC_DEFS = new ConcurrentHashMap<>(); private static final Map<MetricDefinitionAndTenantId, List<String>> METRIC_DEFS = new ConcurrentHashMap<>();
private static final MetricDefinitionAndTenantIdMatcher matcher = new MetricDefinitionAndTenantIdMatcher(); private static final MetricDefinitionAndTenantIdMatcher matcher = new MetricDefinitionAndTenantIdMatcher();
private static final Object SENTINAL = new Object(); private static final Object SENTINAL = new Object();
@ -220,9 +220,9 @@ public class MetricFilteringBolt extends BaseRichBolt {
collector.emit(new Values(metricDefinitionAndTenantId, null)); collector.emit(new Values(metricDefinitionAndTenantId, null));
LOG.info("Found {} Metric Definitions", METRIC_DEFS.size()); LOG.info("Found {} Metric Definitions", METRIC_DEFS.size());
// Just output these here so they are only output once per JVM // Just output these here so they are only output once per JVM
LOG.info("MIN_LAG_VALUE set to {} seconds", MIN_LAG_VALUE/1000); LOG.info("MIN_LAG_VALUE set to {} seconds", MIN_LAG_VALUE);
LOG.info("MAX_LAG_MESSAGES set to {}", MAX_LAG_MESSAGES); LOG.info("MAX_LAG_MESSAGES set to {}", MAX_LAG_MESSAGES);
LOG.info("LAG_MESSAGE_PERIOD set to {} seconds", LAG_MESSAGE_PERIOD/1000); LOG.info("LAG_MESSAGE_PERIOD set to {} seconds", LAG_MESSAGE_PERIOD);
} }
} }
} }
@ -233,7 +233,7 @@ public class MetricFilteringBolt extends BaseRichBolt {
* Allow override of current time for testing. * Allow override of current time for testing.
*/ */
protected long getCurrentTime() { protected long getCurrentTime() {
return System.currentTimeMillis(); return System.currentTimeMillis()/1000;
} }
private void addMetricDef(MetricDefinitionAndTenantId metricDefinitionAndTenantId, String subAlarmId) { private void addMetricDef(MetricDefinitionAndTenantId metricDefinitionAndTenantId, String subAlarmId) {

View File

@ -241,13 +241,13 @@ public class ThresholdingEngineAlarmTest extends TopologyTestCase {
else { else {
System.out.println("Feeding metrics..."); System.out.println("Feeding metrics...");
long time = System.currentTimeMillis(); long time = System.currentTimeMillis()/1000;
++goodValueCount; ++goodValueCount;
for (final SubAlarm subAlarm : subAlarms) { for (final SubAlarm subAlarm : subAlarms) {
final MetricDefinitionAndTenantId metricDefinitionAndTenantId = final MetricDefinitionAndTenantId metricDefinitionAndTenantId =
new MetricDefinitionAndTenantId(subAlarm.getExpression().getMetricDefinition(), TEST_ALARM_TENANT_ID); new MetricDefinitionAndTenantId(subAlarm.getExpression().getMetricDefinition(), TEST_ALARM_TENANT_ID);
metricSpout.feed(new Values(metricDefinitionAndTenantId, time, metricSpout.feed(new Values(metricDefinitionAndTenantId, time,
new Metric(metricDefinitionAndTenantId.metricDefinition, time / 1000, (double) (goodValueCount == 15 ? 1 : 555)))); new Metric(metricDefinitionAndTenantId.metricDefinition, time, (double) (goodValueCount == 15 ? 1 : 555))));
} }
} }
try { try {

View File

@ -192,11 +192,11 @@ public class ThresholdingEngineTest extends TopologyTestCase {
if (feedCount > 0) { if (feedCount > 0) {
System.out.println("Feeding metrics..."); System.out.println("Feeding metrics...");
long time = System.currentTimeMillis(); long time = System.currentTimeMillis()/1000;
metricSpout.feed(new Values(new MetricDefinitionAndTenantId(cpuMetricDef, TEST_ALARM_TENANT_ID), time, metricSpout.feed(new Values(new MetricDefinitionAndTenantId(cpuMetricDef, TEST_ALARM_TENANT_ID), time,
new Metric(cpuMetricDef.name, cpuMetricDef.dimensions, time / 1000, (double) (++goodValueCount == 15 ? 1 : 555)))); new Metric(cpuMetricDef.name, cpuMetricDef.dimensions, time, (double) (++goodValueCount == 15 ? 1 : 555))));
metricSpout.feed(new Values(new MetricDefinitionAndTenantId(memMetricDef, TEST_ALARM_TENANT_ID), time, metricSpout.feed(new Values(new MetricDefinitionAndTenantId(memMetricDef, TEST_ALARM_TENANT_ID), time,
new Metric(memMetricDef.name, extraMemMetricDefDimensions, time / 1000, (double) (goodValueCount == 15 ? 1 : 555)))); new Metric(memMetricDef.name, extraMemMetricDefDimensions, time, (double) (goodValueCount == 15 ? 1 : 555))));
if (--feedCount == 0) if (--feedCount == 0)
waitCount = 3; waitCount = 3;

View File

@ -109,19 +109,19 @@ public class MetricFilteringBoltTest {
final long prepareTime = bolt.getCurrentTime(); final long prepareTime = bolt.getCurrentTime();
final MetricDefinition metricDefinition = subAlarms.get(0).getExpression().getMetricDefinition(); final MetricDefinition metricDefinition = subAlarms.get(0).getExpression().getMetricDefinition();
final long oldestTimestamp = prepareTime - MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT*1000; final long oldestTimestamp = prepareTime - MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT;
final Tuple lateMetricTuple = createMetricTuple(metricDefinition, oldestTimestamp, new Metric(metricDefinition, oldestTimestamp/1000, 42.0)); final Tuple lateMetricTuple = createMetricTuple(metricDefinition, oldestTimestamp, new Metric(metricDefinition, oldestTimestamp, 42.0));
bolt.execute(lateMetricTuple); bolt.execute(lateMetricTuple);
verify(collector, times(1)).ack(lateMetricTuple); verify(collector, times(1)).ack(lateMetricTuple);
bolt.setCurrentTime(prepareTime + MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT*1000); bolt.setCurrentTime(prepareTime + MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT);
final Tuple lateMetricTuple2 = createMetricTuple(metricDefinition, prepareTime, new Metric(metricDefinition, prepareTime/1000, 42.0)); final Tuple lateMetricTuple2 = createMetricTuple(metricDefinition, prepareTime, new Metric(metricDefinition, prepareTime, 42.0));
bolt.execute(lateMetricTuple2); bolt.execute(lateMetricTuple2);
verify(collector, times(1)).ack(lateMetricTuple2); verify(collector, times(1)).ack(lateMetricTuple2);
verify(collector, times(1)).emit(MetricAggregationBolt.METRIC_AGGREGATION_CONTROL_STREAM, verify(collector, times(1)).emit(MetricAggregationBolt.METRIC_AGGREGATION_CONTROL_STREAM,
new Values(MetricAggregationBolt.METRICS_BEHIND)); new Values(MetricAggregationBolt.METRICS_BEHIND));
bolt.setCurrentTime(prepareTime + 2 * MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT * 1000); bolt.setCurrentTime(prepareTime + 2 * MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT);
long caughtUpTimestamp = bolt.getCurrentTime() - MetricFilteringBolt.MIN_LAG_VALUE_DEFAULT; long caughtUpTimestamp = bolt.getCurrentTime() - MetricFilteringBolt.MIN_LAG_VALUE_DEFAULT;
final Tuple metricTuple = createMetricTuple(metricDefinition, caughtUpTimestamp, new Metric(metricDefinition, caughtUpTimestamp/1000, 42.0)); final Tuple metricTuple = createMetricTuple(metricDefinition, caughtUpTimestamp, new Metric(metricDefinition, caughtUpTimestamp, 42.0));
bolt.execute(metricTuple); bolt.execute(metricTuple);
// Metrics are caught up so there should not be another METRICS_BEHIND message // Metrics are caught up so there should not be another METRICS_BEHIND message
verify(collector, times(1)).ack(metricTuple); verify(collector, times(1)).ack(metricTuple);
@ -141,8 +141,8 @@ public class MetricFilteringBoltTest {
// Need to send MetricFilteringBolt.MAX_LAG_MESSAGES_DEFAULT + 1 metrics because the lag message is not // Need to send MetricFilteringBolt.MAX_LAG_MESSAGES_DEFAULT + 1 metrics because the lag message is not
// output on the first one. // output on the first one.
for (int i = 0; i < MetricFilteringBolt.MAX_LAG_MESSAGES_DEFAULT + 1; i++) { for (int i = 0; i < MetricFilteringBolt.MAX_LAG_MESSAGES_DEFAULT + 1; i++) {
final Tuple lateMetricTuple = createMetricTuple(metricDefinition, prepareTime, new Metric(metricDefinition, prepareTime/1000, 42.0)); final Tuple lateMetricTuple = createMetricTuple(metricDefinition, prepareTime, new Metric(metricDefinition, prepareTime, 42.0));
bolt.setCurrentTime(prepareTime + MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT * 1000); bolt.setCurrentTime(prepareTime + MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT);
bolt.execute(lateMetricTuple); bolt.execute(lateMetricTuple);
verify(collector, times(1)).ack(lateMetricTuple); verify(collector, times(1)).ack(lateMetricTuple);
if (!first) { if (!first) {
@ -153,8 +153,8 @@ public class MetricFilteringBoltTest {
prepareTime = bolt.getCurrentTime(); prepareTime = bolt.getCurrentTime();
} }
// One more // One more
long timestamp = bolt.getCurrentTime() - MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT * 1000; long timestamp = bolt.getCurrentTime() - MetricFilteringBolt.LAG_MESSAGE_PERIOD_DEFAULT;
final Tuple metricTuple = createMetricTuple(metricDefinition, timestamp, new Metric(metricDefinition, timestamp/1000, 42.0)); final Tuple metricTuple = createMetricTuple(metricDefinition, timestamp, new Metric(metricDefinition, timestamp, 42.0));
bolt.execute(metricTuple); bolt.execute(metricTuple);
verify(collector, times(1)).ack(metricTuple); verify(collector, times(1)).ack(metricTuple);
// Won't be any more of these // Won't be any more of these
@ -224,7 +224,7 @@ public class MetricFilteringBoltTest {
for (final SubAlarm subAlarm : subAlarms) { for (final SubAlarm subAlarm : subAlarms) {
// First do a MetricDefinition that is an exact match // First do a MetricDefinition that is an exact match
final MetricDefinition metricDefinition = subAlarm.getExpression().getMetricDefinition(); final MetricDefinition metricDefinition = subAlarm.getExpression().getMetricDefinition();
final Tuple exactTuple = createMetricTuple(metricDefinition, metricTimestamp++ * 1000, new Metric(metricDefinition, metricTimestamp, 42.0)); final Tuple exactTuple = createMetricTuple(metricDefinition, metricTimestamp++, new Metric(metricDefinition, metricTimestamp, 42.0));
bolt1.execute(exactTuple); bolt1.execute(exactTuple);
verify(collector1, times(1)).ack(exactTuple); verify(collector1, times(1)).ack(exactTuple);
verify(collector1, howMany).emit(new Values(exactTuple.getValue(0), exactTuple.getValue(2))); verify(collector1, howMany).emit(new Values(exactTuple.getValue(0), exactTuple.getValue(2)));
@ -234,7 +234,7 @@ public class MetricFilteringBoltTest {
extraDimensions.put("group", "group_a"); extraDimensions.put("group", "group_a");
final MetricDefinition inexactMetricDef = new MetricDefinition(metricDefinition.name, extraDimensions); final MetricDefinition inexactMetricDef = new MetricDefinition(metricDefinition.name, extraDimensions);
Metric inexactMetric = new Metric(inexactMetricDef, metricTimestamp, 42.0); Metric inexactMetric = new Metric(inexactMetricDef, metricTimestamp, 42.0);
final Tuple inexactTuple = createMetricTuple(metricDefinition, metricTimestamp++ * 1000, inexactMetric); final Tuple inexactTuple = createMetricTuple(metricDefinition, metricTimestamp++, inexactMetric);
bolt1.execute(inexactTuple); bolt1.execute(inexactTuple);
verify(collector1, times(1)).ack(inexactTuple); verify(collector1, times(1)).ack(inexactTuple);
// We want the MetricDefinitionAndTenantId from the exact tuple, but the inexactMetric // We want the MetricDefinitionAndTenantId from the exact tuple, but the inexactMetric