@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()); }
@Override public void init(Context context) { TranslatorContext translatorContext = ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId); this.msgConverter = translatorContext.getMsgConverter(streamName); ContainerContext containerContext = context.getContainerContext(); metricsRegistry = containerContext.getContainerMetricsRegistry(); processingTime = new SamzaHistogram(metricsRegistry, logicalOpId, TranslatorConstants.PROCESSING_TIME_NAME); queryInputEvents = metricsRegistry.newCounter(queryLogicalId, TranslatorConstants.INPUT_EVENTS_NAME); queryInputEvents.clear(); }
@Override public ReadWriteTable getTable() { Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId)); JavaTableConfig tableConfig = new JavaTableConfig(context.getJobContext().getConfig()); String realTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.REAL_TABLE_ID); ReadWriteTable table = this.context.getTaskContext().getTable(realTableId); String cacheTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.CACHE_TABLE_ID); ReadWriteTable cache; if (cacheTableId != null) { cache = this.context.getTaskContext().getTable(cacheTableId); } else { cache = createDefaultCacheTable(realTableId, tableConfig); defaultCaches.add(cache); } boolean isWriteAround = Boolean.parseBoolean(tableConfig.getForTable(tableId, CachingTableDescriptor.WRITE_AROUND)); CachingTable cachingTable = new CachingTable(tableId, table, cache, isWriteAround); cachingTable.init(this.context); return cachingTable; }
/** * Constructor based on container context * * @param context {@link Context} for this task * @param table underlying table * @param tableId table Id */ public TableMetricsUtil(Context context, Table table, String tableId) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(table); Preconditions.checkNotNull(tableId); this.metricsRegistry = context.getTaskContext().getTaskMetricsRegistry(); this.groupName = table.getClass().getSimpleName(); this.tableId = tableId; }
private void initTables(boolean isTimerMetricsDisabled, ReadWriteTable ... 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)); }
@Override public void init(Context context) { MetricsConfig metricsConfig = new MetricsConfig(context.getJobContext().getConfig()); clock = metricsConfig.getMetricsTimerEnabled() ? () -> System.nanoTime() : () -> 0L; metrics = new TableMetrics(context, this, tableId); }
@Before public void setup() { this.context = new MockContext(); 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()); }
/** * Constructor based on container context * * @param context {@link Context} for this task * @param table underlying table * @param tableId table Id */ public TableMetricsUtil(Context context, Table table, String tableId) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(table); Preconditions.checkNotNull(tableId); this.metricsRegistry = context.getContainerContext().getContainerMetricsRegistry(); this.groupName = table.getClass().getSimpleName(); this.tableId = tableId; }
@Override public void init(Context context) { TranslatorContext translatorContext = ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId); this.samzaMsgConverter = translatorContext.getMsgConverter(outputTopic); }
/** * Constructor based on container context * * @param context {@link Context} for this task * @param table underlying table * @param tableId table Id */ public TableMetricsUtil(Context context, Table table, String tableId) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(table); Preconditions.checkNotNull(tableId); this.metricsRegistry = context.getTaskContext().getTaskMetricsRegistry(); this.groupName = table.getClass().getSimpleName(); this.tableId = tableId; }
this.highResClock = createHighResClock(context.getJobContext().getConfig()); registeredOperators = new HashSet<>(); prevOperators = new HashSet<>(); inputStreams = new HashSet<>(); TaskContextImpl taskContext = (TaskContextImpl) context.getTaskContext(); MetricsRegistry metricsRegistry = taskContext.getTaskMetricsRegistry(); this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages");
private LocalTable createTable(boolean isTimerDisabled) { Map<String, String> config = new HashMap<>(); if (isTimerDisabled) { config.put(MetricsConfig.METRICS_TIMER_ENABLED(), "false"); } Context context = mock(Context.class); JobContext jobContext = mock(JobContext.class); when(context.getJobContext()).thenReturn(jobContext); when(jobContext.getConfig()).thenReturn(new MapConfig(config)); ContainerContext containerContext = mock(ContainerContext.class); when(context.getContainerContext()).thenReturn(containerContext); when(containerContext.getContainerMetricsRegistry()).thenReturn(metricsRegistry); LocalTable table = new LocalTable("t1", kvStore); table.init(context); return table; } }
@Override public ReadWriteTable getTable() { Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId)); JavaTableConfig tableConfig = new JavaTableConfig(context.getJobContext().getConfig()); Cache guavaCache = SerdeUtils.deserialize(GuavaCacheTableDescriptor.GUAVA_CACHE, tableConfig.getForTable(tableId, GuavaCacheTableDescriptor.GUAVA_CACHE)); GuavaCacheTable table = new GuavaCacheTable(tableId, guavaCache); table.init(this.context); guavaTables.add(table); return table; }
private StreamOperatorTask createStreamOperatorTask(Clock clock, StreamApplicationDescriptorImpl graphSpec) throws Exception { Map<String, String> mapConfig = new HashMap<>(); mapConfig.put("job.name", "jobName"); mapConfig.put("job.id", "jobId"); StreamTestUtils.addStreamConfigs(mapConfig, "inStream", "insystem", "instream"); StreamTestUtils.addStreamConfigs(mapConfig, "inStream2", "insystem", "instream2"); Context context = new MockContext(new MapConfig(mapConfig)); TaskModel taskModel = mock(TaskModel.class); when(taskModel.getSystemStreamPartitions()).thenReturn(ImmutableSet .of(new SystemStreamPartition("insystem", "instream", new Partition(0)), new SystemStreamPartition("insystem", "instream2", new Partition(0)))); when(context.getTaskContext().getTaskModel()).thenReturn(taskModel); when(context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap()); when(context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap()); // need to return different stores for left and right side IntegerSerde integerSerde = new IntegerSerde(); TimestampedValueSerde timestampedValueSerde = new TimestampedValueSerde(new KVSerde(integerSerde, integerSerde)); when(context.getTaskContext().getStore(eq("jobName-jobId-join-j1-L"))) .thenReturn(new TestInMemoryStore(integerSerde, timestampedValueSerde)); when(context.getTaskContext().getStore(eq("jobName-jobId-join-j1-R"))) .thenReturn(new TestInMemoryStore(integerSerde, timestampedValueSerde)); StreamOperatorTask sot = new StreamOperatorTask(graphSpec.getOperatorSpecGraph(), clock); sot.init(context); return sot; }
/** * initializes the TranslatorOutputMetricsMapFunction before any message is processed * @param context the {@link Context} for this task */ @Override public void init(Context context) { ContainerContext containerContext = context.getContainerContext(); metricsRegistry = containerContext.getContainerMetricsRegistry(); inputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.INPUT_EVENTS_NAME); inputEvents.clear(); }
@Override public void init(Context context) { TranslatorContext translatorContext = ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId); this.msgConverter = translatorContext.getMsgConverter(streamName); }
this.highResClock = createHighResClock(context.getJobContext().getConfig()); registeredOperators = new HashSet<>(); prevOperators = new HashSet<>(); inputStreams = new HashSet<>(); final ContainerContext containerContext = context.getContainerContext(); final MetricsRegistry metricsRegistry = containerContext.getContainerMetricsRegistry(); this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages"); final TaskContextImpl taskContext = (TaskContextImpl) context.getTaskContext(); this.taskName = taskContext.getTaskModel().getTaskName(); this.eosStates = (EndOfStreamStates) taskContext.fetchObject(EndOfStreamStates.class.getName());
/** * Constructor based on container context * * @param context {@link Context} for this task * @param table underlying table * @param tableId table Id */ public TableMetricsUtil(Context context, Table table, String tableId) { Preconditions.checkNotNull(context); Preconditions.checkNotNull(table); Preconditions.checkNotNull(tableId); this.metricsRegistry = context.getTaskContext().getTaskMetricsRegistry(); this.groupName = table.getClass().getSimpleName(); this.tableId = tableId; }
this.highResClock = createHighResClock(context.getJobContext().getConfig()); registeredOperators = new HashSet<>(); prevOperators = new HashSet<>(); inputStreams = new HashSet<>(); TaskContextImpl taskContext = (TaskContextImpl) context.getTaskContext(); MetricsRegistry metricsRegistry = taskContext.getTaskMetricsRegistry(); this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages");
@Override public void init(Context context) { TranslatorContext translatorContext = ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId); this.samzaMsgConverter = translatorContext.getMsgConverter(outputTopic); ContainerContext containerContext = context.getContainerContext(); metricsRegistry = containerContext.getContainerMetricsRegistry(); /* insert (SendToOutputStream) metrics */ insertProcessingTime = new SamzaHistogram(metricsRegistry, insertLogicalId, TranslatorConstants.TOTAL_LATENCY_NAME);; /* query metrics */ totalLatency = new SamzaHistogram(metricsRegistry, queryLogicalId, TranslatorConstants.TOTAL_LATENCY_NAME);; queryLatency = new SamzaHistogram(metricsRegistry, queryLogicalId, TranslatorConstants.QUERY_LATENCY_NAME); queueingLatency = new SamzaHistogram(metricsRegistry, queryLogicalId, TranslatorConstants.QUEUEING_LATENCY_NAME);; queryOutputEvents = metricsRegistry.newCounter(queryLogicalId, TranslatorConstants.OUTPUT_EVENTS_NAME); queryOutputEvents.clear(); }