Beispiel #1
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);
        }
Beispiel #2
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);
            }
        }