/** * Aggregates any sub stats that may have been created. */ public void join() { for (Stat subStat : subStats) { this.value += subStat.getValue(); } } }
/** * Aggregates any sub stats that may have been created. */ public void join() { for (Stat subStat : subStats) { this.value += subStat.getValue(); } } }
public static Predicate<Stat> isMatch(StatFilter filter) { return stat -> { if ((stat.getValue() != 0 && !filter.reportZeros)) { return false; } if (filter.name != null && !stat.getName().equals(filter.name)) { return false; } if (!stat.getTags().containsAll(filter.tags)) { return false; } return true; }; } }
public static Predicate<Stat> isMatch(StatFilter filter) { return stat -> { if ((stat.getValue() != 0 && !filter.reportZeros)) { return false; } if (filter.name != null && !stat.getName().equals(filter.name)) { return false; } if (!stat.getTags().containsAll(filter.tags)) { return false; } return true; }; } }
@Override public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) { Set<Tag> allTags = new HashSet<Tag>(); /* * DataDog only tracks to second precision */ long ts = invokeTimeMs / 1000; for (Stat stat : stats) { allTags.addAll(tags); allTags.addAll(stat.getTags()); String tagsString = allTags.stream().map(e -> formatEntry(e.getKey(), e.getValue())) .collect(Collectors.joining(",")); /* * MONITORING|unix_epoch_timestamp|value|metric_type|my.metric.name|#tag1:value,tag2 */ String[] logParts = {"MONITORING", "" + ts, "" + stat.getValue(), stat.getType().name(), prefix + "." + stat.getName(), "#" + tagsString}; allTags.clear(); System.out.println(String.join("|", logParts)); } }
@Override public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) { Set<Tag> allTags = new HashSet<Tag>(); /* * DataDog only tracks to second precision */ long ts = invokeTimeMs / 1000; for (Stat stat : stats) { allTags.addAll(tags); allTags.addAll(stat.getTags()); String tagsString = allTags.stream().map(e -> formatEntry(e.getKey(), e.getValue())) .collect(Collectors.joining(",")); /* * MONITORING|unix_epoch_timestamp|value|metric_type|my.metric.name|#tag1:value,tag2 */ String[] logParts = {"MONITORING", "" + ts, "" + stat.getValue(), stat.getType().name(), prefix + "." + stat.getName(), "#" + tagsString}; allTags.clear(); System.out.println(String.join("|", logParts)); } }
@Override public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) { Set<Tag> allTags = new HashSet<Tag>(); for (Stat stat : stats) { allTags.addAll(tags); allTags.addAll(stat.getTags()); String tagsString = allTags.stream().map(e -> formatEntry(e.getKey(), e.getValue())) .collect(Collectors.joining(",")); String metric = String.format("%s %s %d", stat.getName(), tagsString, stat.getValue()); buffer.add(metric); allTags.clear(); } }
metric.setTimestamp(dt); metric.setDimensions(metricDims); metric.setValue((double) stat.getValue());
metric.setTimestamp(dt); metric.setDimensions(metricDims); metric.setValue((double) stat.getValue());
@Test public void testSerializationException() throws HandlerException, SerializationException { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); Serializer serSpy = spy(handler.ser.getSerializer()); doThrow(new DeserializationException("")).when(serSpy).serialize(any()); handler.ser.setSerializer(serSpy); handler.handler(events, context); assertEquals(1, handler.ser.getErrorCountStat().getValue()); }
@Test public void testDeserializationException() throws HandlerException { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); DeserializerProcessor proc = handler.sources.get(0).getDeserProcessor(); Deserializer deserSpy = spy(proc.getDeserializer()); doThrow(new DeserializationException("expected")).when(deserSpy).deserialize(anyString()); proc.setDeserializer(deserSpy); handler.handler(events, context); assertEquals(1, proc.getErrorCountStat().getValue()); }
@Test public void testOperationException() throws HandlerException { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); List<OperationProcessor> operationProcessors = handler.sources.get(0).getOperationProcessors(); for (OperationProcessor operationProcessor : operationProcessors) { EventOperation operation = (EventOperation) spy(operationProcessor.getOperation()); doThrow(new OperationException("expected")).when(operation).perform(any()); operationProcessor.setOperation(operation); } handler.handler(events, context); assertEquals(1, operationProcessors.get(0).getErrorCountStat().getValue()); }
@Test public void testIpcOnAddFailure() throws Throwable { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(2); events.add(new DummyEvent("foo", 0)); events.add(new DummyEvent("bar", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); TransportBuffer tbSpy1 = spy(new ArrayTransportBuffer()); TransportBuffer tbSpy2 = spy(new ArrayTransportBuffer()); doCallRealMethod().doCallRealMethod().when(tbSpy1).add(any()); doThrow(new IllegalStateException("expected")).when(tbSpy2).add(any()); IpcSenderService spyIpc = spy(handler.getIpcService()); TransportFactory tfSpy = spy(spyIpc.getTransportFactory()); when(tfSpy.newTransportBuffer()).thenReturn(tbSpy1, tbSpy2); spyIpc.setTransportFactory(tfSpy); handler.setIpcService(spyIpc); handler.handler(events, context); assertEquals(1, spyIpc.getSuccessCountStat().getValue()); }