org.apache.samza.metrics.MetricsRegistry Java Examples

The following examples show how to use org.apache.samza.metrics.MetricsRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatermarkStates.java    From samza with Apache License 2.0 6 votes vote down vote up
WatermarkStates(
    Set<SystemStreamPartition> ssps,
    Map<SystemStream, Integer> producerTaskCounts,
    MetricsRegistry metricsRegistry) {
  final Map<SystemStreamPartition, WatermarkState> states = new HashMap<>();
  final List<SystemStreamPartition> intSsps = new ArrayList<>();

  ssps.forEach(ssp -> {
    final int producerCount = producerTaskCounts.getOrDefault(ssp.getSystemStream(), 0);
    states.put(ssp, new WatermarkState(producerCount));
    if (producerCount != 0) {
      intSsps.add(ssp);
    }
  });
  this.watermarkStates = Collections.unmodifiableMap(states);
  this.watermarkMetrics = new WatermarkMetrics(metricsRegistry);
  this.intermediateSsps = Collections.unmodifiableList(intSsps);
}
 
Example #2
Source File: TestDiagnosticsUtil.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildDiagnosticsManagerReturnsConfiguredReporter() {
  Config config = new MapConfig(buildTestConfigs());
  JobModel mockJobModel = mock(JobModel.class);
  SystemFactory systemFactory = mock(SystemFactory.class);
  SystemProducer mockProducer = mock(SystemProducer.class);
  MetricsReporterFactory metricsReporterFactory = mock(MetricsReporterFactory.class);
  MetricsSnapshotReporter mockReporter = mock(MetricsSnapshotReporter.class);

  when(systemFactory.getProducer(anyString(), any(Config.class), any(MetricsRegistry.class))).thenReturn(mockProducer);
  when(metricsReporterFactory.getMetricsReporter(anyString(), anyString(), any(Config.class))).thenReturn(
      mockReporter);
  PowerMockito.mockStatic(ReflectionUtil.class);
  when(ReflectionUtil.getObj(REPORTER_FACTORY, MetricsReporterFactory.class)).thenReturn(metricsReporterFactory);
  when(ReflectionUtil.getObj(SYSTEM_FACTORY, SystemFactory.class)).thenReturn(systemFactory);

  Optional<Pair<DiagnosticsManager, MetricsSnapshotReporter>> managerReporterPair =
      DiagnosticsUtil.buildDiagnosticsManager(JOB_NAME, JOB_ID, mockJobModel, CONTAINER_ID, Optional.of(ENV_ID),
          config);

  Assert.assertTrue(managerReporterPair.isPresent());
  Assert.assertEquals(mockReporter, managerReporterPair.get().getValue());
}
 
Example #3
Source File: ContainerStorageManager.java    From samza with Apache License 2.0 6 votes vote down vote up
/**
 *  Creates SystemConsumer objects for store restoration, creating one consumer per system.
 */
private static Map<String, SystemConsumer> createConsumers(Set<String> storeSystems,
    Map<String, SystemFactory> systemFactories, Config config, MetricsRegistry registry) {
  // Create one consumer for each system in use, map with one entry for each such system
  Map<String, SystemConsumer> consumers = new HashMap<>();

  // Iterate over the list of storeSystems and create one sysConsumer per system
  for (String storeSystemName : storeSystems) {
    SystemFactory systemFactory = systemFactories.get(storeSystemName);
    if (systemFactory == null) {
      throw new SamzaException("System " + storeSystemName + " does not exist in config");
    }
    consumers.put(storeSystemName, systemFactory.getConsumer(storeSystemName, config, registry));
  }

  return consumers;
}
 
Example #4
Source File: TestKafkaCheckpointManagerJava.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadSucceedsOnKeySerdeExceptionsWhenValidationIsDisabled() throws Exception {
  KafkaStreamSpec checkpointSpec = new KafkaStreamSpec(CHECKPOINT_TOPIC, CHECKPOINT_TOPIC,
      CHECKPOINT_SYSTEM, 1);
  Config mockConfig = mock(Config.class);
  when(mockConfig.get(JobConfig.SSP_GROUPER_FACTORY)).thenReturn(GROUPER_FACTORY_CLASS);

  // mock out a consumer that returns a single checkpoint IME
  SystemStreamPartition ssp = new SystemStreamPartition("system-1", "input-topic", new Partition(0));
  List<List<IncomingMessageEnvelope>> checkpointEnvelopes = ImmutableList.of(
      ImmutableList.of(newCheckpointEnvelope(TASK1, ssp, "0")));
  SystemConsumer mockConsumer = newConsumer(checkpointEnvelopes);

  SystemAdmin mockAdmin = newAdmin("0", "1");
  SystemFactory factory = newFactory(mock(SystemProducer.class), mockConsumer, mockAdmin);

  // wire up an exception throwing serde with the checkpointmanager
  KafkaCheckpointManager checkpointManager = new KafkaCheckpointManager(checkpointSpec, factory,
      false, mockConfig, mock(MetricsRegistry.class), new ExceptionThrowingCheckpointSerde(),
      new ExceptionThrowingCheckpointKeySerde());
  checkpointManager.register(TASK1);
  checkpointManager.start();

  // expect the read to succeed inspite of the exception from ExceptionThrowingSerde
  checkpointManager.readLastCheckpoint(TASK1);
}
 
Example #5
Source File: MockSystemFactory.java    From samza with Apache License 2.0 6 votes vote down vote up
public SystemConsumer getConsumer(String systemName, Config config, MetricsRegistry registry) {
  return new SystemConsumer() {
    public void start() {
    }

    public void stop() {
    }

    public void register(SystemStreamPartition systemStreamPartition, String offset) {
      MSG_QUEUES.putIfAbsent(systemStreamPartition, new ArrayList<>());
    }

    public Map<SystemStreamPartition, List<IncomingMessageEnvelope>> poll(Set<SystemStreamPartition> systemStreamPartitions, long timeout) {
      Map<SystemStreamPartition, List<IncomingMessageEnvelope>> retQueues = new HashMap<>();
      systemStreamPartitions.forEach(ssp -> {
        List<IncomingMessageEnvelope> msgs = MSG_QUEUES.get(ssp);
        if (msgs == null) {
          retQueues.put(ssp, new ArrayList<>());
        } else {
          retQueues.put(ssp, MSG_QUEUES.remove(ssp));
        }
      });
      return retQueues;
    }
  };
}
 
Example #6
Source File: TestKafkaCheckpointManagerJava.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test(expected = StreamValidationException.class)
public void testStartFailsOnTopicValidationErrors() {

  KafkaStreamSpec checkpointSpec = new KafkaStreamSpec(CHECKPOINT_TOPIC, CHECKPOINT_TOPIC,
      CHECKPOINT_SYSTEM, 1);

  // create an admin that throws an exception during validateStream
  SystemAdmin mockAdmin = newAdmin("0", "10");
  doThrow(new StreamValidationException("invalid stream")).when(mockAdmin).validateStream(checkpointSpec);

  SystemFactory factory = newFactory(mock(SystemProducer.class), mock(SystemConsumer.class), mockAdmin);
  KafkaCheckpointManager checkpointManager = new KafkaCheckpointManager(checkpointSpec, factory,
      true, mock(Config.class), mock(MetricsRegistry.class), null, new KafkaCheckpointLogKeySerde());

  // expect an exception during startup
  checkpointManager.createResources();
  checkpointManager.start();
}
 
Example #7
Source File: SamzaStoreStateInternalsTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public KeyValueStore<byte[], byte[]> getKVStore(
    String storeName,
    File storeDir,
    MetricsRegistry registry,
    SystemStreamPartition changeLogSystemStreamPartition,
    JobContext jobContext,
    ContainerContext containerContext,
    StorageEngineFactory.StoreMode readWrite) {
  KeyValueStoreMetrics metrics = new KeyValueStoreMetrics(storeName, registry);
  return new TestStore(metrics);
}
 
Example #8
Source File: ZkUtilsMetrics.java    From samza with Apache License 2.0 5 votes vote down vote up
public ZkUtilsMetrics(MetricsRegistry metricsRegistry) {
  super(metricsRegistry);
  this.reads = newCounter("reads");
  this.writes = newCounter("writes");
  this.deletions = newCounter("deletions");
  this.subscriptions = newCounter("subscriptions");
  this.zkConnectionError = newCounter("zk-connection-errors");
}
 
Example #9
Source File: BaseKeyValueStorageEngineFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps {@code storeToWrap} with the proper layers to handle large messages.
 * If "disallow.large.messages" is enabled, then the message will be serialized and the size will be checked before
 * storing in the serialized message in the cache.
 * If "disallow.large.messages" is disabled, then the deserialized message will be stored in the cache. If
 * "drop.large.messages" is enabled, then large messages will not be sent to the logged store.
 */
private static <T, U> KeyValueStore<T, U> buildStoreWithLargeMessageHandling(String storeName,
    MetricsRegistry registry,
    KeyValueStore<byte[], byte[]> storeToWrap,
    StorageConfig storageConfig,
    int cacheSize,
    int batchSize,
    Serde<T> keySerde,
    Serde<U> msgSerde) {
  int maxMessageSize = storageConfig.getChangelogMaxMsgSizeBytes(storeName);
  if (storageConfig.getDisallowLargeMessages(storeName)) {
    /*
     * The store wrapping ordering is done this way so that a large message cannot end up in the cache. However, it
     * also means that serialized data is in the cache, so performance will be worse since the data needs to be
     * deserialized even when cached.
     */
    KeyValueStore<byte[], byte[]> maybeCachedStore =
        buildMaybeCachedStore(storeName, registry, storeToWrap, cacheSize, batchSize);
    // this will throw a RecordTooLargeException when a large message is encountered
    LargeMessageSafeStore largeMessageSafeKeyValueStore =
        new LargeMessageSafeStore(maybeCachedStore, storeName, false, maxMessageSize);
    return buildSerializedStore(storeName, registry, largeMessageSafeKeyValueStore, keySerde, msgSerde);
  } else {
    KeyValueStore<byte[], byte[]> toBeSerializedStore;
    if (storageConfig.getDropLargeMessages(storeName)) {
      toBeSerializedStore = new LargeMessageSafeStore(storeToWrap, storeName, true, maxMessageSize);
    } else {
      toBeSerializedStore = storeToWrap;
    }
    KeyValueStore<T, U> serializedStore =
        buildSerializedStore(storeName, registry, toBeSerializedStore, keySerde, msgSerde);
    /*
     * Allows deserialized entries to be stored in the cache, but it means that a large message may end up in the
     * cache even though it was not persisted to the logged store.
     */
    return buildMaybeCachedStore(storeName, registry, serializedStore, cacheSize, batchSize);
  }
}
 
Example #10
Source File: TaskConfig.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Create the checkpoint manager
 *
 * @param metricsRegistry Registry of metrics to use. Can be null if not using metrics.
 * @return CheckpointManager object if checkpoint manager factory is configured, otherwise empty.
 */
public Optional<CheckpointManager> getCheckpointManager(MetricsRegistry metricsRegistry) {
  return Optional.ofNullable(get(CHECKPOINT_MANAGER_FACTORY))
      .filter(StringUtils::isNotBlank)
      .map(checkpointManagerFactoryName -> ReflectionUtil.getObj(checkpointManagerFactoryName,
          CheckpointManagerFactory.class).getCheckpointManager(this, metricsRegistry));
}
 
Example #11
Source File: TestCachingTable.java    From samza with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #12
Source File: BlockingEnvelopeMap.java    From samza with Apache License 2.0 5 votes vote down vote up
public BlockingEnvelopeMap(MetricsRegistry metricsRegistry, Clock clock, String metricsGroupName) {
  metricsGroupName = (metricsGroupName == null) ? this.getClass().getName() : metricsGroupName;
  this.metrics = new BlockingEnvelopeMapMetrics(metricsGroupName, metricsRegistry);
  this.bufferedMessages = new ConcurrentHashMap<SystemStreamPartition, BlockingQueue<IncomingMessageEnvelope>>();
  this.noMoreMessage = new ConcurrentHashMap<SystemStreamPartition, Boolean>();
  this.clock = clock;
  this.bufferedMessagesSize = new ConcurrentHashMap<SystemStreamPartition, AtomicLong>();
}
 
Example #13
Source File: MonitorLoader.java    From samza with Apache License 2.0 5 votes vote down vote up
public static Monitor instantiateMonitor(String monitorName, MonitorConfig monitorConfig,
    MetricsRegistry metricsRegistry) throws InstantiationException {
  String factoryClass = monitorConfig.getMonitorFactoryClass();
  try {
    MonitorFactory monitorFactory = ReflectionUtil.getObj(factoryClass, MonitorFactory.class);
    return monitorFactory.getMonitorInstance(monitorName, monitorConfig, metricsRegistry);
  } catch (Exception e) {
    throw (InstantiationException)
        new InstantiationException("Unable to instantiate monitor with factory class " + factoryClass).initCause(e);
  }
}
 
Example #14
Source File: BlockingEnvelopeMap.java    From samza with Apache License 2.0 5 votes vote down vote up
public BlockingEnvelopeMap(MetricsRegistry metricsRegistry) {
  this(metricsRegistry, new Clock() {
    public long currentTimeMillis() {
      return System.currentTimeMillis();
    }
  });
}
 
Example #15
Source File: BlockingEnvelopeMap.java    From samza with Apache License 2.0 5 votes vote down vote up
public BlockingEnvelopeMapMetrics(String group, MetricsRegistry metricsRegistry) {
  this.group = group;
  this.metricsRegistry = metricsRegistry;
  this.noMoreMessageGaugeMap = new ConcurrentHashMap<SystemStreamPartition, Gauge<Integer>>();
  this.blockingPollCountMap = new ConcurrentHashMap<SystemStreamPartition, Counter>();
  this.blockingPollTimeoutCountMap = new ConcurrentHashMap<SystemStreamPartition, Counter>();
  this.pollCount = metricsRegistry.newCounter(group, "poll-count");
}
 
Example #16
Source File: BaseKeyValueStorageEngineFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps {@code storeToWrap} with a {@link CachedStore} if caching is enabled.
 * Otherwise, returns the {@code storeToWrap}.
 */
private static <T, U> KeyValueStore<T, U> buildMaybeCachedStore(String storeName, MetricsRegistry registry,
    KeyValueStore<T, U> storeToWrap, int cacheSize, int batchSize) {
  if (cacheSize > 0) {
    CachedStoreMetrics cachedStoreMetrics = new CachedStoreMetrics(storeName, registry);
    return new CachedStore<>(storeToWrap, cacheSize, batchSize, cachedStoreMetrics);
  } else {
    return storeToWrap;
  }
}
 
Example #17
Source File: BaseKeyValueStorageEngineFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps {@code storeToWrap} with a {@link SerializedKeyValueStore}.
 */
private static <T, U> KeyValueStore<T, U> buildSerializedStore(String storeName,
    MetricsRegistry registry,
    KeyValueStore<byte[], byte[]> storeToWrap,
    Serde<T> keySerde,
    Serde<U> msgSerde) {
  SerializedKeyValueStoreMetrics serializedMetrics = new SerializedKeyValueStoreMetrics(storeName, registry);
  return new SerializedKeyValueStore<>(storeToWrap, keySerde, msgSerde, serializedMetrics);
}
 
Example #18
Source File: TestRemoteTableEndToEnd.java    From samza with Apache License 2.0 5 votes vote down vote up
private Context createMockContext() {
  MetricsRegistry metricsRegistry = mock(MetricsRegistry.class);
  doReturn(new Counter("")).when(metricsRegistry).newCounter(anyString(), anyString());
  doReturn(new Timer("")).when(metricsRegistry).newTimer(anyString(), anyString());
  Context context = new MockContext();
  doReturn(new MapConfig()).when(context.getJobContext()).getConfig();
  doReturn(metricsRegistry).when(context.getContainerContext()).getContainerMetricsRegistry();
  return context;
}
 
Example #19
Source File: TestKafkaCheckpointManagerJava.java    From samza with Apache License 2.0 5 votes vote down vote up
private SystemFactory newFactory(SystemProducer producer, SystemConsumer consumer, SystemAdmin admin) {
  SystemFactory factory = mock(SystemFactory.class);
  when(factory.getProducer(anyString(), any(Config.class), any(MetricsRegistry.class))).thenReturn(producer);
  when(factory.getConsumer(anyString(), any(Config.class), any(MetricsRegistry.class))).thenReturn(consumer);
  when(factory.getAdmin(anyString(), any(Config.class))).thenReturn(admin);
  return factory;
}
 
Example #20
Source File: ZkJobCoordinator.java    From samza with Apache License 2.0 5 votes vote down vote up
ZkJobCoordinator(String processorId, Config config, MetricsRegistry metricsRegistry, ZkUtils zkUtils, MetadataStore jobModelMetadataStore, MetadataStore coordinatorStreamStore) {
  // TODO: When we consolidate metadata stores for standalone, this check can be removed. For now, we expect this type.
  //   Keeping method signature as MetadataStore to avoid public API changes in the future
  Preconditions.checkArgument(coordinatorStreamStore instanceof CoordinatorStreamStore);

  this.config = config;
  this.metrics = new ZkJobCoordinatorMetrics(metricsRegistry);
  this.zkSessionMetrics = new ZkSessionMetrics(metricsRegistry);
  this.processorId = processorId;
  this.zkUtils = zkUtils;
  // setup a listener for a session state change
  // we are mostly interested in "session closed" and "new session created" events
  zkUtils.getZkClient().subscribeStateChanges(new ZkSessionStateChangedListener());
  leaderElector = new ZkLeaderElector(processorId, zkUtils);
  leaderElector.setLeaderElectorListener(new LeaderElectorListenerImpl());
  this.debounceTimeMs = new JobConfig(config).getDebounceTimeMs();
  debounceTimer = new ScheduleAfterDebounceTime(processorId);
  debounceTimer.setScheduledTaskCallback(throwable -> {
    LOG.error("Received exception in debounce timer! Stopping the job coordinator", throwable);
    stop();
  });
  this.barrier =  new ZkBarrierForVersionUpgrade(zkUtils.getKeyBuilder().getJobModelVersionBarrierPrefix(), zkUtils, new ZkBarrierListenerImpl(), debounceTimer);
  systemAdmins = new SystemAdmins(config);
  streamMetadataCache = new StreamMetadataCache(systemAdmins, METADATA_CACHE_TTL_MS, SystemClock.instance());
  LocationIdProviderFactory locationIdProviderFactory =
      ReflectionUtil.getObj(new JobConfig(config).getLocationIdProviderFactory(), LocationIdProviderFactory.class);
  LocationIdProvider locationIdProvider = locationIdProviderFactory.getLocationIdProvider(config);
  this.locationId = locationIdProvider.getLocationId();
  this.coordinatorStreamStore = (CoordinatorStreamStore) coordinatorStreamStore;
  this.jobModelMetadataStore = jobModelMetadataStore;
}
 
Example #21
Source File: AzureBlobSystemProducerMetrics.java    From samza with Apache License 2.0 5 votes vote down vote up
public AzureBlobSystemProducerMetrics(String systemName, String accountName, MetricsRegistry metricsRegistry) {
  this.metricsRegistry = metricsRegistry;
  this.systemName = systemName;
  this.accountName = accountName;

  sourceMetricsMap = new HashMap<>();
  aggregateMetrics = new AzureBlobBasicMetrics(AGGREGATE, metricsRegistry);
  systemMetrics = new AzureBlobBasicMetrics(String.format(SYSTEM_METRIC_FORMAT, accountName, systemName), metricsRegistry);
  aggregateAzureContainerErrorMetrics = metricsRegistry.newCounter(AGGREGATE, AZURE_CONTAINER_ERROR);
  systemAzureContainerErrorMetrics = metricsRegistry.newCounter(String.format(SYSTEM_METRIC_FORMAT, accountName, systemName), AZURE_CONTAINER_ERROR);
}
 
Example #22
Source File: ZkJobCoordinatorFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
private ZkUtils getZkUtils(Config config, MetricsRegistry metricsRegistry, String coordinatorZkBasePath) {
  ZkConfig zkConfig = new ZkConfig(config);
  ZkKeyBuilder keyBuilder = new ZkKeyBuilder(coordinatorZkBasePath);
  ZkClient zkClient = ZkCoordinationUtilsFactory
      .createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs());
  return new ZkUtils(keyBuilder, zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), metricsRegistry);
}
 
Example #23
Source File: EventHubSystemProducer.java    From samza with Apache License 2.0 5 votes vote down vote up
public EventHubSystemProducer(EventHubConfig config, String systemName,
    EventHubClientManagerFactory eventHubClientManagerFactory, Map<String, Interceptor> interceptors,
    MetricsRegistry registry) {
  super(systemName, config, registry);
  LOG.info("Creating EventHub Producer for system {}", systemName);
  this.config = config;
  this.systemName = systemName;
  this.partitioningMethod = config.getPartitioningMethod(systemName);
  this.interceptors = interceptors;
  this.maxMessageSize = config.getSkipMessagesLargerThan(systemName);
  this.eventHubClientManagerFactory = eventHubClientManagerFactory;
}
 
Example #24
Source File: EventHubSystemFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
@Override
public SystemProducer getProducer(String systemName, Config config, MetricsRegistry registry) {
  EventHubConfig eventHubConfig = new EventHubConfig(config);
  return new EventHubSystemProducer(eventHubConfig, systemName, new EventHubClientManagerFactory(),
          getInterceptorsMap(eventHubConfig, systemName),
          registry);
}
 
Example #25
Source File: ZkSessionMetrics.java    From samza with Apache License 2.0 5 votes vote down vote up
public ZkSessionMetrics(MetricsRegistry registry) {
  super(registry);
  this.zkSessionExpirations = newCounter("zk-session-expirations");
  this.zkSessionDisconnects = newCounter("zk-session-disconnects");
  this.zkSessionErrors = newCounter("zk-session-errors");
  this.zkNewSessions = newCounter("zk-new-sessions");
  this.zkSyncConnected = newCounter("zk-sync-connected");
}
 
Example #26
Source File: EventHubSystemConsumer.java    From samza with Apache License 2.0 5 votes vote down vote up
EventHubSystemConsumer(EventHubConfig config, String systemName,
    EventHubClientManagerFactory eventHubClientManagerFactory, Map<String, Interceptor> interceptors,
    MetricsRegistry registry, Clock clock) {
  super(registry, clock);

  this.config = config;
  this.clock = clock;
  this.systemName = systemName;
  this.interceptors = interceptors;
  this.eventHubClientManagerFactory = eventHubClientManagerFactory;
  List<String> streamIds = config.getStreams(systemName);
  prefetchCount = config.getPrefetchCount(systemName);

  recentRetryAttempts = new SlidingTimeWindowReservoir(config.getRetryWindowMs(systemName), clock);

  // Initiate metrics
  eventReadRates =
      streamIds.stream().collect(Collectors.toMap(Function.identity(), x -> registry.newCounter(x, EVENT_READ_RATE)));
  eventByteReadRates = streamIds.stream()
      .collect(Collectors.toMap(Function.identity(), x -> registry.newCounter(x, EVENT_BYTE_READ_RATE)));
  consumptionLagMs = streamIds.stream()
      .collect(Collectors.toMap(Function.identity(), x -> new SamzaHistogram(registry, x, CONSUMPTION_LAG_MS)));
  readErrors =
      streamIds.stream().collect(Collectors.toMap(Function.identity(), x -> registry.newCounter(x, READ_ERRORS)));

  // Locking to ensure that these aggregated metrics will be created only once across multiple system consumers.
  synchronized (AGGREGATE_METRICS_LOCK) {
    if (aggEventReadRate == null) {
      aggEventReadRate = registry.newCounter(AGGREGATE, EVENT_READ_RATE);
      aggEventByteReadRate = registry.newCounter(AGGREGATE, EVENT_BYTE_READ_RATE);
      aggConsumptionLagMs = new SamzaHistogram(registry, AGGREGATE, CONSUMPTION_LAG_MS);
      aggReadErrors = registry.newCounter(AGGREGATE, READ_ERRORS);
    }
  }
}
 
Example #27
Source File: TestLocalTableWrite.java    From samza with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

  putNs = new Timer("");
  putAllNs = new Timer("");
  deleteNs = new Timer("");
  deleteAllNs = new Timer("");
  flushNs = new Timer("");
  numPuts = new Counter("");
  numPutAlls = new Counter("");
  numDeletes = new Counter("");
  numDeleteAlls = new Counter("");
  numFlushes = new Counter("");
  putCallbackNs = new Timer("");
  deleteCallbackNs = new Timer("");

  metricsRegistry = mock(MetricsRegistry.class);
  String groupName = LocalTable.class.getSimpleName();
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-put-ns")).thenReturn(putNs);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-putAll-ns")).thenReturn(putAllNs);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-delete-ns")).thenReturn(deleteNs);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-deleteAll-ns")).thenReturn(deleteAllNs);
  when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-puts")).thenReturn(numPuts);
  when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-putAlls")).thenReturn(numPutAlls);
  when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-deletes")).thenReturn(numDeletes);
  when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-deleteAlls")).thenReturn(numDeleteAlls);
  when(metricsRegistry.newCounter(groupName, TABLE_ID + "-num-flushes")).thenReturn(numFlushes);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-put-callback-ns")).thenReturn(putCallbackNs);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-delete-callback-ns")).thenReturn(deleteCallbackNs);
  when(metricsRegistry.newTimer(groupName, TABLE_ID + "-flush-ns")).thenReturn(flushNs);

  kvStore = mock(KeyValueStore.class);
}
 
Example #28
Source File: ZkUtils.java    From samza with Apache License 2.0 5 votes vote down vote up
public ZkUtils(ZkKeyBuilder zkKeyBuilder, ZkClient zkClient, int connectionTimeoutMs, int sessionTimeOutMs, MetricsRegistry metricsRegistry) {
  this.keyBuilder = zkKeyBuilder;
  this.connectionTimeoutMs = connectionTimeoutMs;
  this.zkClient = zkClient;
  this.metrics = new ZkUtilsMetrics(metricsRegistry);
  this.currentGeneration = new AtomicInteger(0);
  this.sessionTimeoutMs = sessionTimeOutMs;
}
 
Example #29
Source File: ElasticsearchSystemProducerMetrics.java    From samza with Apache License 2.0 5 votes vote down vote up
public ElasticsearchSystemProducerMetrics(String systemName, MetricsRegistry registry) {
  super(systemName + "-", registry);

  bulkSendSuccess = newCounter("bulk-send-success");
  inserts = newCounter("docs-inserted");
  updates = newCounter("docs-updated");
  conflicts = newCounter("version-conflicts");
}
 
Example #30
Source File: ElasticsearchSystemFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
@Override
public SystemProducer getProducer(String name, Config config, MetricsRegistry metricsRegistry) {
  ElasticsearchConfig elasticsearchConfig = new ElasticsearchConfig(name, config);
  return new ElasticsearchSystemProducer(name,
                                         getBulkProcessorFactory(elasticsearchConfig),
                                         getClient(elasticsearchConfig),
                                         getIndexRequestFactory(elasticsearchConfig),
                                         new ElasticsearchSystemProducerMetrics(name, metricsRegistry));
}