/** * This method is used to log delayed metrics, if tracking delayed metrics * is turned on for this Blueflood service. * @param tenantid * @param delayedMetrics */ public void trackDelayedMetricsTenant(String tenantid, final List<Metric> delayedMetrics) { if (isTrackingDelayedMetrics) { String logMessage = String.format("[TRACKER][DELAYED METRIC] Tenant sending delayed metrics %s", tenantid); log.info(logMessage); // log individual delayed metrics locator and collectionTime double delayedMinutes; long nowMillis = System.currentTimeMillis(); for (Metric metric : delayedMetrics) { delayedMinutes = (double)(nowMillis - metric.getCollectionTime()) / 1000 / 60; logMessage = String.format("[TRACKER][DELAYED METRIC] %s has collectionTime %s which is delayed by %.2f minutes", metric.getLocator().toString(), dateFormatter.format(new Date(metric.getCollectionTime())), delayedMinutes); log.info(logMessage); } } }
@Test public void testTrackDelayedAggregatedMetricsTenant() { // enable tracking delayed metrics and track tracker.setIsTrackingDelayedMetrics(); List<String> delayedMetricNames = new ArrayList<String>() {{ for ( Metric metric : delayedMetrics ) { add(metric.getLocator().toString()); } }}; long ingestTime = System.currentTimeMillis(); tracker.trackDelayedAggregatedMetricsTenant(tenantId, delayedMetrics.get(0).getCollectionTime(), ingestTime, delayedMetricNames); // verify verify(loggerMock, atLeastOnce()).info("[TRACKER] Tracking delayed metrics started"); verify(loggerMock, atLeastOnce()).info("[TRACKER][DELAYED METRIC] Tenant sending delayed metrics " + tenantId); verify(loggerMock, atLeastOnce()).info(contains("[TRACKER][DELAYED METRIC] " + tenantId + ".delayed.metric1" + "," + tenantId + ".delayed.metric2 have collectionTime 2016-01-01 00:00:00 which is delayed")); }
@Test public void testJSONMetricsContainerConstruction() throws Exception { // Construct the JSONMetricsContainter from JSON metric objects JSONMetricsContainer jsonMetricsContainer = getContainer( "ac1", generateJSONMetricsData() ); List<Metric> metricsCollection = jsonMetricsContainer.getValidMetrics(); assertTrue( jsonMetricsContainer.getValidationErrors().isEmpty() ); assertTrue( metricsCollection.size() == 2 ); assertEquals( "ac1.mzord.duration", metricsCollection.get( 0 ).getLocator().toString() ); assertEquals( Long.MAX_VALUE, metricsCollection.get( 0 ).getMetricValue() ); assertEquals( 1234566, metricsCollection.get( 0 ).getTtlInSeconds() ); assertTrue( current - metricsCollection.get( 0 ).getCollectionTime() < MINUTE ); assertEquals( "milliseconds", metricsCollection.get( 0 ).getUnit() ); assertEquals( "ac1.mzord.status", metricsCollection.get( 1 ).getLocator().toString() ); assertEquals( 0, metricsCollection.get( 1 ).getMetricValue() ); assertEquals( "unknown", metricsCollection.get( 1 ).getUnit() ); }