Ejemplo n.º 1
0
        public void TestLabeledBooleanMetricType()
        {
            BooleanMetricType booleanMetric = new BooleanMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledBooleanMetric = new LabeledMetricType <BooleanMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_boolean_metric",
                sendInPings: new string[] { "metrics" },
                submetric: booleanMetric
                );

            labeledBooleanMetric["label1"].Set(false);
            labeledBooleanMetric["label2"].Set(true);

            Assert.False(labeledBooleanMetric["label1"].TestGetValue());
            Assert.True(labeledBooleanMetric["label2"].TestGetValue());
        }
Ejemplo n.º 2
0
        public void TestLabeledStringMetricType()
        {
            StringMetricType stringMetric = new StringMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_string_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledStringMetric = new LabeledMetricType <StringMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_string_metric",
                sendInPings: new string[] { "metrics" },
                submetric: stringMetric
                );

            labeledStringMetric["label1"].Set("foo");
            labeledStringMetric["label2"].Set("bar");

            Assert.Equal("foo", labeledStringMetric["label1"].TestGetValue());
            Assert.Equal("bar", labeledStringMetric["label2"].TestGetValue());
        }
Ejemplo n.º 3
0
        public void EnsureInvalidLabelsOnLabeledStringGoToOther()
        {
            StringMetricType stringMetric = new StringMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_string_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledStringMetric = new LabeledMetricType <StringMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_string_metric",
                sendInPings: new string[] { "metrics" },
                submetric: stringMetric
                );

            labeledStringMetric["notSnakeCase"].Set("foo");
            labeledStringMetric[""].Set("foo");
            labeledStringMetric["with/slash"].Set("foo");
            labeledStringMetric["this_string_has_more_than_thirty_characters"].Set("foo");

            Assert.Equal(
                4,
                labeledStringMetric.TestGetNumRecordedErrors(
                    ErrorType.InvalidLabel
                    )
                );
            Assert.Equal(
                "foo",
                labeledStringMetric["__other__"].TestGetValue()
                );
        }
Ejemplo n.º 4
0
        public void TestOtherLabelWithoutPredefinedLabels()
        {
            CounterMetricType counterMetric = new CounterMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledCounterMetric = new LabeledMetricType <CounterMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" },
                submetric: counterMetric
                );

            for (int i = 0; i <= 20; i++)
            {
                labeledCounterMetric[$"label_{i}"].Add(1);
            }
            // Go back and record in one of the real labels again
            labeledCounterMetric["label_0"].Add(1);

            Assert.Equal(2, labeledCounterMetric["label_0"].TestGetValue());
            for (int i = 1; i <= 15; i++)
            {
                Assert.Equal(1, labeledCounterMetric[$"label_{i}"].TestGetValue());
            }
            Assert.Equal(5, labeledCounterMetric["__other__"].TestGetValue());
        }
Ejemplo n.º 5
0
        public void TestOtherLabelWithoutPredefinedLabelsBeforeGleanInits()
        {
            CounterMetricType counterMetric = new CounterMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledCounterMetric = new LabeledMetricType <CounterMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" },
                submetric: counterMetric
                );

            // Make sure Glean isn't initialized, and turn task queueing on
            GleanInstance.TestDestroyGleanHandle();
            Dispatchers.QueueInitialTasks = true;

            for (int i = 0; i <= 20; i++)
            {
                labeledCounterMetric[$"label_{i}"].Add(1);
            }
            // Go back and record in one of the real labels again
            labeledCounterMetric["label_0"].Add(1);

            // Initialize glean
            GleanInstance.Initialize(
                applicationId: "org.mozilla.csharp.tests",
                applicationVersion: "1.0-test",
                uploadEnabled: true,
                configuration: new Configuration(),
                dataDir: TempDataDir
                );

            Assert.Equal(2, labeledCounterMetric["label_0"].TestGetValue());
            for (int i = 1; i <= 15; i++)
            {
                Assert.Equal(1, labeledCounterMetric[$"label_{i}"].TestGetValue());
            }
            Assert.Equal(5, labeledCounterMetric["__other__"].TestGetValue());
        }
Ejemplo n.º 6
0
        public void TestOtherLabelWithPredefinedLabels()
        {
            CounterMetricType counterMetric = new CounterMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledCounterMetric = new LabeledMetricType <CounterMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" },
                submetric: counterMetric,
                labels: new HashSet <string>()
            {
                "foo", "bar", "baz"
            }
                );

            labeledCounterMetric["foo"].Add(1);
            labeledCounterMetric["foo"].Add(2);
            labeledCounterMetric["bar"].Add(1);
            labeledCounterMetric["not_there"].Add(1);
            labeledCounterMetric["also_not_there"].Add(1);
            labeledCounterMetric["not_me"].Add(1);

            Assert.Equal(3, labeledCounterMetric["foo"].TestGetValue());
            Assert.Equal(1, labeledCounterMetric["bar"].TestGetValue());
            Assert.False(labeledCounterMetric["baz"].TestHasValue());
            // The rest all lands in the __other__ bucket
            Assert.Equal(3, labeledCounterMetric["not_there"].TestGetValue());
        }
Ejemplo n.º 7
0
        public void TestLabeledCounterType()
        {
            CounterMetricType counterMetric = new CounterMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" }
                );

            var labeledCounterMetric = new LabeledMetricType <CounterMetricType>(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Application,
                name: "labeled_counter_metric",
                sendInPings: new string[] { "metrics" },
                submetric: counterMetric
                );

            labeledCounterMetric["label1"].Add(1);
            labeledCounterMetric["label2"].Add(2);

            // Record a regular non-labeled counter. This isn't normally
            // possible with the generated code because the subMetric is private,
            // but it's useful to test here that it works.
            counterMetric.Add(3);

            Assert.True(labeledCounterMetric["label1"].TestHasValue());
            Assert.Equal(1, labeledCounterMetric["label1"].TestGetValue());

            Assert.True(labeledCounterMetric["label2"].TestHasValue());
            Assert.Equal(2, labeledCounterMetric["label2"].TestGetValue());

            Assert.True(counterMetric.TestHasValue());
            Assert.Equal(3, counterMetric.TestGetValue());
        }