Example #1
0
        public void TestMetricsSimulateHeartbeat()
        {
            var evalMetrics1 = TangFactory.GetTang().NewInjector().GetInstance <IEvaluatorMetrics>();

            evalMetrics1.CreateAndRegisterMetric <CounterMetric>("counter", "counter with no records", false);
            evalMetrics1.CreateAndRegisterMetric <IntegerMetric>("iteration", "iteration with records", true);
            Assert.True(evalMetrics1.TryGetMetric("counter", out CounterMetric counter));
            Assert.True(evalMetrics1.TryGetMetric("iteration", out IntegerMetric iter));
            for (int i = 1; i <= 5; i++)
            {
                counter.Increment();
                iter.AssignNewValue(i);
            }

            var me1Str       = evalMetrics1.Serialize();
            var evalMetrics2 = new EvaluatorMetrics(me1Str);
            var metricsData2 = evalMetrics2.GetMetricsData();

            var sink = TangFactory.GetTang().NewInjector().GetInstance <IMetricsSink>();

            sink.Sink(metricsData2.FlushMetricRecords());

            foreach (var t in metricsData2.GetMetricTrackers())
            {
                Assert.Equal(0, t.GetMetricRecords().ToList().Count);
            }
        }
Example #2
0
        public void TestEvaluatorMetricsCountersOnly()
        {
            var evalMetrics1 = TangFactory.GetTang().NewInjector().GetInstance <IEvaluatorMetrics>();
            var counter1     = evalMetrics1.CreateAndRegisterMetric <CounterMetric>(
                "counter1",
                "Counter1 description",
                false);

            for (int i = 0; i < 5; i++)
            {
                counter1.Increment();
            }
            var evalMetricsData = evalMetrics1.GetMetricsData();

            ValidateMetric(evalMetricsData, "counter1", 5);

            foreach (var t in evalMetricsData.GetMetricTrackers())
            {
                // Records for counter1 should be null because KeepUpdateHistory is false.
                Assert.Null(t.GetMetricRecords());
            }

            var metricsStr   = evalMetrics1.Serialize();
            var evalMetrics2 = new EvaluatorMetrics(metricsStr);

            Assert.False(evalMetrics2.GetMetricsData().TryGetMetric("counter1", out CounterMetric metricObj));
            Assert.Null(metricObj);
        }
Example #3
0
        public void TestEvaluatorMetrics()
        {
            var metrics  = TangFactory.GetTang().NewInjector().GetInstance <IEvaluatorMetrics>();
            var counters = metrics.GetMetricsCounters();

            counters.TryRegisterCounter("counter1", "counter1 description");
            counters.TryRegisterCounter("counter2", "counter2 description");
            ValidateCounter(counters, "counter1", 0);
            ValidateCounter(counters, "counter2", 0);

            counters.Increment("counter1", 3);
            counters.Increment("counter1", 1);
            counters.Increment("counter2", 2);
            counters.Increment("counter2", 3);
            ValidateCounter(counters, "counter1", 4);
            ValidateCounter(counters, "counter2", 5);

            var counterStr = metrics.Serialize();

            var metrics2  = new EvaluatorMetrics(counterStr);
            var counters2 = metrics2.GetMetricsCounters();

            ValidateCounter(counters2, "counter1", 4);
            ValidateCounter(counters2, "counter2", 5);
        }