use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class TestCachingTable method initTables.
private void initTables(boolean isTimerMetricsDisabled, ReadWriteUpdateTable... tables) {
Map<String, String> config = new HashMap<>();
if (isTimerMetricsDisabled) {
config.put(MetricsConfig.METRICS_TIMER_ENABLED, "false");
}
Context context = new MockContext();
doReturn(new MapConfig(config)).when(context.getJobContext()).getConfig();
metricsRegistry = mock(MetricsRegistry.class);
doReturn(mock(Timer.class)).when(metricsRegistry).newTimer(anyString(), anyString());
doReturn(mock(Counter.class)).when(metricsRegistry).newCounter(anyString(), anyString());
doReturn(mock(Gauge.class)).when(metricsRegistry).newGauge(anyString(), any());
doReturn(metricsRegistry).when(context.getContainerContext()).getContainerMetricsRegistry();
Arrays.asList(tables).forEach(t -> t.init(context));
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class MockSystemFactory method getProducer.
public SystemProducer getProducer(String systemName, Config config, MetricsRegistry registry) {
return new SystemProducer() {
private final Random seed = new Random(System.currentTimeMillis());
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public void register(String source) {
}
@Override
public void send(String source, OutgoingMessageEnvelope envelope) {
SystemStream systemStream = envelope.getSystemStream();
List<SystemStreamPartition> sspForSystem = MSG_QUEUES.keySet().stream().filter(ssp -> ssp.getSystemStream().equals(systemStream)).collect(ArrayList::new, (l, ssp) -> l.add(ssp), (l1, l2) -> l1.addAll(l2));
if (sspForSystem.isEmpty()) {
MSG_QUEUES.putIfAbsent(new SystemStreamPartition(systemStream, new Partition(0)), new ArrayList<>());
sspForSystem.add(new SystemStreamPartition(systemStream, new Partition(0)));
}
int partitionCount = sspForSystem.size();
int partitionId = envelope.getPartitionKey() == null ? envelope.getKey() == null ? this.seed.nextInt(partitionCount) : envelope.getKey().hashCode() % partitionCount : envelope.getPartitionKey().hashCode() % partitionCount;
SystemStreamPartition ssp = new SystemStreamPartition(envelope.getSystemStream(), new Partition(partitionId));
List<IncomingMessageEnvelope> msgQueue = MSG_QUEUES.get(ssp);
msgQueue.add(new IncomingMessageEnvelope(ssp, null, envelope.getKey(), envelope.getMessage()));
}
@Override
public void flush(String source) {
}
};
}
use of org.apache.samza.metrics.MetricsRegistry in project samza by apache.
the class OperatorImpl method init.
/**
* Initialize this {@link OperatorImpl} and its user-defined functions.
*
* @param internalTaskContext the {@link InternalTaskContext} for the task
*/
public final void init(InternalTaskContext internalTaskContext) {
final Context context = internalTaskContext.getContext();
String opId = getOpImplId();
if (initialized) {
throw new IllegalStateException(String.format("Attempted to initialize Operator %s more than once.", opId));
}
if (closed) {
throw new IllegalStateException(String.format("Attempted to initialize Operator %s after it was closed.", opId));
}
this.highResClock = createHighResClock(context.getJobContext().getConfig());
registeredOperators = new LinkedHashSet<>();
prevOperators = new LinkedHashSet<>();
inputStreams = new LinkedHashSet<>();
final ContainerContext containerContext = context.getContainerContext();
final MetricsRegistry metricsRegistry = containerContext.getContainerMetricsRegistry();
this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages");
this.handleMessageNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-message-ns");
this.handleTimerNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-timer-ns");
final TaskContext taskContext = context.getTaskContext();
this.taskName = taskContext.getTaskModel().getTaskName();
this.eosStates = (EndOfStreamStates) internalTaskContext.fetchObject(EndOfStreamStates.class.getName());
this.watermarkStates = (WatermarkStates) internalTaskContext.fetchObject(WatermarkStates.class.getName());
this.controlMessageSender = new ControlMessageSender(internalTaskContext.getStreamMetadataCache());
this.taskModel = taskContext.getTaskModel();
this.callbackScheduler = taskContext.getCallbackScheduler();
handleInit(context);
this.elasticityFactor = new JobConfig(context.getJobContext().getConfig()).getElasticityFactor();
initialized = true;
}
Aggregations