public <T> ListGauge<T> newListGauge(String name) { return registry.newListGauge(groupName, new ListGauge(name)); }
@Override public void run() { for (int i = 1; i <= 100; i++) { listGauge.add(i); } } });
/** * Add a value to the list. * (Timestamp assigned to this value is the current timestamp.) * @param value The Gauge value to be added */ public void add(T value) { this.elements.add(new TimestampedValue<T>(value, Instant.now().toEpochMilli())); // perform any evictions that may be needed. this.evict(); }
/** * Evicts entries from the elements list, based on the given item-size and durationThreshold. * Concurrent eviction threads can cause incorrectness (when reading elements.size or elements.peek). */ private synchronized void evict() { this.evictBasedOnSize(); this.evictBasedOnTimestamp(); }
1); ListGauge listGauge = new ListGauge<DiagnosticsExceptionEvent>("exceptions"); DiagnosticsExceptionEvent diagnosticsExceptionEvent1 = new DiagnosticsExceptionEvent(1, new SamzaException("this is a samza exception", new RuntimeException("cause")), new HashMap()); listGauge.add(diagnosticsExceptionEvent1); metricMessage.get(samzaContainerMetricsGroupName).put("exceptions", listGauge.getValues()); metricMessage.get(samzaContainerMetricsGroupName).put("commit-calls", 0);
@Test public void basicTest() { ListGauge<String> listGauge = getListGaugeForTest(); listGauge.add("sampleValue"); Assert.assertEquals("Names should be the same", listGauge.getName(), "sampleListGauge"); Assert.assertEquals("List sizes should match", listGauge.getValues().size(), 1); Assert.assertEquals("ListGauge should contain sampleGauge", listGauge.getValues().contains("sampleValue"), true); }
@Test public void testSizeEnforcement() { ListGauge listGauge = getListGaugeForTest(); for (int i = 15; i > 0; i--) { listGauge.add("v" + i); } Assert.assertEquals("List sizes should be as configured at creation time", listGauge.getValues().size(), 10); int valueIndex = 10; Collection<String> currentList = listGauge.getValues(); Iterator iterator = currentList.iterator(); while (iterator.hasNext()) { String gaugeValue = (String) iterator.next(); Assert.assertTrue(gaugeValue.equals("v" + valueIndex)); valueIndex--; } }
/** * Evicts entries from the elements list, based on the given item-size and durationThreshold. * Concurrent eviction threads can cause incorrectness (when reading elements.size or elements.peek). */ private synchronized void evict() { this.evictBasedOnSize(); this.evictBasedOnTimestamp(); }
public <T> ListGauge<T> newListGauge(String name) { return registry.newListGauge(groupName, new ListGauge(name)); }
@Override public void run() { for (int i = 1; i <= 100; i++) { listGauge.add(i); } } });
/** * Add a value to the list. * (Timestamp assigned to this value is the current timestamp.) * @param value The Gauge value to be added */ public void add(T value) { this.elements.add(new TimestampedValue<T>(value, Instant.now().toEpochMilli())); // perform any evictions that may be needed. this.evict(); }
public <T> ListGauge<T> newListGauge(String name) { return registry.newListGauge(groupName, new ListGauge(name)); }
@Override protected void append(LoggingEvent loggingEvent) { try { // if an event with a non-null throwable is received => exception event if (loggingEvent.getThrowableInformation() != null) { DiagnosticsExceptionEvent diagnosticsExceptionEvent = new DiagnosticsExceptionEvent(loggingEvent.timeStamp, loggingEvent.getThrowableInformation().getThrowable(), loggingEvent.getProperties()); samzaContainerExceptionMetric.add(diagnosticsExceptionEvent); LOG.debug("Received DiagnosticsExceptionEvent " + diagnosticsExceptionEvent); } else { LOG.debug("Received non-exception event with message " + loggingEvent.getMessage()); } } catch (Exception e) { // blanket catch of all exceptions so as to not impact any job LOG.error("Exception in logging event parsing", e); } }
/** * Get the Collection of values currently in the list. * @return the collection of values */ public Collection<T> getValues() { this.evict(); return Collections.unmodifiableList(this.elements.stream().map(x -> x.getValue()).collect(Collectors.toList())); }
public <T> ListGauge<T> newListGauge(String name) { return registry.newListGauge(groupName, new ListGauge(name)); }
@Override public void append(LogEvent logEvent) { try { // if an event with a non-null throwable is received => exception event if (logEvent.getThrown() != null) { DiagnosticsExceptionEvent diagnosticsExceptionEvent = new DiagnosticsExceptionEvent(logEvent.getTimeMillis(), logEvent.getThrown(), logEvent.getContextData().toMap()); samzaContainerExceptionMetric.add(diagnosticsExceptionEvent); LOG.debug("Received DiagnosticsExceptionEvent " + diagnosticsExceptionEvent); } else { LOG.debug("Received non-exception event with message " + logEvent.getMessage()); } } catch (Exception e) { // blanket catch of all exceptions so as to not impact any job LOG.error("Exception in logevent parsing", e); } } }
/** * Get the Collection of values currently in the list. * @return the collection of values */ public Collection<T> getValues() { this.evict(); return Collections.unmodifiableList(this.elements.stream().map(x -> x.getValue()).collect(Collectors.toList())); }
public <T> ListGauge<T> newListGauge(String name) { return registry.newListGauge(groupName, new ListGauge(name)); }
private <T> ListGauge<T> getListGaugeForTest() { return new ListGauge<T>("sampleListGauge", 10, Duration.ofSeconds(60)); }