Exemple #1
0
        public void TestMultipleAggregation()
        {
            // metrics with 2 tags, key1, that has key values of val[0-1], and key2, which has key values of val[0-3].
            IEnumerable <Metric> metrics = Enumerable.Range(1, 12).Select(i => new Metric(this.now, "test_metric", i, new Dictionary <string, string>
            {
                { "key1", $"val{i % 2}" },
                { "key2", $"val{i % 4}" }
            })).ToArray();

            // values are summed by ignoring key1 first (so shared key2), then multiplied together (since only key 2 is left)
            MetricAggregator aggregator = new MetricAggregator(new AggregationTemplate(
                                                                   "test_metric",
                                                                   ("key1", new Summer()),
                                                                   ("key2", new Multiplier())));

            Metric result = aggregator.AggregateMetrics(metrics).Single();

            // split by key2 (mod 4) and summed, then the result is multiplied
            double expected = (1 + 5 + 9) * (2 + 6 + 10) * (3 + 7 + 11) * (4 + 8 + 12);

            Assert.Equal(expected, result.Value);

            // values are multiplied by ignoring key2 first (so shared key1), then summed together (since only key1 is left)
            aggregator = new MetricAggregator(new AggregationTemplate(
                                                  "test_metric",
                                                  ("key2", new Multiplier()),
                                                  ("key1", new Summer())));

            result = aggregator.AggregateMetrics(metrics).Single();

            // split by key1 (mod 2) and multiplied, then the result is summed
            expected = (1 * 3 * 5 * 7 * 9 * 11) + (2 * 4 * 6 * 8 * 10 * 12);
            Assert.Equal(expected, result.Value);
        }
Exemple #2
0
        public void TestMultipleTagsKeepsNonAggregateTagsSeperate()
        {
            MetricAggregator aggregator = new MetricAggregator(new AggregationTemplate(
                                                                   "test_metric",
                                                                   ("key1", new Summer()),
                                                                   ("key2", new Multiplier())));

            // metrics with 3 tags, key1, that has key values of val[0-1], key2, which has key values of val[0-3], and key3, which has values [True/False].
            IEnumerable <Metric> metrics = Enumerable.Range(1, 16).Select(i => new Metric(this.now, "test_metric", i, new Dictionary <string, string>
            {
                { "key1", $"val{i % 2}" },
                { "key2", $"val{i % 4}" },
                { "key3", (i <= 8).ToString() }
            })).ToArray();

            Metric[] results = aggregator.AggregateMetrics(metrics).ToArray();
            Assert.Equal(2, results.Length);

            // always split by key3 (<= 8), then split by key2 (mod 4) and summed, then multiplied
            double expected = (1 + 5) * (2 + 6) * (3 + 7) * (4 + 8);

            Assert.Equal(expected, results.Where(m => m.Tags.Contains(new KeyValuePair <string, string>("key3", true.ToString()))).Single().Value);

            expected = (9 + 13) * (10 + 14) * (11 + 15) * (12 + 16);
            Assert.Equal(expected, results.Where(m => m.Tags.Contains(new KeyValuePair <string, string>("key3", false.ToString()))).Single().Value);
        }
Exemple #3
0
        public MetricsWorker(IMetricsScraper scraper, IMetricsStorage storage, IMetricsPublisher uploader)
        {
            this.scraper  = Preconditions.CheckNotNull(scraper, nameof(scraper));
            this.storage  = Preconditions.CheckNotNull(storage, nameof(storage));
            this.uploader = Preconditions.CheckNotNull(uploader, nameof(uploader));

            this.metricFilter = new MetricTransformer()
                                .AddAllowedTags((MetricsConstants.MsTelemetry, true.ToString()))
                                .AddDisallowedTags(
                ("quantile", "0.1"),
                ("quantile", "0.5"),
                ("quantile", "0.99"))
                                .AddTagsToRemove(MetricsConstants.MsTelemetry, MetricsConstants.IotHubLabel, MetricsConstants.DeviceIdLabel)
                                .AddTagsToModify(
                ("id", this.ReplaceDeviceId),
                ("module_name", this.ReplaceModuleId),
                ("to", name => name.CreateSha256()),
                ("from", name => name.CreateSha256()),
                ("to_route_input", name => name.CreateSha256()),
                ("from_route_output", name => name.CreateSha256()));

#pragma warning disable SA1111 // Closing parenthesis should be on line of last parameter
            this.metricAggregator = new MetricAggregator(
                new AggregationTemplate("edgehub_gettwin_total", "id", new Summer()),
                new AggregationTemplate(
                    "edgehub_messages_received_total",
                    ("route_output", new Summer()),
                    ("id", new Summer())
                    ),
                new AggregationTemplate(
                    "edgehub_messages_sent_total",
                    ("from", new Summer()),
                    ("to", new Summer()),
                    ("from_route_output", new Summer()),
                    ("to_route_input", new Summer())
                    ),
                new AggregationTemplate(
                    new string[]
            {
                "edgehub_message_size_bytes",
                "edgehub_message_size_bytes_sum",
                "edgehub_message_size_bytes_count"
            },
                    "id",
                    new Averager()),
                new AggregationTemplate(
                    new string[]
            {
                "edgehub_message_process_duration_seconds",
                "edgehub_message_process_duration_seconds_sum",
                "edgehub_message_process_duration_seconds_count",
            },
                    ("from", new Averager()),
                    ("to", new Averager())
                    ),
                new AggregationTemplate(
                    "edgehub_direct_methods_total",
                    ("from", new Summer()),
                    ("to", new Summer())
                    ),
                new AggregationTemplate("edgehub_queue_length", "endpoint", new Summer()),
                new AggregationTemplate(
                    new string[]
            {
                "edgehub_messages_dropped_total",
                "edgehub_messages_unack_total",
            },
                    ("from", new Summer()),
                    ("from_route_output", new Summer())
                    ),
                new AggregationTemplate("edgehub_client_connect_failed_total", "id", new Summer())
                );
#pragma warning restore SA1111 // Closing parenthesis should be on line of last parameter
        }