package com.salesforce.dva.argus.service.tsdb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;

/**
 * Federation by forking large range queries into smaller range sub queries
 *
 * @author  Dilip Devaraj (ddevaraj@salesforce.com)
 */
public class TimeQueryFederation extends QueryFederation{

	private static final long TIME_FEDERATE_LIMIT_MILLIS = 86400000L;
	// private static final long TIME_FEDERATE_LIMIT_MILLIS = 3600000L;

	@Override
	public Map<MetricQuery, List<MetricQuery>> federateQueries(List<MetricQuery> queries) {
		Map<MetricQuery, List<MetricQuery>> mapQuerySubQueries = new HashMap<>();
		for (MetricQuery query : queries) {

			List<MetricQuery> metricSubQueries = new ArrayList<>();
			if (query.getEndTimestamp() - query.getStartTimestamp() > TIME_FEDERATE_LIMIT_MILLIS) {
				LoggerFactory.getLogger(getClass()).info("Federating into multiple sub queries based on time " + TIME_FEDERATE_LIMIT_MILLIS);
				for (long time = query.getStartTimestamp(); time <= query.getEndTimestamp(); time = time + TIME_FEDERATE_LIMIT_MILLIS) {
					MetricQuery mq = new MetricQuery(query);
					mq.setStartTimestamp(time);
					if (time + TIME_FEDERATE_LIMIT_MILLIS > query.getEndTimestamp()) {
						mq.setEndTimestamp(query.getEndTimestamp());
					} else {
						mq.setEndTimestamp(time + TIME_FEDERATE_LIMIT_MILLIS);
					}
					metricSubQueries.add(mq);
				}
				mapQuerySubQueries.put(query, metricSubQueries);
			} else {
				metricSubQueries.add(query);
				mapQuerySubQueries.put(query, metricSubQueries);
			}
		}
		return mapQuerySubQueries;
	}
}
@@ -145,41 +145,8 @@
 p;%0A%0A
-import org.slf4j.LoggerFactory;%0A%0A
 /**%0A
@@ -409,77 +409,8 @@
 00L;
-%0A%09// private static final long TIME_FEDERATE_LIMIT_MILLIS = 3600000L;
 %0A%0A%09@
@@ -681,16 +681,16 @@
 st%3C%3E();%0A
+
 %09%09%09if (q
@@ -776,138 +776,8 @@
 ) %7B%0A
-%09%09%09%09LoggerFactory.getLogger(getClass()).info(%22Federating into multiple sub queries based on time %22 + TIME_FEDERATE_LIMIT_MILLIS);%0A
 %09%09%09%09

Undo some changes