use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class ContainerHeartbeatMonitor method initializeMetrics.
private void initializeMetrics(Config config) {
reporters = MetricsReporterLoader.getMetricsReporters(new MetricsConfig(config), SOURCE_NAME);
MetricsRegistryMap registryMap = new MetricsRegistryMap();
metrics = new ContainerHeartbeatMetrics(registryMap);
reporters.values().forEach(reporter -> reporter.register(SOURCE_NAME, registryMap));
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class SSPGrouperProxy method getSystemStreamPartitionMapper.
/**
* Creates a instance of {@link SystemStreamPartitionMapper} using the stream partition expansion factory class
* defined in the {@param config}.
* @param config the configuration of the samza job.
* @return the instantiated {@link SystemStreamPartitionMapper} object.
*/
private SystemStreamPartitionMapper getSystemStreamPartitionMapper(Config config) {
JobConfig jobConfig = new JobConfig(config);
String systemStreamPartitionMapperClass = jobConfig.getSystemStreamPartitionMapperFactoryName();
SystemStreamPartitionMapperFactory systemStreamPartitionMapperFactory = ReflectionUtil.getObj(systemStreamPartitionMapperClass, SystemStreamPartitionMapperFactory.class);
return systemStreamPartitionMapperFactory.getStreamPartitionMapper(config, new MetricsRegistryMap());
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class SamzaTaskProxy method readTasksFromCoordinatorStream.
/**
* Builds list of {@link Task} from job model in coordinator stream.
* @param consumer system consumer associated with a job's coordinator stream.
* @return list of {@link Task} constructed from job model in coordinator stream.
*/
protected List<Task> readTasksFromCoordinatorStream(CoordinatorStreamSystemConsumer consumer) {
CoordinatorStreamStore coordinatorStreamStore = new CoordinatorStreamStore(consumer.getConfig(), new MetricsRegistryMap());
LocalityManager localityManager = new LocalityManager(coordinatorStreamStore);
Map<String, ProcessorLocality> containerLocalities = localityManager.readLocality().getProcessorLocalities();
TaskAssignmentManager taskAssignmentManager = new TaskAssignmentManager(new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetTaskContainerMapping.TYPE), new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetTaskModeMapping.TYPE));
Map<String, String> taskNameToContainerIdMapping = taskAssignmentManager.readTaskAssignment();
StorageConfig storageConfig = new StorageConfig(consumer.getConfig());
List<String> storeNames = storageConfig.getStoreNames();
return taskNameToContainerIdMapping.entrySet().stream().map(entry -> {
String hostName = Optional.ofNullable(containerLocalities.get(entry.getValue())).map(ProcessorLocality::host).orElse(null);
return new Task(hostName, entry.getKey(), entry.getValue(), new ArrayList<>(), storeNames);
}).collect(Collectors.toList());
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestApplicationMasterRestClient method testGetMetricsSuccess.
@Test
public void testGetMetricsSuccess() throws IOException {
SamzaApplicationState samzaAppState = createSamzaApplicationState();
MetricsRegistryMap registry = new MetricsRegistryMap();
assignMetricValues(samzaAppState, registry);
String response = ApplicationMasterRestServlet.getMetrics(jsonMapper, registry);
setupMockClientResponse(HttpStatus.SC_OK, "Success", response);
ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT);
Map<String, Map<String, Object>> metricsResult = client.getMetrics();
String group = SamzaAppMasterMetrics.class.getCanonicalName();
assertEquals(1, metricsResult.size());
assertTrue(metricsResult.containsKey(group));
Map<String, Object> amMetricsGroup = metricsResult.get(group);
assertEquals(8, amMetricsGroup.size());
assertEquals(samzaAppState.runningProcessors.size(), amMetricsGroup.get("running-containers"));
assertEquals(samzaAppState.neededProcessors.get(), amMetricsGroup.get("needed-containers"));
assertEquals(samzaAppState.completedProcessors.get(), amMetricsGroup.get("completed-containers"));
assertEquals(samzaAppState.failedContainers.get(), amMetricsGroup.get("failed-containers"));
assertEquals(samzaAppState.releasedContainers.get(), amMetricsGroup.get("released-containers"));
assertEquals(samzaAppState.processorCount.get(), amMetricsGroup.get("container-count"));
assertEquals(samzaAppState.jobHealthy.get() ? 1 : 0, amMetricsGroup.get("job-healthy"));
assertEquals(0, amMetricsGroup.get("container-from-previous-attempt"));
}
Aggregations