public static void incCounter(Counter counter) { if (counter != null) { counter.inc(); } }
@Override public Counter newCounter(String group, String name) { return new Counter(name); }
public long dec() { return dec(1); }
@Test public void testMetrics() { ReadableMetricsRegistry registry = new MetricsRegistryMap(); ElasticsearchSystemProducerMetrics metrics = new ElasticsearchSystemProducerMetrics("es", registry); metrics.bulkSendSuccess.inc(29L); metrics.inserts.inc(); metrics.updates.inc(7L); metrics.conflicts.inc(3L); Set<String> groups = registry.getGroups(); assertEquals(1, groups.size()); assertEquals(GRP_NAME, groups.toArray()[0]); Map<String, Metric> metricMap = registry.getGroup(GRP_NAME); assertEquals(4, metricMap.size()); assertEquals(29L, ((Counter) metricMap.get("es-bulk-send-success")).getCount()); assertEquals(1L, ((Counter) metricMap.get("es-docs-inserted")).getCount()); assertEquals(7L, ((Counter) metricMap.get("es-docs-updated")).getCount()); assertEquals(3L, ((Counter) metricMap.get("es-version-conflicts")).getCount()); }
@Test public void shouldDeleteLocalTaskStoreWhenItHasNoOffsetFile() throws Exception { localStoreMonitor.monitor(); assertTrue("Task store directory should not exist.", !taskStoreDir.exists()); assertEquals(taskStoreSize, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); assertEquals(1, localStoreMonitorMetrics.noOfDeletedTaskPartitionStores.getCount()); }
@Test public void shouldDeleteInActiveLocalStoresOfTheJob() throws Exception { File inActiveStoreDir = new File(jobDir, "inActiveStore"); FileUtils.forceMkdir(inActiveStoreDir); File inActiveTaskDir = new File(inActiveStoreDir, "test-task"); FileUtils.forceMkdir(inActiveTaskDir); long inActiveTaskDirSize = inActiveTaskDir.getTotalSpace(); localStoreMonitor.monitor(); assertTrue("Inactive task store directory should not exist.", !inActiveTaskDir.exists()); assertEquals(taskStoreSize + inActiveTaskDirSize, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); assertEquals(2, localStoreMonitorMetrics.noOfDeletedTaskPartitionStores.getCount()); FileUtils.deleteDirectory(inActiveStoreDir); }
public void incPoll() { this.pollCount.inc(); } }
@Test public void shouldDeleteTaskStoreWhenTaskPreferredStoreIsNotLocalHost() throws Exception { Task task = new Task("notLocalHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store")); Mockito.when(jobsClientMock.getTasks(Mockito.any())).thenReturn(ImmutableList.of(task)); localStoreMonitor.monitor(); assertTrue("Task store directory should not exist.", !taskStoreDir.exists()); assertEquals(taskStoreSize, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); assertEquals(1, localStoreMonitorMetrics.noOfDeletedTaskPartitionStores.getCount()); }
@Override public Counter newCounter(String group, String name) { return new Counter(name); }
public long dec() { return dec(1); }
public long inc() { return inc(1); }
@Test public void shouldDeleteLocalStoreWhenLastModifiedTimeOfOffsetFileIsGreaterThanOffsetTTL() throws Exception { File offsetFile = createOffsetFile(taskStoreDir); offsetFile.setLastModified(0); localStoreMonitor.monitor(); assertTrue("Offset file should not exist.", !offsetFile.exists()); assertEquals(0, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); }
@Override public Counter newCounter(String group, String name) { if (!counters.containsKey(group)) { counters.put(group, new ArrayList<>()); } Counter c = new Counter(name); counters.get(group).add(c); return c; }
public void incTotalNumEvents() { numTotalEventsCounter.inc(); }
@Test public void shouldDoNothingWhenTheJobIsRunning() throws Exception { Mockito.when(jobsClientMock.getJobStatus(Mockito.any())).thenReturn(JobStatus.STARTED); File offsetFile = createOffsetFile(taskStoreDir); localStoreMonitor.monitor(); assertTrue("Offset file should exist.", offsetFile.exists()); assertEquals(0, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); }
@Override public Counter newCounter(String group, String name) { Counter counter = new Counter(name); return newCounter(group, counter); }
public void incBlockingPoll(SystemStreamPartition systemStreamPartition) { this.blockingPollCountMap.get(systemStreamPartition).inc(); }
@Test public void shouldDoNothingWhenLastModifiedTimeOfOffsetFileIsLessThanOffsetTTL() throws Exception { File offsetFile = createOffsetFile(taskStoreDir); localStoreMonitor.monitor(); assertTrue("Offset file should exist.", offsetFile.exists()); assertEquals(0, localStoreMonitorMetrics.diskSpaceFreedInBytes.getCount()); }
public static Context getMockContext() { Context context = new MockContext(); MetricsRegistry metricsRegistry = mock(MetricsRegistry.class); doAnswer(args -> new Timer((String) args.getArguments()[0])).when(metricsRegistry).newTimer(anyString(), anyString()); doAnswer(args -> new Counter((String) args.getArguments()[0])).when(metricsRegistry).newCounter(anyString(), anyString()); doAnswer(args -> new Gauge((String) args.getArguments()[0], 0)).when(metricsRegistry).newGauge(anyString(), any()); doReturn(metricsRegistry).when(context.getContainerContext()).getContainerMetricsRegistry(); return context; }
/** * Updates the Diagnostics Metrics (processing time and number of events) * @param arrivalTime input message arrival time (= beging of processing in this operator) * @param outputTime output message output time (=end of processing in this operator) * @param isNewInputMessage whether the input Message is from new input message or not */ private void updateMetrics(Instant arrivalTime, Instant outputTime, boolean isNewInputMessage) { if (isNewInputMessage) { inputEvents.inc(); } outputEvents.inc(); processingTime.update(Duration.between(arrivalTime, outputTime).toMillis()); }