public void TestRegisterProducerRemove1BrokerMetrics() { var producerStatisticsHandler = new ProducerStatisticsHandler( config.ClientId, config.ApplicationId, threadId); producerStatisticsHandler.Register(streamMetricsRegistry); var sensorLibrdkafkaProducerMetrics = streamMetricsRegistry .GetThreadScopeSensor(threadId) .Count(s => s.Name.StartsWith($"{StreamMetricsRegistry.SENSOR_LIBRDKAFKA_LABEL}.")); Assert.IsTrue(sensorLibrdkafkaProducerMetrics > 0); var statistics = JsonConvert.DeserializeObject <Statistics>(jsonPayload); producerStatisticsHandler.Publish(statistics); var sensorTotalBRInFlight = streamMetricsRegistry .GetThreadScopeSensor(threadId) .FirstOrDefault(s => s.Name.Contains($"{LibrdKafkaProducerMetrics.TOTAL_BROKER_REQUEST_INFLIFGHT_AWAITING_RESPONSE}")); Assert.AreEqual(3, sensorTotalBRInFlight.Metrics.Count()); Thread.Sleep(100); var statistics2 = JsonConvert.DeserializeObject <Statistics>(jsonPayloadWithout1Broker); producerStatisticsHandler.Publish(statistics2); var sensorTotalBRInFlight2 = streamMetricsRegistry .GetThreadScopeSensor(threadId) .FirstOrDefault(s => s.Name.Contains($"{LibrdKafkaProducerMetrics.TOTAL_BROKER_REQUEST_INFLIFGHT_AWAITING_RESPONSE}")); Assert.AreEqual(2, sensorTotalBRInFlight2.Metrics.Count()); }
public void TestRegisterProducerMetrics() { var producerStatisticsHandler = new ProducerStatisticsHandler( config.ClientId, config.ApplicationId, threadId, "0_0"); producerStatisticsHandler.Register(streamMetricsRegistry); var sensorLibrdkafkaProducerMetrics = streamMetricsRegistry .GetThreadScopeSensor(threadId) .Count(s => s.Name.StartsWith($"{StreamMetricsRegistry.SENSOR_LIBRDKAFKA_LABEL}.")); Assert.IsTrue(sensorLibrdkafkaProducerMetrics > 0); var statistics = JsonConvert.DeserializeObject <Statistics>(jsonPayload); producerStatisticsHandler.Publish(statistics); }
public IProducer <byte[], byte[]> GetProducer(ProducerConfig config) { ProducerBuilder <byte[], byte[]> builder = builderKafkaHandler.GetProducerBuilder(config); builder.SetLogHandler(loggerAdapter.LogProduce); builder.SetErrorHandler(loggerAdapter.ErrorProduce); if (exposeLibrdKafka) { // TODO : test librdkafka statistics with IntegrationTest (WIP see #82) var producerStatisticsHandler = new ProducerStatisticsHandler( config.ClientId, streamConfig.ApplicationId, (config as StreamizProducerConfig)?.ThreadId, (config as StreamizProducerConfig)?.Id?.ToString()); producerStatisticsHandler.Register(MetricsRegistry); builder.SetStatisticsHandler((c, stat) => { var statistics = JsonConvert.DeserializeObject <Statistics>(stat); producerStatisticsHandler.Publish(statistics); }); } return(builder.Build()); }