public void BuildSummaryMetric()
        {
            var timestamp = DateTime.UtcNow;
            var interval  = 33L;
            var value     = MetricSummaryValue.Create(10d, 64, 3, 15);

            var attributes = new Dictionary <string, object>
            {
                { "attrKey", "attrValue" }
            };

            var metricBuilder = MetricBuilder.CreateSummaryMetric("metricname")
                                .WithValue(value)
                                .WithTimestamp(timestamp)
                                .WithIntervalMs(interval)
                                .WithAttribute("adsfasdf", 12)
                                .WithAttributes(attributes);

            var metric = metricBuilder.Build();

            Assert.AreEqual("metricname", metric.Name);
            Assert.AreEqual("summary", metric.Type);
            Assert.AreEqual(value, metric.Value);
            Assert.AreEqual(DateTimeExtensions.ToUnixTimeMilliseconds(timestamp), metric.Timestamp);
            Assert.AreEqual(interval, metric.IntervalMs);
            Assert.AreEqual(12, metric.Attributes["adsfasdf"]);
            Assert.AreEqual("attrValue", metric.Attributes["attrKey"]);
        }
Exemple #2
0
        public void MetricBatchWithNoCommonElement()
        {
            var timestamp    = DateTime.UtcNow;
            var interval     = 125L;
            var gaugeValue   = 213d;
            var summaryValue = MetricSummaryValue.Create(10d, 64, 3, 15);

            var metricBatch = MetricBatchBuilder.Create()
                              .WithMetric(MetricBuilder.CreateSummaryMetric("SummaryMetric")
                                          .WithTimestamp(timestamp)
                                          .WithIntervalMs(interval)
                                          .WithValue(summaryValue)
                                          .Build())
                              .WithMetric(MetricBuilder.CreateGaugeMetric("GaugeMetric")
                                          .WithTimestamp(timestamp)
                                          .WithIntervalMs(interval)
                                          .WithValue(gaugeValue)
                                          .Build())
                              .Build();

            Assert.AreEqual(2, metricBatch.Metrics.Count, $"MetricBatch Metrics count - expected: 2, actual: {metricBatch.Metrics.Count}");
            Assert.IsNull(metricBatch.CommonProperties, $"MetricBatch CommonProperties - expected: null, actual: not null");
        }