コード例 #1
0
        public async void Fields_can_be_converted_to_boolean()
        {
            const bool expectedValue = true;
            var        options       = new InfluxDbObserverOptions("databaseName");
            var        observer      = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                            options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag>(), new[] { new Measurement <bool>("value", expectedValue) }) });

            await influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == "value" && (bool)field.Value == expectedValue))));
        }
コード例 #2
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Fields_can_be_converted_to_string()
        {
            const string expectedValue = "any string";
            var          options       = new InfluxDbObserverOptions("databaseName");
            var          observer      = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                              options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new Tag[0], expectedValue, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == "value" && (string)field.Value == expectedValue))));
        }
コード例 #3
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Measurement_name_selector_is_used_to_select_measurement_name()
        {
            const string expectedMeasurementName = "expectedMeasurementName";
            var          options = new InfluxDbObserverOptions("databaseName")
            {
                MeasurementNameSelector = metric => expectedMeasurementName
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new Tag[0], 0, new Metric[0]) });

            influxDbClient.Received(1).WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                                                  Arg.Is <IEnumerable <Point> >(x => x.All(y => y.Measurement == expectedMeasurementName)));
        }
コード例 #4
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Retention_policy_is_used_to_select_retention_policy()
        {
            const string expectedRetentionPolicy = "expectedRetentionPolicy";
            var          options = new InfluxDbObserverOptions("databaseName")
            {
                RetentionPolicySelector = (metric, database) => expectedRetentionPolicy,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new Tag[0], 0, new Metric[0]) });

            influxDbClient.DidNotReceive().WriteAsync("autogen", Arg.Any <string>(), Arg.Any <IEnumerable <Point> >());
            influxDbClient.Received(1).WriteAsync(expectedRetentionPolicy, Arg.Any <string>(),
                                                  Arg.Is <IEnumerable <Point> >(x => x.All(y => y.Measurement == "name")));
        }
コード例 #5
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Database_selector_is_used_to_select_database()
        {
            const string expectedDatabase  = "expectedDatabase";
            const string incorrectDatabase = "databaseName";
            var          options           = new InfluxDbObserverOptions(incorrectDatabase)
            {
                DatabaseSelector = _ => expectedDatabase
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new Tag[0], 0, new Metric[0]) });

            influxDbClient.DidNotReceive().WriteAsync(Arg.Any <string>(), incorrectDatabase, Arg.Any <IEnumerable <Point> >());
            influxDbClient.Received(1).WriteAsync(Arg.Any <string>(), expectedDatabase, Arg.Is <IEnumerable <Point> >(x => x.All(y => y.Measurement == "name")));
        }
コード例 #6
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Fields_converted_to_double_are_handled_as_float()
        {
            const float expectedValue = 1.0f;
            var         options       = new InfluxDbObserverOptions("databaseName")
            {
                ConvertFieldType = x => Convert.ToDouble(x)
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new Tag[0], expectedValue, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == "value" && (float)field.Value == expectedValue))));
        }
コード例 #7
0
        public async void Fields_are_converted_according_to_options()
        {
            const float expectedValue = 1.0f;
            var         options       = new InfluxDbObserverOptions("databaseName")
            {
                ConvertFieldType = x => Convert.ToSingle(x)
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag>(), new[] { new Measurement <int>("value", (int)expectedValue) }) });

            await influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == "value" && (float)field.Value == expectedValue))));
        }
コード例 #8
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Tags_can_be_converted_to_string()
        {
            const string tagName  = "tag";
            const string tagValue = "a random string";
            var          options  = new InfluxDbObserverOptions("databaseName")
            {
                TagToFieldSelector = tag => tag.Key == tagName,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new[] { new Tag(tagName, tagValue), }, 0, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == tagName && (string)field.Value == tagValue))));
        }
コード例 #9
0
ファイル: InfluxDbObserverTest.cs プロジェクト: forki/Okanshi
        public void Tags_can_be_ignored_as_defined_by_options()
        {
            const string tagName = "tag";
            var          options = new InfluxDbObserverOptions("databaseName")
            {
                TagsToIgnore = new List <string> {
                    tagName
                }
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new[] { new Tag(tagName, "100"), }, 0, new Metric[0]) });

            influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(point => point.Tags.All(tag => tag.Key != tagName))));
        }
コード例 #10
0
        public async void Tags_can_be_converted_to_boolean()
        {
            const string tagName  = "tag";
            const string tagValue = "true";
            var          options  = new InfluxDbObserverOptions("databaseName")
            {
                TagToFieldSelector = tag => tag.Key == tagName,
            };
            var observer = new InfluxDbObserver(new MetricMonitorRegistryPoller(DefaultMonitorRegistry.Instance), influxDbClient,
                                                options);

            await observer.Update(new[] { new Metric("name", DateTimeOffset.UtcNow, new List <Tag> {
                    new Tag(tagName, tagValue),
                }, new[] { new Measurement <int>("value", 0) }) });

            await influxDbClient.Received(1)
            .WriteAsync(Arg.Any <string>(), Arg.Any <string>(),
                        Arg.Is <IEnumerable <Point> >(points => points.All(
                                                          point => point.Fields.Any(field => field.Key == tagName && (bool)field.Value == Convert.ToBoolean(tagValue)))));
        }