{"id":26403,"date":"2024-01-10T05:00:00","date_gmt":"2024-01-10T04:00:00","guid":{"rendered":"https:\/\/sii.pl\/blog\/?p=26403"},"modified":"2025-03-05T11:45:25","modified_gmt":"2025-03-05T10:45:25","slug":"performance-under-control-with-k6-docker-and-integration-with-influxdb-and-grafana","status":"publish","type":"post","link":"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-docker-and-integration-with-influxdb-and-grafana\/","title":{"rendered":"Performance under control with k6 \u2013 Docker and integration with InfluxDB and Grafana"},"content":{"rendered":"\n<p>To fully understand system performance, it is essential not only to conduct tests but also to build observability. Integration of third-party tools becomes crucial in achieving complete visibility and time-based data analysis, allowing for real-time monitoring of applications, identifying potential issues, and taking appropriate actions to enhance performance.<\/p>\n\n\n\n<p>In this article, we will explore how building observability for systems is critical in the context of performance testing and how to effectively integrate k6, Grafana, and InfluxDB to obtain comprehensive and accurate test results. However, we need to grasp the fundamental theory before implementing our integrations.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Testy wydajno\u015bciowe z k6: Docker oraz integracja z InfluxDB i Grafan\u0105 | cz\u0119\u015b\u0107 7\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/fU2G-jkw8Js?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Docker and Docker Compose?<\/strong><\/h2>\n\n\n\n<p>Docker is an open-source platform that enables operating-system-level virtualization. It allows packaging applications and all their dependencies into units called containers. Each container runs in isolation, meaning it can have its libraries, configuration files, and other dependencies independently of other containers on the same host. This makes applications run in containers portable and uniform across different environments, from local developer machines to production servers.<\/p>\n\n\n\n<p>Docker empowers developers and administrators to <strong>create, deliver, and run applications in an automated and repeatable manner<\/strong>. This makes the application deployment process more reliable and faster while eliminating issues related to differences in environment configuration.<\/p>\n\n\n\n<p>On the other hand, Docker Compose is a tool that extends Docker&#8217;s functionality, enabling the management of multiple containers as single applications. It allows defining an entire application environment in a single configuration file, where you can specify all the containers, their dependencies, networks, and other parameters. This makes it easy to start and stop an entire application consisting of multiple containers with a single command.<\/p>\n\n\n\n<p>Docker Compose is particularly useful in developer and testing environments, where multiple services and dependencies are often utilized. It helps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>shorten the setup time,<\/li>\n\n\n\n<li>automate processes,<\/li>\n\n\n\n<li>and avoid issues related to manual management of multiple containers.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Storing metrics in InfluxDB<\/strong><\/h2>\n\n\n\n<p>InfluxDB is a distributed time-series database designed for storing, querying, and analyzing time-based data, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>telemetry data,<\/li>\n\n\n\n<li>event logs,<\/li>\n\n\n\n<li>application metrics,<\/li>\n\n\n\n<li>or measurement data.<\/li>\n<\/ul>\n\n\n\n<p>InfluxDB provides an efficient and scalable solution for storing large amounts of data with a time-changing nature. Due to its specialization in time-based data, it is frequently used in IoT applications, system monitoring, real-time analytics, and <strong>other domains requiring precise collection and analysis of time-based data.<\/strong><\/p>\n\n\n\n<p>InfluxDB is <strong>an ideal tool for storing metrics from performance tests<\/strong> and other applications related to time-based data analysis. Its specialization in time-based data allows for precise collection and archival of performance test results, such as server response times, requests per second, or system load.<\/p>\n\n\n\n<p>InfluxDB <strong>is a popular choice<\/strong> among performance testing and system monitoring teams because it offers efficient and reliable data storage and easy integration with other data analysis and visualization tools. This enables us to build advanced and comprehensive solutions for performance analysis, which is crucial for ensuring the optimal operation of our systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Data visualization with Grafana<\/strong><\/h2>\n\n\n\n<p>Grafana is a popular open-source tool for visualizing and monitoring data from various sources. It is primarily used for creating interactive and visually appealing charts, panels, and dashboards that allow for visual analysis and presentation of data. Grafana collaborates with many databases and monitoring systems, with InfluxDB being one of the most commonly used data sources.<\/p>\n\n\n\n<p>Tool enables integration with InfluxDB, making visualizing time-based data stored in the InfluxDB database easy. This integration allows us to create advanced line charts, bar charts, pie charts, heatmaps, and more based on performance test results and other time-based data. These visualizations help us understand changes in application performance over time, identify trends, and pinpoint potential issues.<\/p>\n\n\n\n<p>Grafana also offers advanced features such as dynamic filters, interactive panel toggling, combining different data sources, and much more. This allows us to tailor the presented data to our needs and generate personalized reports and dashboards that help us effectively monitor and analyze the performance of our applications.<\/p>\n\n\n\n<p>When combined with InfluxDB, Grafana becomes a powerful tool for comprehensive monitoring and visualization of time-based data, particularly valuable for performance testing and time-related data analysis. This enables better understanding and optimization of application performance, which is crucial for ensuring excellent quality and performance of our systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><strong>Workflow summary<\/strong><\/strong><\/h2>\n\n\n\n<p>In summary, we will use Docker in our project to create and configure communication containers. Ultimately, we will create three containers with the following communication pattern:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01-1024x644.png\" alt=\"Communication pattern\" class=\"wp-image-26367\" width=\"617\" height=\"388\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01-1024x644.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01-300x189.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01-768x483.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01-1536x966.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-01.png 1563w\" sizes=\"(max-width: 617px) 100vw, 617px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 1 Communication pattern<\/figcaption><\/figure>\n\n\n\n<p>This is a simple and standard integration, which is a starting point for developing a monitoring system.<\/p>\n\n\n\n<p>Before we move on to creating the docker-compose.yaml file, we first need to build a Docker image responsible for running the test scenarios based on the commands defined in the package.json file. Here is the ready configuration for the Dockerfile:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02.png\"><img decoding=\"async\" width=\"1024\" height=\"531\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02-1024x531.png\" alt=\"Gotowa konfiguracja pliku Dockerfile\" class=\"wp-image-26369\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02-1024x531.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02-300x156.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02-768x398.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02-1536x797.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-02.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 2 Ready configuration for the Dockerfile<\/figcaption><\/figure>\n\n\n\n<p>The above Dockerfile describes the process of building a container image that contains the environment for running k6 tests and installs the required dependencies related to Node.js and npm. Here is its breakdown:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FROM node:latest \u2013 this line specifies the base image on which the container image will be built. In this case, the &#8220;node:latest&#8221; image is used, which includes the Node.js environment, enabling the execution of JavaScript scripts.<\/li>\n\n\n\n<li>USER root \u2013 setting the user to &#8220;root.&#8221; This line is optional and only required if we need administrator privileges to install and modify packages.<\/li>\n\n\n\n<li>WORKDIR \/ \u2013 specifies the working directory inside the container to the root directory (&#8220;\/&#8221;). All subsequent commands will be executed in this directory.<\/li>\n\n\n\n<li>ADD &#8230; \u2013 downloading the k6 archive with the specified version (0.45.0) and unpacking it inside the container.<\/li>\n\n\n\n<li>RUN &#8230; \u2013 executing subsequent commands. Unpack the k6 archive, move the k6 executable to the &#8220;\/usr\/bin&#8221; directory, and install dependencies from the package.json file using &#8220;npm install.&#8221;<\/li>\n\n\n\n<li>ENTRYPOINT [ &#8220;npm&#8221; ] \u2013 specifies the entry point into the container. In this case, npm will be automatically executed when the container is run, allowing the execution of test scripts defined in the package.json files.<\/li>\n<\/ul>\n\n\n\n<p>Let&#8217;s implement and discuss the docker-compose.yaml file in which we will describe the structure of our containers.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03.png\"><img decoding=\"async\" width=\"751\" height=\"1024\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-751x1024.png\" alt=\"Implementation docker-compose.yaml file\" class=\"wp-image-26372\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-751x1024.png 751w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-220x300.png 220w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-768x1048.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-1126x1536.png 1126w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03-1502x2048.png 1502w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-03.png 1808w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 3 Implementation docker-compose.yaml file<\/figcaption><\/figure>\n\n\n\n<p>In the above docker-compose.yaml file structure, three services have been defined, creating a comprehensive environment for performance testing. Each service is responsible for specific tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>InfluxDB \u2013 a time-series database that stores data collected during performance tests. The image version &#8220;influxdb:1.8&#8221; is specified along with its associated parameters. The service is connected to two networks, &#8220;k6&#8221; and &#8220;grafana,&#8221; enabling communication with the other services. Port &#8220;8086&#8221; is exposed to allow access to InfluxDB from other containers. An environment variable &#8220;INFLUXDB_DB&#8221; is defined, specifying the name of the &#8220;k6&#8221; database in InfluxDB.<\/li>\n\n\n\n<li>Grafana \u2013 this service allows visualization and analysis of time-series data stored in InfluxDB. The &#8220;grafana\/grafana:latest&#8221; image is used, and relevant parameters are defined. The service is connected to the &#8220;grafana&#8221; network. Port &#8220;3000&#8221; is exposed, enabling access to the Grafana interface from an external environment. Environment variables are also configured to allow anonymous access to Grafana.<\/li>\n<\/ul>\n\n\n\n<p>Additionally, the docker-compose.The yaml file includes volumes that allow the provision of configuration files and dashboards to the Grafana container. The first volume is for the newly created directory dashboards, where the panels we define will be located and automatically imported by the Grafana container. An example panel we will use <a href=\"https:\/\/github.com\/gpiechnik2\/k6-boilerplate\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >is available in our repository<\/a>, to which we warmly invite you.<\/p>\n\n\n\n<p>Let&#8217;s discuss the next two configurations defined in the docker-compose.yaml file for the Grafana services.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The grafana-dashboard.yaml file \u2013 defines a dashboard provider for Grafana. This configuration specifies that new panels will be associated with the main folder and provided from files in the \/var\/lib\/grafana\/dashboards directory. This approach enables the automatic addition and management of panels in the Grafana system using configuration files.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04.png\"><img decoding=\"async\" width=\"1024\" height=\"722\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04-1024x722.png\" alt=\"grafana-dashboard.yaml files\" class=\"wp-image-26374\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04-1024x722.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04-300x211.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04-768x541.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-04.png 1084w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 4 Grafana-dashboard.yaml file<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The grafana-datasource.yaml file \u2013 contains the data source configuration for Grafana, pointing to the InfluxDB database named &#8220;k6.&#8221; With this setting, Grafana will use this data source as the default, enabling automatic utilization in panels that do not have a specific data source selected. The data source is accessible through a proxy at the address &#8220;<a href=\"http:\/\/influxdb:8086\/\" rel=\"nofollow\" >http:\/\/influxdb:8086<\/a>&#8220;.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-05.png\"><img decoding=\"async\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-05.png\" alt=\"grafana-datasource.yaml file\" class=\"wp-image-26376\" width=\"840\" height=\"732\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-05.png 876w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-05-300x262.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-05-768x670.png 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 5 Grafana-datasource.yaml file<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>k6 \u2013 this service is responsible for executing performance tests. The k6-with-npm image we created a moment ago is defined, and the &#8220;k6&#8221; network in which the service operates is specified. Port &#8220;6565&#8221; is exposed, allowing access to the k6 interface. An environment variable, &#8220;K6_OUT,&#8221; is configured, pointing to the InfluxDB database and its endpoint &#8220;<a href=\"http:\/\/influxdb:8086\/k6\" rel=\"nofollow\" >http:\/\/influxdb:8086\/k6<\/a>&#8220;, where test results will be stored. Additionally, through a volume, test scripts and their helper directories are accessible on the local system within the k6 container.<\/li>\n<\/ul>\n\n\n\n<p>A detailed explanation of the complete functioning of docker-compose.yaml and Docker itself would require a separate and detailed series of articles. This article<strong> focused on providing a general overview of these concepts<\/strong>. However, we plan to create a separate series to delve into Docker from the basics.<\/p>\n\n\n\n<p>In summary, the entire environment in docker-compose.yaml is configured in a way that enables automatic operation and communication between individual services. InfluxDB collects data from performance tests, which can then be visualized and analyzed in the Grafana interface, while the testing process itself is handled by k6. <strong>This makes the environment easy to deploy and scale, making it a good starting point for monitoring and analyzing application performance.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Preparing before running the scenario<\/strong><\/h2>\n\n\n\n<p>To run the environment locally correctly, ensure you have <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/docs.docker.com\/doc\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >Docker<\/a> and <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/docs.docker.com\/compose\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >Docker Compose<\/a> installed. Then, navigate to the project&#8217;s main directory and execute the following command to build a Docker image based on the Dockerfile we created earlier.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-06.png\"><img decoding=\"async\" width=\"808\" height=\"428\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-06.png\" alt=\"Building a Docker image\" class=\"wp-image-26379\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-06.png 808w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-06-300x159.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-06-768x407.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 6 Building a Docker image<\/figcaption><\/figure>\n\n\n\n<p>We are ready to create and run the InfluxDB and Grafana containers.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-07.png\"><img decoding=\"async\" width=\"946\" height=\"422\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-07.png\" alt=\"creating and running the InfluxDB and Grafana containers\" class=\"wp-image-26383\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-07.png 946w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-07-300x134.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-07-768x343.png 768w\" sizes=\"(max-width: 946px) 100vw, 946px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 7 Creating and running the InfluxDB and Grafana containers<\/figcaption><\/figure>\n\n\n\n<p>By defining access to the Grafana interface in the docker-compose.yaml file, we can now access the Grafana dashboard using the address 127.0.0.1:3000 within the available environment.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1.png\"><img decoding=\"async\" width=\"1024\" height=\"545\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-1024x545.png\" alt=\"Grafana dashboard\" class=\"wp-image-26385\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-1024x545.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-300x160.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-768x409.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-1536x818.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-08-1-2048x1090.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 8 Grafana dashboard<\/figcaption><\/figure>\n\n\n\n<p>However, since we haven&#8217;t started the k6 container and thus the test scenario, <strong>no results are visible yet<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The final steps<\/strong><\/h2>\n\n\n\n<p>Before running our scenario, let&#8217;s make minor changes to the assert helper function. Let&#8217;s modify it to accept more arguments, including the crucial errors object.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09.png\"><img decoding=\"async\" width=\"1024\" height=\"637\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09-1024x637.png\" alt=\"Changes to the assert helper function\" class=\"wp-image-26388\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09-1024x637.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09-300x187.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09-768x478.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09-1536x956.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-09.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 9 Changes to the assert helper function<\/figcaption><\/figure>\n\n\n\n<p>The above change is because <strong>k6 doesn&#8217;t handle logging application errors precisely enough<\/strong>, making it difficult to analyze and draw conclusions. Therefore, we expanded our function to pass more detailed data. These details are aggregated in the errors object, defined in each test scenario right after the import section. We introduce this logic in the scenario responsible for searching for training courses. You can find the complete changes <a href=\"https:\/\/github.com\/gpiechnik2\/k6-boilerplate\" target=\"_blank\" aria-label=\"in our repository (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\" rel=\"nofollow\" >in our repository<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10.png\"><img decoding=\"async\" width=\"1024\" height=\"743\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10-1024x743.png\" alt=\"Introducing logic in the scenario\" class=\"wp-image-26392\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10-1024x743.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10-300x218.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10-768x557.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10-1536x1115.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-10.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 10 Introducing logic in the scenario<\/figcaption><\/figure>\n\n\n\n<p>After making the necessary changes, let&#8217;s execute the following command to remove existing k6 containers and then run the defined command from the package.json file:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11.png\"><img decoding=\"async\" width=\"1024\" height=\"364\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11-1024x364.png\" alt=\"Running the defined command from the package.json file\" class=\"wp-image-26394\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11-1024x364.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11-300x107.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11-768x273.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-11.png 1186w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 11 Running the defined command from the package.json file<\/figcaption><\/figure>\n\n\n\n<p>This way, a single run of the test for searching an article on the website will be executed. Let&#8217;s move to Grafana to check if the results are displayed correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12.png\"><img decoding=\"async\" width=\"1024\" height=\"545\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-1024x545.png\" alt=\"Verification of the correctness of displays\" class=\"wp-image-26396\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-1024x545.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-300x160.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-768x409.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-1536x818.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-12-2048x1090.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 12 Verification of the correctness of displays<\/figcaption><\/figure>\n\n\n\n<p>Additionally, if an error is detected, it will be displayed in a table at the bottom of the panel, divided into two sections. The first section groups and summarizes the detected errors, while the second section provides a more detailed view of these errors.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13.png\"><img decoding=\"async\" width=\"1024\" height=\"545\" src=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-1024x545.png\" alt=\"Error detection\" class=\"wp-image-26398\" srcset=\"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-1024x545.png 1024w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-300x160.png 300w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-768x409.png 768w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-1536x818.png 1536w, https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/p7-attachment-13-2048x1090.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Fig. 13 Error detection<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>In this article, we delved into integrating the k6 tool with Grafana and InfluxDB, <strong>opening up new possibilities for monitoring and visualizing performance test results<\/strong>. Through Grafana, we created interactive and aesthetically pleasing charts based on data stored in InfluxDB, making it easier to analyze test outcomes.<\/p>\n\n\n\n<p>Furthermore, we learned that Docker is an excellent tool for container isolation and deployment, enabling easy installation and execution of necessary tools. Integrating these technologies allowed us to enhance the observability of our performance tests, a crucial aspect in building reliable and efficient applications.<\/p>\n\n\n\n<p>***<\/p>\n\n\n\n<p>If you haven\u2019t had a chance to read the articles in the series yet, you can find them here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-introduction\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Performance under control with k6 \u2013 introduction<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-recording-parametrization-and-running-the-first-test-scenario\/\" target=\"_blank\" rel=\"noreferrer noopener\">Performance under control with k6 \u2013 recording, parametrization, and running the first test scenario<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-metrics-quality-thresholds-tagging\/\" target=\"_blank\" rel=\"noreferrer noopener\">Performance under control with k6 \u2013 metrics, quality thresholds, tagging<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-additional-configurations-types-of-scenario-models-and-executors\/\" target=\"_blank\" rel=\"noreferrer noopener\">Performance under control with k6 \u2013 additional configurations types of scenario models and executors<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-framework-initialization\/\" target=\"_blank\" rel=\"noreferrer noopener\">Performance under control with k6 \u2013 framework initialization<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-best-practices-test-suite-creation-and-configuration\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Performance under control with k6 \u2013 best practices, test suite creation, and configuration<\/a><\/li>\n<\/ul>\n\n\n\n<p>In addition, I encourage you to&nbsp;<a href=\"https:\/\/github.com\/gpiechnik2\/k6-boilerplate\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >check out the project\u2019s Repository<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;26403&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;2&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;11&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;5\\\/5 ( votes: 2)&quot;,&quot;size&quot;:&quot;18&quot;,&quot;title&quot;:&quot;Performance under control with k6 \u2013 Docker and integration with InfluxDB and Grafana&quot;,&quot;width&quot;:&quot;139.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} ( {votes}: {count})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 139.5px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 11px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 18px; height: 18px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 14.4px;\">\n            5\/5 ( votes: 2)    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>To fully understand system performance, it is essential not only to conduct tests but also to build observability. Integration of &hellip; <a class=\"continued-btn\" href=\"https:\/\/sii.pl\/blog\/en\/performance-under-control-with-k6-docker-and-integration-with-influxdb-and-grafana\/\">Continued<\/a><\/p>\n","protected":false},"author":517,"featured_media":26402,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","inline_featured_image":false,"footnotes":""},"categories":[1321],"tags":[2128,1794,1790,1791,1639,1590],"class_list":["post-26403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-testing","tag-grafana-en","tag-testy-wydajnosci-en","tag-k6-en","tag-tosca-en","tag-przeglad-narzedzi-en","tag-tools"],"acf":[],"aioseo_notices":[],"republish_history":[],"featured_media_url":"https:\/\/sii.pl\/blog\/wp-content\/uploads\/2023\/12\/Wydajnosc-pod-kontrola-\u2013-co-sklania-mnie-do-wyboru-k6.jpg","category_names":["Testing"],"_links":{"self":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/26403"}],"collection":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/users\/517"}],"replies":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/comments?post=26403"}],"version-history":[{"count":3,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/26403\/revisions"}],"predecessor-version":[{"id":26523,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/posts\/26403\/revisions\/26523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media\/26402"}],"wp:attachment":[{"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/media?parent=26403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/categories?post=26403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sii.pl\/blog\/en\/wp-json\/wp\/v2\/tags?post=26403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}