public void Initialize()
        {
            streamMetricsRegistry
                = new StreamMetricsRegistry(Guid.NewGuid().ToString(),
                                            MetricsRecordingLevel.DEBUG);

            config.ApplicationId    = "test-stream-thread";
            config.StateDir         = Guid.NewGuid().ToString();
            config.Guarantee        = ProcessingGuarantee.AT_LEAST_ONCE;
            config.PollMs           = 10;
            config.CommitIntervalMs = 1;

            var builder = new StreamBuilder();
            var stream  = builder.Stream <string, string>("topic");

            stream.GroupByKey().Count();
            stream.To("topic2");

            var topo = builder.Build();

            id = new TaskId {
                Id = 0, Partition = 0
            };
            var processorTopology = builder.Build().Builder.BuildTopology(id);

            syncKafkaSupplier = new SyncKafkaSupplier();
            var producer = syncKafkaSupplier.GetProducer(config.ToProducerConfig());
            var consumer = syncKafkaSupplier.GetConsumer(config.ToConsumerConfig(), null);

            topicPartition = new TopicPartition("topic", 0);
            task           = new StreamTask(
                threadId,
                id,
                new List <TopicPartition> {
                topicPartition
            },
                processorTopology,
                consumer,
                config,
                syncKafkaSupplier,
                null,
                new MockChangelogRegister(),
                streamMetricsRegistry);
            task.GroupMetadata = consumer as SyncConsumer;

            task.InitializeStateStores();
            task.InitializeTopology();
            task.RestorationIfNeeded();
            var activeRestorationSensor = streamMetricsRegistry.GetSensors().FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.ACTIVE_RESTORATION)));

            Assert.AreEqual(1,
                            activeRestorationSensor.Metrics[MetricName.NameAndGroup(
                                                                TaskMetrics.ACTIVE_RESTORATION,
                                                                StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
            task.CompleteRestoration();
            Assert.AreEqual(0,
                            activeRestorationSensor.Metrics[MetricName.NameAndGroup(
                                                                TaskMetrics.ACTIVE_RESTORATION,
                                                                StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
        }
        private StreamMetric GetSensorMetric(string sensorName, string metricSuffix, string group)
        {
            long now    = DateTime.Now.GetMilliseconds();
            var  sensor = streamMetricsRegistry.GetSensors().FirstOrDefault(s => s.Name.Equals(GetSensorName(sensorName)));

            if (sensor == null)
            {
                throw new NullReferenceException($"sensor {sensorName} not found");
            }

            MetricName keyMetric = MetricName.NameAndGroup(
                sensorName + metricSuffix,
                group);

            if (!sensor.Metrics.ContainsKey(keyMetric))
            {
                throw new NullReferenceException($"metric {sensorName + metricSuffix}|{group} not found inside {sensorName}");
            }

            return(sensor.Metrics[keyMetric]);
        }
Beispiel #3
0
 /// <summary>
 /// Get read-only handle on global sensors registry, including streams client's own sensors plus
 /// its embedded producer, consumer sensors (if <see cref="IStreamConfig.ExposeLibrdKafkaStats"/> is enable.
 /// </summary>
 /// <returns><see cref="IReadOnlyCollection{T}"/> of all sensors</returns>
 public IEnumerable <Sensor> Metrics()
 => metricsRegistry.GetSensors();