public MetricsData(int version, Metric metric, ref MetricPoint metricPoint) : base(version) { if (metric == null) { throw new ArgumentNullException(nameof(metric)); } IList <MetricDataPoint> metricDataPoints = new List <MetricDataPoint>(); MetricDataPoint metricDataPoint = null; switch (metric.MetricType) { case MetricType.DoubleSum: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetSumDouble()); metricDataPoint.DataPointType = DataPointType.Aggregation; break; case MetricType.DoubleGauge: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetGaugeLastValueDouble()); metricDataPoint.DataPointType = DataPointType.Measurement; break; } metricDataPoints.Add(metricDataPoint); Metrics = metricDataPoints; Properties = new ChangeTrackingDictionary <string, string>(); foreach (var tag in metricPoint.Tags) { Properties.Add(new KeyValuePair <string, string>(tag.Key, tag.Value?.ToString())); } Properties.Add(AggregationIntervalMsKey, DefaultExportIntervalMilliseconds); }
public MetricsData(int version, Metric metric, ref MetricPoint metricPoint) : base(version) { IList <MetricDataPoint> metricDataPoints = new List <MetricDataPoint>(); MetricDataPoint metricDataPoint = null; switch (metric.MetricType) { case MetricType.DoubleSum: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetSumDouble()); metricDataPoint.DataPointType = DataPointType.Aggregation; break; case MetricType.DoubleGauge: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetGaugeLastValueDouble()); metricDataPoint.DataPointType = DataPointType.Measurement; break; } metricDataPoints.Add(metricDataPoint); Metrics = metricDataPoints; Properties = new ChangeTrackingDictionary <string, string>(); foreach (var tag in metricPoint.Tags) { Properties.Add(new KeyValuePair <string, string>(tag.Key, tag.Value?.ToString())); } }
public void Add_KeyValuePair_AddsNewItem() { var expectedKey = "key"; var expectedItem = new TestItem(); var subject = new ChangeTrackingDictionary <string, TestItem>(); subject.Add(new KeyValuePair <string, TestItem>(expectedKey, expectedItem)); Assert.True(subject.HasChanges); var changes = subject.GetChangeSet(ChangePath.Empty); Assert.Single(changes); var values = changes.First().Value; var value = Assert.Single(values); Assert.Equal(ChangeAction.Add, value.Action); Assert.Same(expectedItem, value.NewValue); }
public MetricsData(int version, Metric metric, MetricPoint metricPoint) : base(version) { if (metric == null) { throw new ArgumentNullException(nameof(metric)); } IList <MetricDataPoint> metricDataPoints = new List <MetricDataPoint>(); MetricDataPoint metricDataPoint = null; switch (metric.MetricType) { case MetricType.DoubleSum: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetSumDouble()) { DataPointType = DataPointType.Aggregation }; break; case MetricType.DoubleGauge: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetGaugeLastValueDouble()) { DataPointType = DataPointType.Measurement }; break; case MetricType.LongSum: // potential for minor precision loss implicitly going from long->double // see: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/numeric-conversions#implicit-numeric-conversions metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetSumLong()) { DataPointType = DataPointType.Aggregation }; break; case MetricType.LongGauge: // potential for minor precision loss implicitly going from long->double // see: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/numeric-conversions#implicit-numeric-conversions metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetGaugeLastValueLong()) { DataPointType = DataPointType.Measurement }; break; case MetricType.Histogram: metricDataPoint = new MetricDataPoint(metric.Name, metricPoint.GetHistogramSum()); metricDataPoint.DataPointType = DataPointType.Aggregation; long histogramCount = metricPoint.GetHistogramCount(); // Current schema only supports int values for count // if the value is within integer range we will use it otherwise ignore it. metricDataPoint.Count = (histogramCount <= int.MaxValue && histogramCount >= int.MinValue) ? (int?)histogramCount : null; break; } metricDataPoints.Add(metricDataPoint); Metrics = metricDataPoints; Properties = new ChangeTrackingDictionary <string, string>(); foreach (var tag in metricPoint.Tags) { if (tag.Key.Length <= SchemaConstants.MetricsData_Properties_MaxKeyLength && tag.Value != null) { // Note: if Key exceeds MaxLength or if Value is null, the entire KVP will be dropped. Properties.Add(new KeyValuePair <string, string>(tag.Key, tag.Value.ToString().Truncate(SchemaConstants.MetricsData_Properties_MaxValueLength))); } } Properties.Add(AggregationIntervalMsKey, DefaultExportIntervalMilliseconds); }