if (!CheckFromJson.isValid(checkFromJson)) {
invalidMetricsCounter.inc();
} else {
for (String metricName : checkFromJson.getMetricNames()) {
MetricPoint metricPoint = checkFromJson.getMetric(metricName);
// Bail out for string metrics
if(metricPoint.getType() == String.class) {
line = reader.readLine();
continue;
}
Locator metricLocator;
if(checkFromJson.getCheckType().contains("remote")) {
String longMetricName = String.format("%s.rackspace.monitoring.entities.%s.checks.%s.%s.%s.%s",
checkFromJson.getTenantId(),
checkFromJson.getEntityId(),
checkFromJson.getCheckType(),
checkFromJson.getCheckId(),
checkFromJson.getMonitoringZoneId(),
metricName).trim();
metricLocator = Locator.createLocatorFromDbKey(longMetricName);
} else {
String longMetricName = String.format("%s.rackspace.monitoring.entities.%s.checks.%s.%s.%s",
checkFromJson.getTenantId(),
checkFromJson.getEntityId(),
checkFromJson.getCheckType(),
checkFromJson.getCheckId(),
metricName).trim();
metricLocator = Locator.createLocatorFromDbKey(longMetricName);
}
if (!shardsToBackfill.contains(Util.computeShard(metricLocator.toString()))) {
line = reader.readLine();
continue;
}
long timestamp = checkFromJson.getTimestamp();
long snappedMillis = Granularity.MIN_5.snapMillis(timestamp);
Range rangeOfThisTimestamp = new Range(snappedMillis, snappedMillis + Granularity.MIN_5.milliseconds() - 1);
//Do not add timestamps that lie out of range
if (!rangesToRollup.contains(rangeOfThisTimestamp)) {
log.warn("Timestamp of metric found lying out the range: "+rangeOfThisTimestamp+" TS: "+timestamp);
line = reader.readLine();
continue;
}
//These are out of band timestamps lying in the ranges which we have already rolled
if (rangesToRollup.contains(rangeOfThisTimestamp) && !rangesStillApplicable.contains(rangeOfThisTimestamp)) {
log.warn("Range of timestamp of metric "+ metricLocator + "is out of applicable ranges");
outOfRangeToleration++;
// If we are seeing a lot of out of band metrics, something is wrong. May be metrics are back logged a lot. stop immediately. try to increase the range buffer?
if (outOfRangeToleration > OUT_OF_RANGE_TOLERATION_THRESHOLD) {
throw new OutOFBandException("Starting to see a lot of metrics in non-applicable ranges");
}
line = reader.readLine();
continue;
}
// The following it required because concurrent data structure provides weak consistency. For eg. Two threads both calling get will see different results. putIfAbsent provides atomic operation
ConcurrentHashMap<Locator, Points> tsToPoint = locatorToTimestampToPoint.get(rangeOfThisTimestamp);
if(tsToPoint == null) {
// Need to synchronize this HashMap, because multiple threads might be calling containsKey and then putting values at the same time
final ConcurrentHashMap<Locator, Points> tsToPointVal = new ConcurrentHashMap<Locator, Points>();
tsToPoint = locatorToTimestampToPoint.putIfAbsent(rangeOfThisTimestamp, tsToPointVal);
if (tsToPoint == null) {
tsToPoint = tsToPointVal;
}
}
Points points = tsToPoint.get(metricLocator);
if (points == null) {
Points pointsToPut = new Points();
points = tsToPoint.putIfAbsent(metricLocator, pointsToPut);
if (points == null) {
points = pointsToPut;
}
}
points.add(new Points.Point(timestamp, new SimpleNumber(metricPoint.getValue())));
metricsParsedAndMergedMeter.mark();
/*
if (tsToPoint.containsKey(metricLocator)) {