public void GetTagsInOrder_Should_Fall_Back_To_Tag_Bag_For_GatewayId()
        {
            // arrange + act
            var result = MetricExporterHelper.GetTagsInOrder(new[] { MetricRegistry.GatewayIdTagName }, Array.Empty<KeyValuePair<string, object?>>(), this.metricTagBag);

            // assert
            Assert.Equal(new[] { GatewayId }, result);
        }
        public void GetTagsInOrder_Should_Indicate_Gateway_Id_Unknown_When_GatewayId_Not_Set()
        {
            // arrange + act
            var result = MetricExporterHelper.GetTagsInOrder(new[] { MetricRegistry.GatewayIdTagName },
                                                             Array.Empty<KeyValuePair<string, object?>>(),
                                                             new RegistryMetricTagBag(new NetworkServerConfiguration()));

            // assert
            Assert.Equal(new[] { "unknown" }, result);
        }
        public void GetTagsInOrder_Should_Fall_Back_To_Tag_Bag_For_Station_Eui()
        {
            // arrange
            var stationEui = new StationEui(1);
            this.metricTagBag.StationEui.Value = stationEui;

            // act
            var result = MetricExporterHelper.GetTagsInOrder(new[] { MetricRegistry.ConcentratorIdTagName }, Array.Empty<KeyValuePair<string, object?>>(), this.metricTagBag);

            // assert
            Assert.Equal(new[] { stationEui.ToString() }, result);
        }
        public void GetTagsInOrder_Returns_Tags_When_Invoked_With_Unordered_Tags()
        {
            // arrange
            var tags = new[] { "foo", "bar" };
            var tagValues = new[] { KeyValuePair.Create("bar", (object?)"barvalue"), KeyValuePair.Create("foo", (object?)"foovalue") };

            // act
            var result = MetricExporterHelper.GetTagsInOrder(tags, tagValues, this.metricTagBag);

            // assert
            Assert.Equal(new[] { "foovalue", "barvalue" }, result);
        }
示例#5
0
        protected override void TrackValue(Instrument instrument, double measurement, ReadOnlySpan <KeyValuePair <string, object?> > tags, object?state)
        {
#pragma warning disable format
            Action <string, string[], double> trackMetric = instrument switch
            {
                Counter <double> or Counter <int> or
                Counter <short> or Counter <byte> or
                Counter <long> or Counter <decimal> or
                                              Counter <float> => IncCounter,
                Histogram <double> or Histogram <int> or
                Histogram <short> or Histogram <byte> or
                Histogram <long> or Histogram <decimal> or
                Histogram <float> => RecordHistogram,
                ObservableGauge <double> or ObservableGauge <int> or
                ObservableGauge <short> or ObservableGauge <byte> or
                ObservableGauge <long> or ObservableGauge <decimal> or
                ObservableGauge <float> => RecordObservableGauge,
                _ => throw new NotImplementedException()
            };
#pragma warning restore format

            var inOrderTags = MetricExporterHelper.GetTagsInOrder(this.registryLookup[instrument.Name].Tags, tags, this.metricTagBag);
            trackMetric(instrument.Name, inOrderTags, measurement);
        }
 public void GetTagsInOrder_Throws_When_Tag_Is_Empty()
 {
     const string tagName = "foo";
     var result = Assert.Throws<LoRaProcessingException>(() => MetricExporterHelper.GetTagsInOrder(new[] { tagName }, new[] { KeyValuePair.Create(tagName, (object?)string.Empty) }, this.metricTagBag));
     Assert.Equal(LoRaProcessingErrorCode.TagNotSet, result.ErrorCode);
 }
 public void GetTagsInOrder_Throws_When_Tag_Value_Is_Not_In_Tag_Names(string[] tagNames, params KeyValuePair<string, object?>[] tagValues)
 {
     _ = Assert.Throws<InvalidOperationException>(() => MetricExporterHelper.GetTagsInOrder(tagNames, tagValues, this.metricTagBag));
 }
 public void GetTagsInOrder_Throws_When_Tag_Not_Found()
 {
     var result = Assert.Throws<LoRaProcessingException>(() => MetricExporterHelper.GetTagsInOrder(new[] { "foo" }, Array.Empty<KeyValuePair<string, object?>>(), this.metricTagBag));
     Assert.Equal(LoRaProcessingErrorCode.TagNotSet, result.ErrorCode);
 }