@Test public void testIncorrectParseSkip() throws IOException { List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("app").setTagValue("1").build(), Tag.newBuilder().setTagKey("server").setTagValue("1").build(), Tag.newBuilder().setTagKey("s").setTagValue("jvm").build()); GraphiteDecoder.parseAndInsertDataPoints("test", "app=1 1497720452", engine); GraphiteDecoder.parseAndInsertDataPoints("test", "app=1.app=2 1497720452", engine); GraphiteDecoder.parseAndInsertDataPoints("test", "app1.server1.jvm.heap.max233123 1497720452\n" + "app=1.server=2.s=jvm.heap.max 2331231497720452", engine); verify(engine, times(0)).writeDataPointWithLock( MiscUtils.buildDataPoint("test", "heap", "max", tags, ((long) 1497720452) * 1000, 233123), false); tags = Arrays.asList(Tag.newBuilder().setTagKey("server").setTagValue("2").build()); GraphiteDecoder.parseAndInsertDataPoints("test", "app=1.server=1.heap 233123 1497720452", engine); verify(engine, times(0)).writeDataPointWithLock( MiscUtils.buildDataPoint("test", "heap", "max", tags, ((long) 1497720452) * 1000, 233123), false); }
public static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine) throws IOException { String[] parts = line.split("\\s+"); if (parts.length != 3) { logger.fine("Ignoring bad metric:" + line); return; } String[] key = parts[0].split("\\."); String measurementName, valueFieldName; List<Tag> tags = new ArrayList<>(); switch (key.length) { case 0: case 1: case 2: logger.fine("Ignoring bad metric:" + line); return; default: measurementName = key[key.length - 2]; valueFieldName = key[key.length - 1]; for (int i = 0; i < key.length - 2; i++) { String[] split = key[i].split(Measurement.TAG_KV_SEPARATOR); if (split.length != 2) { throw BAD_TAG_EXCEPTION; } tags.add(Tag.newBuilder().setTagKey(split[0]).setTagValue(split[1]).build()); } break; } long timestamp = Long.parseLong(parts[2]) * 1000; if (parts[1].contains(".")) { double value = Double.parseDouble(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } else { long value = Long.parseLong(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } }
GraphiteDecoder extends SimpleChannelInboundHandler<String> { public static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine) throws IOException { String[] parts = line.split("\\s+"); if (parts.length != 3) { logger.fine("Ignoring bad metric:" + line); return; } String[] key = parts[0].split("\\."); String measurementName, valueFieldName; List<Tag> tags = new ArrayList<>(); switch (key.length) { case 0: case 1: case 2: logger.fine("Ignoring bad metric:" + line); return; default: measurementName = key[key.length - 2]; valueFieldName = key[key.length - 1]; for (int i = 0; i < key.length - 2; i++) { String[] split = key[i].split(Measurement.TAG_KV_SEPARATOR); if (split.length != 2) { throw BAD_TAG_EXCEPTION; } tags.add(Tag.newBuilder().setTagKey(split[0]).setTagValue(split[1]).build()); } break; } long timestamp = Long.parseLong(parts[2]) * 1000; if (parts[1].contains(".")) { double value = Double.parseDouble(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } else { long value = Long.parseLong(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } } }
GraphiteDecoder extends SimpleChannelInboundHandler<String> { public static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine) throws IOException { String[] parts = line.split("\\s+"); if (parts.length != 3) { logger.fine("Ignoring bad metric:" + line); return; } String[] key = parts[0].split("\\."); String measurementName, valueFieldName; List<Tag> tags = new ArrayList<>(); switch (key.length) { case 0: case 1: case 2: logger.fine("Ignoring bad metric:" + line); return; default: measurementName = key[key.length - 2]; valueFieldName = key[key.length - 1]; for (int i = 0; i < key.length - 2; i++) { String[] split = key[i].split(Measurement.TAG_KV_SEPARATOR); if (split.length != 2) { throw BAD_TAG_EXCEPTION; } tags.add(Tag.newBuilder().setTagKey(split[0]).setTagValue(split[1]).build()); } break; } long timestamp = Long.parseLong(parts[2]) * 1000; if (parts[1].contains(".")) { double value = Double.parseDouble(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } else { long value = Long.parseLong(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } } GraphiteDecoder(String dbName, StorageEngine storageEngine, Counter writeCounter); }
GraphiteDecoder extends SimpleChannelInboundHandler<String> { public static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine) throws IOException { String[] parts = line.split("\\s+"); if (parts.length != 3) { logger.fine("Ignoring bad metric:" + line); return; } String[] key = parts[0].split("\\."); String measurementName, valueFieldName; List<Tag> tags = new ArrayList<>(); switch (key.length) { case 0: case 1: case 2: logger.fine("Ignoring bad metric:" + line); return; default: measurementName = key[key.length - 2]; valueFieldName = key[key.length - 1]; for (int i = 0; i < key.length - 2; i++) { String[] split = key[i].split(Measurement.TAG_KV_SEPARATOR); if (split.length != 2) { throw BAD_TAG_EXCEPTION; } tags.add(Tag.newBuilder().setTagKey(split[0]).setTagValue(split[1]).build()); } break; } long timestamp = Long.parseLong(parts[2]) * 1000; if (parts[1].contains(".")) { double value = Double.parseDouble(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } else { long value = Long.parseLong(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } } GraphiteDecoder(String dbName, StorageEngine storageEngine, Counter writeCounter); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine); }
GraphiteDecoder extends SimpleChannelInboundHandler<String> { public static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine) throws IOException { String[] parts = line.split("\\s+"); if (parts.length != 3) { logger.fine("Ignoring bad metric:" + line); return; } String[] key = parts[0].split("\\."); String measurementName, valueFieldName; List<Tag> tags = new ArrayList<>(); switch (key.length) { case 0: case 1: case 2: logger.fine("Ignoring bad metric:" + line); return; default: measurementName = key[key.length - 2]; valueFieldName = key[key.length - 1]; for (int i = 0; i < key.length - 2; i++) { String[] split = key[i].split(Measurement.TAG_KV_SEPARATOR); if (split.length != 2) { throw BAD_TAG_EXCEPTION; } tags.add(Tag.newBuilder().setTagKey(split[0]).setTagValue(split[1]).build()); } break; } long timestamp = Long.parseLong(parts[2]) * 1000; if (parts[1].contains(".")) { double value = Double.parseDouble(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } else { long value = Long.parseLong(parts[1]); logger.fine("Writing graphite metric (fp)" + dbName + "," + measurementName + "," + valueFieldName + "," + tags + "," + timestamp + "," + value); storageEngine.writeDataPointWithLock( MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, timestamp, value), false); } } GraphiteDecoder(String dbName, StorageEngine storageEngine, Counter writeCounter); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); static void parseAndInsertDataPoints(String dbName, String line, StorageEngine storageEngine);  }