use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImplGraph method setup.
@Before
public void setup() {
this.context = new MockContext();
// individual tests can override this config if necessary
when(this.context.getJobContext().getConfig()).thenReturn(mock(Config.class));
TaskModel taskModel = mock(TaskModel.class);
when(taskModel.getTaskName()).thenReturn(new TaskName("task 0"));
when(this.context.getTaskContext().getTaskModel()).thenReturn(taskModel);
when(this.context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap());
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestOperatorImpl method setup.
@Before
public void setup() {
this.context = new MockContext();
this.internalTaskContext = mock(InternalTaskContext.class);
when(this.internalTaskContext.getContext()).thenReturn(this.context);
// might be necessary in the future
when(this.internalTaskContext.fetchObject(EndOfStreamStates.class.getName())).thenReturn(mock(EndOfStreamStates.class));
when(this.internalTaskContext.fetchObject(WatermarkStates.class.getName())).thenReturn(mock(WatermarkStates.class));
when(this.context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap());
when(this.context.getTaskContext().getTaskModel()).thenReturn(mock(TaskModel.class));
when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap());
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestWatermarkStates method testUpdate.
@Test
public void testUpdate() {
SystemStream input = new SystemStream("system", "input");
SystemStream intermediate = new SystemStream("system", "intermediate");
Set<SystemStreamPartition> ssps = new HashSet<>();
SystemStreamPartition inputPartition0 = new SystemStreamPartition(input, new Partition(0));
SystemStreamPartition intPartition0 = new SystemStreamPartition(intermediate, new Partition(0));
SystemStreamPartition intPartition1 = new SystemStreamPartition(intermediate, new Partition(1));
ssps.add(inputPartition0);
ssps.add(intPartition0);
ssps.add(intPartition1);
Map<SystemStream, Integer> producerCounts = new HashMap<>();
producerCounts.put(intermediate, 2);
// advance watermark on input to 5
WatermarkStates watermarkStates = new WatermarkStates(ssps, producerCounts, new MetricsRegistryMap());
IncomingMessageEnvelope envelope = IncomingMessageEnvelope.buildWatermarkEnvelope(inputPartition0, 5L);
watermarkStates.update((WatermarkMessage) envelope.getMessage(), envelope.getSystemStreamPartition());
assertEquals(watermarkStates.getWatermark(input), 5L);
assertEquals(watermarkStates.getWatermark(intermediate), WATERMARK_NOT_EXIST);
// watermark from task 0 on int p0 to 6
WatermarkMessage watermarkMessage = new WatermarkMessage(6L, "task 0");
watermarkStates.update(watermarkMessage, intPartition0);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition0), WATERMARK_NOT_EXIST);
assertEquals(watermarkStates.getWatermark(intermediate), WATERMARK_NOT_EXIST);
// watermark from task 1 on int p0 to 3
watermarkMessage = new WatermarkMessage(3L, "task 1");
watermarkStates.update(watermarkMessage, intPartition0);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition0), 3L);
assertEquals(watermarkStates.getWatermark(intermediate), WATERMARK_NOT_EXIST);
// watermark from task 0 on int p1 to 10
watermarkMessage = new WatermarkMessage(10L, "task 0");
watermarkStates.update(watermarkMessage, intPartition1);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition1), WATERMARK_NOT_EXIST);
assertEquals(watermarkStates.getWatermark(intermediate), WATERMARK_NOT_EXIST);
// watermark from task 1 on int p1 to 4
watermarkMessage = new WatermarkMessage(4L, "task 1");
watermarkStates.update(watermarkMessage, intPartition1);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition1), 4L);
// verify we got a watermark 3 (min) for int stream
assertEquals(watermarkStates.getWatermark(intermediate), 3L);
// advance watermark from task 1 on int p0 to 8
watermarkMessage = new WatermarkMessage(8L, "task 1");
watermarkStates.update(watermarkMessage, intPartition0);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition0), 6L);
// verify we got a watermark 4 (min) for int stream
assertEquals(watermarkStates.getWatermark(intermediate), 4L);
// advance watermark from task 1 on int p1 to 7
watermarkMessage = new WatermarkMessage(7L, "task 1");
watermarkStates.update(watermarkMessage, intPartition1);
assertEquals(watermarkStates.getWatermarkPerSSP(intPartition1), 7L);
// verify we got a watermark 6 (min) for int stream
assertEquals(watermarkStates.getWatermark(intermediate), 6L);
}
use of org.apache.samza.metrics.MetricsRegistryMap 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.MetricsRegistryMap 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 = getLog4jSystemConfig(config);
if (streamName == null) {
streamName = getStreamName(log4jSystemConfig.getJobName(), log4jSystemConfig.getJobId());
}
// Instantiate metrics
MetricsRegistryMap metricsRegistry = new MetricsRegistryMap();
// Take this.getClass().getName() as the name to make it extend-friendly
metrics = getMetrics(metricsRegistry);
// Register metrics into metrics reporters so that they are able to be reported to other systems
Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(new MetricsConfig(config), containerName);
metricsReporters.values().forEach(reporter -> {
reporter.register(containerName, metricsRegistry);
reporter.start();
});
String systemName = log4jSystemConfig.getSystemName();
String systemFactoryName = log4jSystemConfig.getSystemFactory(systemName).orElseThrow(() -> new SamzaException("Could not figure out \"" + systemName + "\" system factory for log4j " + getName() + " to use"));
SystemFactory systemFactory = ReflectionUtil.getObj(systemFactoryName, SystemFactory.class);
setSerde(log4jSystemConfig, systemName);
setupStream(systemFactory, systemName);
systemProducer = systemFactory.getProducer(systemName, config, metricsRegistry, this.getClass().getSimpleName());
systemStream = new SystemStream(systemName, streamName);
systemProducer.register(SOURCE);
systemProducer.start();
System.out.println(SOURCE + " has been registered in " + systemName + ". So all the logs will be sent to " + streamName + " in " + systemName + ". Logs are partitioned by " + key);
startTransferThread();
}
Aggregations