use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class TestRemoteTable method getMockContext.
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;
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class TestLocalTableRead method setUp.
@Before
public void setUp() {
keys = Arrays.asList("k1", "k2", "k3");
values = new HashMap<>();
values.put("k1", "v1");
values.put("k2", "v2");
values.put("k3", null);
kvStore = mock(KeyValueStore.class);
when(kvStore.get("k1")).thenReturn("v1");
when(kvStore.get("k2")).thenReturn("v2");
when(kvStore.getAll(keys)).thenReturn(values);
getNs = new Timer("");
getAllNs = new Timer("");
numGets = new Counter("");
numGetAlls = new Counter("");
getCallbackNs = new Timer("");
numMissedLookups = new Counter("");
metricsRegistry = mock(MetricsRegistry.class);
String groupName = LocalTable.class.getSimpleName();
when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-gets")).thenReturn(numGets);
when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-getAlls")).thenReturn(numGetAlls);
when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-missed-lookups")).thenReturn(numMissedLookups);
when(metricsRegistry.newTimer(groupName, TABLE_ID + "-get-ns")).thenReturn(getNs);
when(metricsRegistry.newTimer(groupName, TABLE_ID + "-getAll-ns")).thenReturn(getAllNs);
when(metricsRegistry.newTimer(groupName, TABLE_ID + "-get-callback-ns")).thenReturn(getCallbackNs);
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class StreamAppender method setupSystem.
/**
* This should only be called after verifying that the {@link LoggingContextHolder} has the config.
*/
protected void setupSystem() {
config = getConfig();
Log4jSystemConfig log4jSystemConfig = new Log4jSystemConfig(config);
if (streamName == null) {
streamName = getStreamName(log4jSystemConfig.getJobName(), log4jSystemConfig.getJobId());
}
// TODO we need the ACTUAL metrics registry, or the metrics won't get reported by the metric reporters!
MetricsRegistry metricsRegistry = new MetricsRegistryMap();
metrics = new StreamAppenderMetrics("stream-appender", metricsRegistry);
String systemName = log4jSystemConfig.getSystemName();
String systemFactoryName = log4jSystemConfig.getSystemFactory(systemName).orElseThrow(() -> new SamzaException("Could not figure out \"" + systemName + "\" system factory for log4j StreamAppender to use"));
SystemFactory systemFactory = ReflectionUtil.getObj(systemFactoryName, SystemFactory.class);
setSerde(log4jSystemConfig, systemName, streamName);
if (config.getBoolean(CREATE_STREAM_ENABLED, false)) {
int streamPartitionCount = getPartitionCount();
System.out.println("[StreamAppender] creating stream " + streamName + " with partition count " + streamPartitionCount);
StreamSpec streamSpec = StreamSpec.createStreamAppenderStreamSpec(streamName, systemName, streamPartitionCount);
// SystemAdmin only needed for stream creation here.
SystemAdmin systemAdmin = systemFactory.getAdmin(systemName, config);
systemAdmin.start();
systemAdmin.createStream(streamSpec);
systemAdmin.stop();
}
systemProducer = systemFactory.getProducer(systemName, config, metricsRegistry, this.getClass().getSimpleName());
systemStream = new SystemStream(systemName, streamName);
systemProducer.register(SOURCE);
systemProducer.start();
log.info(SOURCE + " has been registered in " + systemName + ". So all the logs will be sent to " + streamName + " in " + systemName + ". Logs are partitioned by " + key);
startTransferThread();
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class TestMonitorService method testShouldNotFailWhenTheMonitorFactoryClassIsNotDefined.
@Test
public void testShouldNotFailWhenTheMonitorFactoryClassIsNotDefined() throws Exception {
// Test that when MonitorFactoryClass is not defined in the config, monitor service
// should not fail.
Map<String, String> configMap = ImmutableMap.of("monitor.monitor1.config.key1", "configValue1", "monitor.monitor1.config.key2", "configValue2", String.format("monitor.MOCK_MONITOR.%s", CONFIG_MONITOR_FACTORY_CLASS), MockMonitorFactory.class.getCanonicalName());
SamzaRestConfig config = new SamzaRestConfig(new MapConfig(configMap));
class SamzaMonitorServiceTest extends SamzaMonitorService {
MetricsRegistry metricsRegistry;
public SamzaMonitorServiceTest(SamzaRestConfig config, MetricsRegistry metricsRegistry) {
super(config, metricsRegistry);
this.metricsRegistry = metricsRegistry;
}
@Override
public void createSchedulerAndScheduleMonitor(String monitorName, MonitorConfig monitorConfig, long schedulingIntervalInMs) {
try {
// immediately run monitor, without scheduling
instantiateMonitor(monitorName, monitorConfig, metricsRegistry).monitor();
} catch (Exception e) {
fail();
}
}
}
SamzaMonitorService monitorService = new SamzaMonitorServiceTest(config, METRICS_REGISTRY);
try {
monitorService.start();
} catch (Exception e) {
fail();
}
Mockito.verify(MockMonitorFactory.MOCK_MONITOR, Mockito.times(1)).monitor();
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class TestInputRegexMonitor method setUp.
@Before
public void setUp() {
inputStreamsDiscovered = new HashSet<>();
Map<String, Pattern> patternMap = new HashMap<>();
patternMap.put(systemName, Pattern.compile("test-.*"));
StreamMetadataCache mockStreamMetadataCache = new MockStreamMetadataCache(null, 1, null);
MetricsRegistry metrics = Mockito.mock(MetricsRegistry.class);
this.callbackCount = new CountDownLatch(expectedNumberOfCallbacks);
// Creating an streamRegexMonitor with empty-input set and test-.* regex input
this.streamRegexMonitor = new StreamRegexMonitor(new HashSet<>(), patternMap, mockStreamMetadataCache, metrics, inputRegexMs, new StreamRegexMonitor.Callback() {
@Override
public void onInputStreamsChanged(Set<SystemStream> initialInputSet, Set<SystemStream> newInputStreams, Map<String, Pattern> regexesMonitored) {
callbackCount.countDown();
inputStreamsDiscovered.addAll(newInputStreams);
// Check that the newInputStream discovered is "kafka" "Test-1"
Assert.assertTrue(inputStreamsDiscovered.size() == 1);
Assert.assertTrue(inputStreamsDiscovered.contains(sampleStream));
}
});
}
Aggregations