コード例 #1
0
        public async void ExploreSolution_GetAllReservations_LoadTest()
        {
            string   baseUrl        = "https://exploresolutionapi.azurewebsites.net";
            string   loginUrl       = baseUrl + "/api/Authentication/request";
            string   getAllToursUrl = baseUrl + "/api/reservations/GetAllReservations";
            TimeSpan warmUp         = TimeSpan.FromMinutes(1);

            IStep loginStep = Auth(loginUrl);

            var getAllReservations = HttpStep.Create("getReservations", async(context) =>
            {
                var responseContent = context.Data as HttpResponseMessage;
                var authToken       = await responseContent.Content.ReadAsStringAsync();
                return(Http.CreateRequest("GET", getAllToursUrl)
                       .WithHeader("Authorization", $"Bearer {authToken}"));
                //.WithCheck(async response =>
                //{
                //    return response.IsSuccessStatusCode ? Response.Ok() : Response.Fail();
                //});
            });

            var influxConfig = InfluxDbSinkConfig.Create("https://westeurope-1.azure.cloud2.influxdata.com", dbName: "*****@*****.**");
            var influxDb     = new InfluxDBSink(influxConfig);

            var scenario = ScenarioBuilder.CreateScenario("Get All Reservations", new[] { loginStep, getAllReservations })
                           .WithWarmUpDuration(warmUp)
                           .WithLoadSimulations(new[]
            {
                Simulation.RampPerSec(10, TimeSpan.FromMinutes(1))
            });

            var nodeStats = NBomberRunner.RegisterScenarios(scenario).Run();
        }
コード例 #2
0
        /// <summary>
        /// Adds the WriteTo.InfluxDB() extension method to <see cref="LoggerConfiguration"/>.
        /// </summary>
        public static LoggerConfiguration InfluxDB(
            this LoggerSinkConfiguration loggerConfiguration,
            InfluxDBSinkOptions sinkOptions,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            if (sinkOptions == null)
            {
                throw new ArgumentNullException(nameof(sinkOptions));
            }

            var defaultOptions = new PeriodicBatchingSinkOptions();

            if (sinkOptions.BatchOptions == null)
            {
                sinkOptions.BatchOptions = defaultOptions; // initialized with default from lib
            }

            if (sinkOptions.BatchOptions.QueueLimit == defaultOptions.QueueLimit)
            {
                // set back to null as don't want to have queue limit if was read null from settings file
                sinkOptions.BatchOptions.QueueLimit = null;
            }

            var influxDbSink = new InfluxDBSink(sinkOptions);
            var batchingSink = new PeriodicBatchingSink(influxDbSink, sinkOptions.BatchOptions);

            return(loggerConfiguration.Sink(batchingSink, restrictedToMinimumLevel));
        }
コード例 #3
0
        public static void Run()
        {
            var step = Step.Create("step", async context =>
            {
                await Task.Delay(TimeSpan.FromSeconds(0.1));
                return(Response.Ok(sizeBytes: 100));
            });

            var scenario = ScenarioBuilder
                           .CreateScenario("simple_scenario", step)
                           .WithoutWarmUp()
                           .WithLoadSimulations(Simulation.KeepConstant(1, TimeSpan.FromMinutes(1)));

            var influxConfig = InfluxDbSinkConfig.Create("http://localhost:8086", dbName: "default");
            var influxDb     = new InfluxDBSink(influxConfig);

            NBomberRunner
            .RegisterScenarios(scenario)
            .WithTestSuite("reporting")
            .WithTestName("influx_test")
            .WithReportingSinks(
                reportingSinks: new[] { influxDb },
                sendStatsInterval: TimeSpan.FromSeconds(10)
                )
            .Run();
        }
コード例 #4
0
        protected async Task WhenConsumingEvents()
        {
            var sink         = new InfluxDBSink(Options, SampleRate);
            var consumeTasks = DiagnosticEvents.Select(async e => await sink.ConsumeAsync(e)).ToList();
            await Task.WhenAll(consumeTasks);

            sink.RecordMeasurements();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default");

            var scenario = BuildScenario();

            NBomberRunner.RegisterScenarios(scenario)
            .SaveStatisticsTo(influxDb)
            .RunInConsole();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var configPath = args[0]; // agent_config.json or coordinator_config.json

            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default");

            NBomberRunner.RegisterScenarios(
                SimpleHttpScenario.Create()
                //MqttReqResponseScenario.Create()
                )
            .WithReportingSinks(new[] { influxDb }, sendStatsInterval: TimeSpan.FromSeconds(20))
            .LoadInfraConfig("infra_config.json")
            .LoadTestConfig(configPath)     // agent_config.json or coordinator_config.json
            .RunInConsole();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "NBomberDb");

            var step = HttpStep.Create("simple step", (context) =>
                                       Http.CreateRequest("GET", "https://nbomber.com")
                                       );

            var scenario = ScenarioBuilder.CreateScenario("test_nbomber", new[] { step })
                           .WithConcurrentCopies(100)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(10))
                           .WithDuration(TimeSpan.FromMinutes(3));

            NBomberRunner.RegisterScenarios(scenario)
            .WithReportingSinks(new[] { influxDb }, TimeSpan.FromSeconds(20))
            .RunInConsole();
        }
コード例 #8
0
        public static void Run()
        {
            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default");

            var step = HttpStep.Create("simple step", (context) =>
                                       Http.CreateRequest("GET", "https://gitter.im")
                                       .WithHeader("Accept", "text/html")
                                       );

            var scenario = ScenarioBuilder.CreateScenario("test_gitter", step)
                           .WithConcurrentCopies(50)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(10))
                           .WithDuration(TimeSpan.FromSeconds(180));

            NBomberRunner.RegisterScenarios(scenario)
            .SaveStatisticsTo(influxDb)
            .RunInConsole();
        }
コード例 #9
0
        public static void Run()
        {
            var influxDb = new InfluxDBSink(url: "http://localhost:8086", dbName: "default");

            var step = HttpStep.Create("simple step", context =>
                                       Http.CreateRequest("GET", "https://nbomber.com")
                                       .WithHeader("Accept", "text/html")
                                       );

            var scenario = ScenarioBuilder.CreateScenario("test_nbomber", new[] { step })
                           .WithConcurrentCopies(50)
                           .WithWarmUpDuration(TimeSpan.FromSeconds(10))
                           .WithDuration(TimeSpan.FromSeconds(180));

            NBomberRunner.RegisterScenarios(scenario)
            .WithReportingSinks(new[] { influxDb }, sendStatsInterval: TimeSpan.FromSeconds(20))
            .RunInConsole();
        }
コード例 #10
0
 public GivenBucketDoesNotExists(DockerFixture dockerFixture)
     : base(dockerFixture)
 {
     _sut = new InfluxDBSink(new InfluxDBSinkOptions()
     {
         ApplicationName = $"Test_{nameof(GivenBucketDoesNotExists)}",
         ConnectionInfo  = new InfluxDBConnectionInfo()
         {
             Uri                     = new Uri("http://127.0.0.1:8086"),
             BucketName              = "logs",
             OrganizationId          = "88e1f5a5ad074d9e", // Organization Id - unique id can be found under Profile > About > Common Ids
             CreateBucketIfNotExists = true,
             //Username = "******",
             //Password = "******",
             AllAccessToken        = "bGfBKhSycNiUOia4k7peib2jHFewkz3o6Hv2uz1xAoUcdnEFRW7cHn03KICySLemA4VPZKvc0CwzSQT8GNl2DA==",
             BucketRetentionPeriod = TimeSpan.FromDays(1)
         },
     });
 }
コード例 #11
0
        public static void Run()
        {
            var userFeed = Feed.CreateRandom(
                "userFeed",
                FeedData.FromJson <User>("./JsonConfig/Configs/user-feed.json")
                );

            var httpFactory = ClientFactory.Create("http_factory",
                                                   initClient: (number, context) => Task.FromResult(new HttpClient {
                BaseAddress = new Uri(_customSettings.BaseUri)
            }));

            var getUser = Step.Create("get_user", httpFactory, userFeed, async context =>
            {
                var userId = context.FeedItem;
                var url    = $"users?id={userId}";

                var response = await context.Client.GetAsync(url, context.CancellationToken);
                var json     = await response.Content.ReadAsStringAsync();

                // parse JSON
                var users = JsonConvert.DeserializeObject <UserResponse[]>(json);

                return(users?.Length == 1
                    ? Response.Ok(users.First()) // we pass user object response to the next step
                    : Response.Fail("not found user"));
            });

            // this 'getPosts' will be executed only if 'getUser' finished OK.
            var getPosts = Step.Create("get_posts", httpFactory, async context =>
            {
                var user = context.GetPreviousStepResponse <UserResponse>();
                var url  = $"posts?userId={user.Id}";

                var response = await context.Client.GetAsync(url, context.CancellationToken);
                var json     = await response.Content.ReadAsStringAsync();

                // parse JSON
                var posts = JsonConvert.DeserializeObject <PostResponse[]>(json);

                return(posts?.Length > 0
                    ? Response.Ok()
                    : Response.Fail());
            });

            var scenario1 = ScenarioBuilder
                            .CreateScenario("rest_api", getUser, getPosts)
                            .WithInit(ScenarioInit);

            // the following scenario will be ignored since it is not included in target scenarios list of config.json
            var scenario2 = ScenarioBuilder
                            .CreateScenario("ignored", getUser, getPosts);

            // settings for worker plugins and reporting sinks are overriden in infra-config.json
            var pingPlugin = new PingPlugin();

            var customPlugin = new CustomPlugin(new CustomPluginSettings
            {
                Message = "Plugin is configured via constructor"
            });

            var influxDbReportingSink = new InfluxDBSink();

            var customReportingSink = new CustomReportingSink(new CustomReportingSinkSettings
            {
                Message = "Reporting sink is configured via constructor"
            });

            NBomberRunner
            .RegisterScenarios(scenario1, scenario2)
            .WithWorkerPlugins(pingPlugin, customPlugin)
            .WithReportingSinks(influxDbReportingSink, customReportingSink)
            .LoadConfig("./JsonConfig/Configs/config.json")
            .LoadInfraConfig("./JsonConfig/Configs/infra-config.json")
            .Run();
        }