<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Microservices Basics Training – 2. Mini-Monolith</title><link>/docs/02/</link><description>Recent content in 2. Mini-Monolith on Microservices Basics Training</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="/docs/02/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: 2.1 Getting Started</title><link>/docs/02/part/21/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/21/</guid><description>
&lt;h2 id="source-code">Source Code&lt;/h2>
&lt;p>The source-code used for this lab is in the folder &lt;code>/code/monolith&lt;/code>&lt;/p>
&lt;ul>
&lt;li>Online Repository Link: &lt;a href="https://github.com/acend/microservices-lab/tree/main/code/monolith" target="_blank" rel="noopener">https://github.com/acend/microservices-lab/tree/main/code/monolith&lt;/a>
.&lt;/li>
&lt;/ul>
&lt;h3 id="task-211---getting-your-workspace-ready">Task 2.1.1 - Getting your workspace ready&lt;/h3>
&lt;p>We will only inspect files in this lab.&lt;/p>
&lt;ul>
&lt;li>Open your IDE or favorite tool and switch to the referenced source folder.&lt;/li>
&lt;/ul></description></item><item><title>Docs: 2.2 Docker Environment</title><link>/docs/02/part/22/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/22/</guid><description>
&lt;h2 id="docker-compose">Docker Compose&lt;/h2>
&lt;p>Our setup for the application is quite simple. It consists of the Quarkus service &lt;code>application&lt;/code> and its database
&lt;code>application-db&lt;/code>. Further we have three more containers setup. We use &lt;code>jaeger&lt;/code> as our tracing, &lt;code>prometheus&lt;/code> to scrape the
metrics and &lt;code>grafana&lt;/code> to visualize them in dashboards.&lt;/p>
&lt;p>All configuration for the docker environment is located in the folder &lt;code>docker&lt;/code>. The folder &lt;code>docker/config&lt;/code> is used to
configure &lt;code>prometheus&lt;/code> and &lt;code>grafana&lt;/code>.&lt;/p>
&lt;h3 id="host-mapped-container-ports">Host mapped container ports&lt;/h3>
&lt;p>Starting up the docker-compose will create a bridge network. We mapped most container ports to the docker host.
This provides easy access for debugging like attaching the database to your IDE.&lt;/p>
&lt;p>However, the most important ports of the containers are:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Container&lt;/th>
&lt;th>Internal Port&lt;/th>
&lt;th>Host Port&lt;/th>
&lt;th>Purpose&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>application&lt;/code>&lt;/td>
&lt;td>8080&lt;/td>
&lt;td>8080&lt;/td>
&lt;td>Main application port&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>application-db&lt;/code>&lt;/td>
&lt;td>5432&lt;/td>
&lt;td>5432&lt;/td>
&lt;td>Database port&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>jaeger&lt;/code>&lt;/td>
&lt;td>16686&lt;/td>
&lt;td>16686&lt;/td>
&lt;td>Jaeger UI&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>jaeger&lt;/code>&lt;/td>
&lt;td>14268&lt;/td>
&lt;td>14268&lt;/td>
&lt;td>Port used to send traces from our Quarkus applications to Jaeger&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>prometheus&lt;/code>&lt;/td>
&lt;td>9090&lt;/td>
&lt;td>9090&lt;/td>
&lt;td>Prometheus service port (includes UI)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>grafana&lt;/code>&lt;/td>
&lt;td>3000&lt;/td>
&lt;td>3000&lt;/td>
&lt;td>Grafana UI&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Have a look at &lt;a href="https://www.jaegertracing.io/docs/1.24/getting-started/" target="_blank" rel="noopener">Jaeger Port Details&lt;/a>
if you need more information
about the available Jaeger ports.&lt;/p>
&lt;h3 id="task-221---inspecting-the-docker-environment">Task 2.2.1 - Inspecting the docker environment&lt;/h3>
&lt;p>Have a look at the &lt;code>/code/monolith/docker&lt;/code> folder and get familiar with the docker environment specified in &lt;code>docker-compose.yaml&lt;/code>&lt;/p></description></item><item><title>Docs: 2.3 Application Structure</title><link>/docs/02/part/23/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/23/</guid><description>
&lt;h2 id="code-structure">Code Structure&lt;/h2>
&lt;p>The application in this lab is structured as follows:&lt;/p>
&lt;ul>
&lt;li>&lt;code>monolith-application&lt;/code>: Base directory for code or artifacts belonging to the &lt;code>application&lt;/code> container&lt;/li>
&lt;li>&lt;code>monolith-application/src/main/docker&lt;/code>: Dockerfiles to build application and container&lt;/li>
&lt;li>&lt;code>monolith-application/src/main/java/ch/puzzle/mm/monolith/&lt;/code>: Location where most of the java application code resides&lt;/li>
&lt;li>&lt;code>monolith-application/src/main/resources/db&lt;/code>: contains the database migration scripts&lt;/li>
&lt;/ul>
&lt;p>The java code is structured by domains and the sub folders &lt;code>boundary&lt;/code>, &lt;code>control&lt;/code> and &lt;code>entity&lt;/code>. Beside domains there are
also helpers. For example the package &lt;code>monkey&lt;/code> which contains a basic ChaosMonkey to inject errors.&lt;/p>
&lt;h3 id="domains">Domains&lt;/h3>
&lt;p>In the application we have the following domains:&lt;/p>
&lt;ul>
&lt;li>&lt;code>article&lt;/code>: Static article management&lt;/li>
&lt;li>&lt;code>order&lt;/code>: Handles the management of the order and initiates the stock management&lt;/li>
&lt;li>&lt;code>stock&lt;/code>: Represents a stock management and handles the amount of items in stock&lt;/li>
&lt;/ul>
&lt;p>The most important classes in the application are:&lt;/p>
&lt;ul>
&lt;li>&lt;code>order/boundary/ShopOrderResource.java&lt;/code>: Provides the RESTful API endpoint for creating a new order&lt;/li>
&lt;li>&lt;code>order/control/ShopOrderService.java&lt;/code>: Handles the effective creation of the order and triggers the stock management&lt;/li>
&lt;li>&lt;code>stock/control/ArticleStockService.java&lt;/code>: Handles the effective management of the items in stock&lt;/li>
&lt;/ul>
&lt;h3 id="task-231---inspecting-application-structure">Task 2.3.1 - Inspecting application structure&lt;/h3>
&lt;ul>
&lt;li>Have a look at the &lt;code>/code/monolith&lt;/code> folder and get familiar with the application structure.&lt;/li>
&lt;/ul></description></item><item><title>Docs: 2.4 Using the Lab</title><link>/docs/02/part/24/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/24/</guid><description>
&lt;h2 id="starting-the-lab">Starting the Lab&lt;/h2>
&lt;p>Open a shell and change your directory to the &lt;code>/code/monolith/docker&lt;/code> folder.&lt;/p>
&lt;p>Start the microservices with&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>$ docker-compose up -d
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating network &lt;span style="color:#4e9a06">&amp;#34;docker_monolith&amp;#34;&lt;/span> with driver &lt;span style="color:#4e9a06">&amp;#34;bridge&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-jaeger ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-grafana ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-alertmanager ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-application-db ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-prometheus ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Creating monolith-application ... &lt;span style="color:#204a87;font-weight:bold">done&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Now your environment is up and running.&lt;/p>
&lt;h2 id="using-the-lab">Using the Lab&lt;/h2>
&lt;h3 id="available-endpoints">Available Endpoints&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Endpoint&lt;/th>
&lt;th>Container&lt;/th>
&lt;th>Purpose&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;a href="http://localhost:8080/shop-orders" target="_blank" rel="noopener">http://localhost:8080/shop-orders&lt;/a>
&lt;/td>
&lt;td>application&lt;/td>
&lt;td>Return and create new orders&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="http://localhost:8080/article-stocks" target="_blank" rel="noopener">http://localhost:8080/article-stocks&lt;/a>
&lt;/td>
&lt;td>application&lt;/td>
&lt;td>List article stock count&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;a href="http://localhost:8080/chaos-monkey" target="_blank" rel="noopener">http://localhost:8080/chaos-monkey&lt;/a>
&lt;/td>
&lt;td>application&lt;/td>
&lt;td>Lets you add a ChaosMonkey&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="sample-requests">Sample Requests&lt;/h3>
&lt;p>In the folder &lt;code>requests&lt;/code> within the monolith lab folder there is an IntelliJ IDEA compatible
HTTP Request file named &lt;code>api.http&lt;/code>. You may run the requests directly from this file or build your own requests.&lt;/p>
&lt;p>Get the article stock information&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl --request GET --url http://localhost:8080/article-stocks
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Get order information&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl --request GET --url http://localhost:8080/shop-orders
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Create new order&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>curl --request POST \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --url http://localhost:8080/shop-orders \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --header &amp;#39;Content-Type: application/json&amp;#39; \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --data &amp;#39;{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;articleOrders&amp;#34; : [
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;articleId&amp;#34; : 1,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;amount&amp;#34; : 1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}&amp;#39;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="task-241---testing-scenario">Task 2.4.1 - Testing scenario&lt;/h3>
&lt;p>Run the following queries:&lt;/p>
&lt;ul>
&lt;li>Check the article-stock count&lt;/li>
&lt;li>Create an order for one item of article &lt;code>1&lt;/code>&lt;/li>
&lt;li>Check the orders and article-stock again&lt;/li>
&lt;/ul>
&lt;p>Answer the questions:&lt;/p>
&lt;ul>
&lt;li>Is the article-stock count correct?&lt;/li>
&lt;li>What happens if you are running out of stock?&lt;/li>
&lt;/ul>
&lt;h3 id="chaosmonkey">ChaosMonkey&lt;/h3>
&lt;p>There is a basic implementation of a ChaosMonkey. It will let you inject errors to methods annotated with &lt;code>@ChaosMonkey&lt;/code>.
You may configure the ChaosMonkey using the provided RESTful API &lt;code>/chaos-monkey&lt;/code>.&lt;/p>
&lt;p>The following error types are available:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Error Type&lt;/th>
&lt;th>Executed&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>RateLimit&lt;/td>
&lt;td>Before method&lt;/td>
&lt;td>Rate limit in calls/sec. Default: &lt;code>Long.MAX_VALUE&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Latency&lt;/td>
&lt;td>After method&lt;/td>
&lt;td>Issues a Thread.sleep() in ms. Default: 0&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ErrorRate&lt;/td>
&lt;td>After method&lt;/td>
&lt;td>Lets you specify a percentage of Errors thrown (0 to 1). Default: 0&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Exception&lt;/td>
&lt;td>After method&lt;/td>
&lt;td>Always triggers an exception if enabled. Default: &lt;code>false&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Sample request for configuring the ChaosMonkey which will throw an exception:&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>curl --request POST \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --url http://127.0.0.1:8080/chaos-monkey \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --header &amp;#39;Content-Type: application/json&amp;#39; \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --data &amp;#39;[
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;clazzName&amp;#34;: &amp;#34;ArticleStockService&amp;#34;,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;methodName&amp;#34;: &amp;#34;orderArticles&amp;#34;,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;enabled&amp;#34;: true,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;errorRate&amp;#34;: 0.0,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;latencyMs&amp;#34;: 0,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;permitsPerSec&amp;#34;: 9.223372036854776E18,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;rateLimiterType&amp;#34;: &amp;#34;BLOCK&amp;#34;,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;throwException&amp;#34;: true
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>]&amp;#39;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="task-242---injecting-an-error">Task 2.4.2 - Injecting an error&lt;/h3>
&lt;p>Enable a ChaosMonkey for the method &lt;code>orderArticles&lt;/code> in the &lt;code>ArticleStockService&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>curl --request POST \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --url http://127.0.0.1:8080/chaos-monkey \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --header &amp;#39;Content-Type: application/json&amp;#39; \
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> --data &amp;#39;[
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;clazzName&amp;#34;: &amp;#34;ArticleStockService&amp;#34;,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;methodName&amp;#34;: &amp;#34;orderArticles&amp;#34;,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;enabled&amp;#34;: true,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &amp;#34;throwException&amp;#34;: true
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>]&amp;#39;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This will throw an &lt;code>InternalServerErrorException&lt;/code> after execution of the method &lt;code>orderArticles&lt;/code>.&lt;/p>
&lt;ul>
&lt;li>Ask yourself what to expect if an exception is thrown?&lt;/li>
&lt;/ul>
&lt;p>Issue the request from the Task 2.4.1.&lt;/p>
&lt;ul>
&lt;li>What did you observe? Is there any difference?&lt;/li>
&lt;li>Is the data still consistent?&lt;/li>
&lt;li>What&amp;rsquo;s the role of a transaction in this case?&lt;/li>
&lt;/ul>
&lt;details >
&lt;summary>Task Hint&lt;/summary>
&lt;p>Since the application throws an &lt;code>InternalServerErrorException&lt;/code> the order is not created and the stock count remains the
same.&lt;/p>
&lt;p>This is due to the fact that the code runs in a single transaction. Throwing a &lt;code>RuntimeException&lt;/code> from an active
transaction triggers a rollback of the transaction.&lt;/p>
&lt;/details></description></item><item><title>Docs: 2.5 Metrics (optional)</title><link>/docs/02/part/25/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/25/</guid><description>
&lt;div class="alert alert-optional" role="alert">
&lt;h4 class="alert-heading">Optional Section&lt;/h4>
&lt;p>The following content is optional. If you have time, feel free to proceed.&lt;/p>
&lt;/div>
&lt;h2 id="metrics-with-prometheus-and-grafana">Metrics with Prometheus and Grafana&lt;/h2>
&lt;p>The involved components for our metrics to be working are:&lt;/p>
&lt;ul>
&lt;li>MicroProfile Metrics: Expose the application metrics as a RESTful Endpoint&lt;/li>
&lt;li>Prometheus: Scrape the exposed metrics periodically&lt;/li>
&lt;li>Grafana: Visualize the scraped metrics&lt;/li>
&lt;/ul>
&lt;h3 id="dependencies">Dependencies&lt;/h3>
&lt;p>Our application includes the following dependency in the &lt;code>pom.xml&lt;/code>.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>GroupId&lt;/th>
&lt;th>ArtifactId&lt;/th>
&lt;th>Description&lt;/th>
&lt;th>Detailed information&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>io.quarkus&lt;/code>&lt;/td>
&lt;td>&lt;code>quarkus-smallrye-metrics&lt;/code>&lt;/td>
&lt;td>Exposes various metrics and statistics about the application&lt;/td>
&lt;td>&lt;a href="https://quarkus.io/guides/microprofile-metrics" target="_blank" rel="noopener">MicroProfile Metrics&lt;/a>
&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Including this dependency is enough for our application to expose the metrics at &lt;code>/metrics&lt;/code>&lt;/p>
&lt;h3 id="metric-details">Metric Details&lt;/h3>
&lt;p>The exposed metrics are using the &lt;a href="https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md" target="_blank" rel="noopener">OpenMetrics Format&lt;/a>
format. Metrics can be put in three different scopes.&lt;/p>
&lt;div class="alert alert-primary" role="alert">
&lt;h4 class="alert-heading">Scopes&lt;/h4>
&lt;ul>
&lt;li>&lt;strong>base&lt;/strong>: metrics that all MicroProfile vendors have to provide. e.g. JVM metrics&lt;/li>
&lt;li>&lt;strong>vendor&lt;/strong>: vendor specific metrics&lt;/li>
&lt;li>&lt;strong>application&lt;/strong>: application-specific metrics&lt;/li>
&lt;/ul>
&lt;p>Source: &lt;a href="https://github.com/eclipse/microprofile-metrics/blob/master/spec/src/main/asciidoc/architecture.adoc" target="_blank" rel="noopener">github.com/eclipse/microprofile-metrics&lt;/a>
&lt;/p>
&lt;p>More Details: &lt;a href="https://download.eclipse.org/microprofile/microprofile-metrics-2.3/microprofile-metrics-spec-2.3.html#scopes" target="_blank" rel="noopener">MicroProfile Metrics - Scope&lt;/a>
&lt;/p>
&lt;/div>
&lt;p>We will only generate metrics for the scope application.&lt;/p>
&lt;p>There are various type of metrics available. The most used types are:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Counters&lt;/strong>: Counters are a metric that is used to keep an incremental or a decremental count.&lt;/li>
&lt;li>&lt;strong>Gauges&lt;/strong>: represent metrics that are sampled to obtain their value.&lt;/li>
&lt;li>&lt;strong>Meters&lt;/strong>: Meters are used to track throughput.&lt;/li>
&lt;li>&lt;strong>Timers&lt;/strong>: Timers are used to aggregate timing duration, in nanoseconds, and provide duration and throughput statistics.&lt;/li>
&lt;/ul>
&lt;p>MicroProfile Metrics provides these types as annotations &lt;code>@Counted&lt;/code>, &lt;code>@Timed&lt;/code>, &lt;code>@Metered&lt;/code> and &lt;code>@Gauge&lt;/code>.&lt;/p>
&lt;h3 id="task-251---inspecting-metrics">Task 2.5.1 - Inspecting metrics&lt;/h3>
&lt;p>Start the environment (if not already running) and point your browser to &lt;a href="http://localhost:8080/metrics" target="_blank" rel="noopener">http://localhost:8080/metrics&lt;/a>
&lt;/p>
&lt;ul>
&lt;li>What do you get?&lt;/li>
&lt;li>Can you identify the different scopes?&lt;/li>
&lt;li>Can you locate some application specific metrics?&lt;/li>
&lt;/ul>
&lt;details >
&lt;summary>Task Hint&lt;/summary>
&lt;p>You will get all metrics in the OpenMetrics TEXT Format. Each metric is on a new line.&lt;/p>
&lt;p>The different scopes can be seen by having a look at the first part of a metric (e.g. &lt;code>vendor_&lt;/code>).&lt;/p>
&lt;/details>
&lt;h2 id="defining-metrics-from-code">Defining metrics from code&lt;/h2>
&lt;p>The following snipped is part of the RESTful API endpoint &lt;code>ShopOrderResource&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-java" data-lang="java">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#5c35cc;font-weight:bold">@POST&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#5c35cc;font-weight:bold">@Transactional&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#5c35cc;font-weight:bold">@Counted&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">name&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;monolith_order_create_request&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">absolute&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">true&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">description&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;number of orders requested&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">tags&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;application=monolith&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;resource=ShopOrderResource&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">})&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#5c35cc;font-weight:bold">@Timed&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">name&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;monolith_order_create_timer&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">absolute&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">true&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">description&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;timer for processing a order creation&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">tags&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;application=monolith&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;resource=ShopOrderResource&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">})&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">public&lt;/span> &lt;span style="color:#000">Response&lt;/span> &lt;span style="color:#000">createShopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">ShopOrderDTO&lt;/span> &lt;span style="color:#000">shopOrderDTO&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">ShopOrder&lt;/span> &lt;span style="color:#000">shopOrder&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#000">shopOrderService&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">.&lt;/span>&lt;span style="color:#c4a000">createOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">shopOrderDTO&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">);&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">registerSuccessfulOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">();&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#000">Response&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">.&lt;/span>&lt;span style="color:#c4a000">ok&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">shopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">).&lt;/span>&lt;span style="color:#c4a000">build&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">();&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;a href="https://raw.githubusercontent.com/acend/microservices-lab/main/solution/monolith/monolith-application/src/main/java/ch/puzzle/mm/monolith/order/boundary/ShopOrderResource.java" target="_blank" rel="noopener">full source ShopOrderResource.java&lt;/a>
&lt;/p>
&lt;p>This code defines the following metrics:&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>application_monolith_order_create_request_total{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 28.0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_rate_per_second{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.21598823940031425
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_one_min_rate_per_second{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.3083022515809183
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_five_min_rate_per_second{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.08583728986138126
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_fifteen_min_rate_per_second{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.030253491344307742
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_min_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.004008576
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_max_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.194742506
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_mean_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.020320811804737986
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_stddev_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 0.044306979654618196
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds_count{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;} 28.0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.5&amp;#34;} 0.008546583
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.75&amp;#34;} 0.01223613
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.95&amp;#34;} 0.190428873
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.98&amp;#34;} 0.194742506
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.99&amp;#34;} 0.194742506
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>application_monolith_order_create_timer_seconds{application=&amp;#34;monolith&amp;#34;,resource=&amp;#34;ShopOrderResource&amp;#34;,quantile=&amp;#34;0.999&amp;#34;} 0.194742506
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="task-252---interpret-metrics">Task 2.5.2 - Interpret metrics&lt;/h3>
&lt;p>Try to interpret the metrics from the listing above&lt;/p>
&lt;ul>
&lt;li>How many orders have been requested?&lt;/li>
&lt;li>How long does the creation of an order take?&lt;/li>
&lt;li>Were the requests made recently or some time ago?&lt;/li>
&lt;li>Were there peaks or were the requests evenly distributed over time?&lt;/li>
&lt;/ul>
&lt;details >
&lt;summary>Task Hint&lt;/summary>
&lt;ul>
&lt;li>A total of 28 orders created&lt;/li>
&lt;li>The count on &lt;code>rate_per_second&lt;/code>, &lt;code>one_min_rate_per_second&lt;/code> are higher than &lt;code>fifteen_min_rate_per_second&lt;/code>
which indicates that most requests are seconds/minutes ago.&lt;/li>
&lt;li>There seem to be peaks as the rates for second, minute, five and fifteen are not evenly distributed.&lt;/li>
&lt;/ul>
&lt;p>The graph may look like this&lt;/p>
&lt;p>&lt;img src="../../dashboard.png" alt="Dashboard">&lt;/p>
&lt;/details>
&lt;h3 id="task-253---inspect-grafana-dashboards">Task 2.5.3 - Inspect grafana dashboards&lt;/h3>
&lt;p>Head over to the Grafana UI at &lt;a href="http://localhost:3001" target="_blank" rel="noopener">http://localhost:3001&lt;/a>
. Login with &lt;code>admin/admin&lt;/code> and inspect the two available dashboards.&lt;/p>
&lt;ul>
&lt;li>SmallRye MicroProfile Metrics: Generated Dashboard containing base and vendor metrics.&lt;/li>
&lt;li>Monolith Dashboard: Custom Dashboard containing some basic metrics from the application.&lt;/li>
&lt;/ul>
&lt;p>Try to change an existing visualization&lt;/p>
&lt;ul>
&lt;li>Open the Monolith Dashboard&lt;/li>
&lt;li>Edit &amp;ldquo;Order Create Timer seconds&amp;rdquo; by clicking the title and selecting edit
&lt;ul>
&lt;li>This graph contains multiple quantiles in the same graph. display only the 0.75 quantile.&lt;/li>
&lt;li>Apply a filter to the metric by adding &lt;code>{quantile=&amp;quot;0.75&amp;quot;}&lt;/code> to the metrics query. This applies a filter to a tag named quantile with value &lt;code>0.75&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>The modified query is using the Prometheus Query Language (PromQL). Check the &lt;a href="https://prometheus.io/docs/prometheus/latest/querying/basics/" target="_blank" rel="noopener">Querying Prometheus&lt;/a>
page for more details.&lt;/p>
&lt;details >
&lt;summary>Task Hint&lt;/summary>
&lt;p>&lt;img src="../../edit-panel.png" alt="Dashboard">&lt;/p>
&lt;/details>
&lt;h2 id="prometheus-scraping">Prometheus scraping&lt;/h2>
&lt;p>We know how our application exposes metrics. We have also seen dashboards with simple visualizations.
Now have a look at the Prometheus configuration &lt;code>docker/config/prometheus/prometheus.yaml&lt;/code> to see how the
scraping of these metrics is configured.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span># my global config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>global:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> scrape_interval: 15s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> evaluation_interval: 15s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span># omitted
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>scrape_configs:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - job_name: &amp;#39;prometheus&amp;#39;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> static_configs:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - targets: [&amp;#39;localhost:9090&amp;#39;]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - job_name: &amp;#39;application&amp;#39;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> static_configs:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - targets: [&amp;#39;application:8080&amp;#39;]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;a href="https://raw.githubusercontent.com/acend/microservices-lab/main/solution/monolith/docker/config/prometheus/prometheus.yaml" target="_blank" rel="noopener">full source prometheus.yaml&lt;/a>
&lt;/p>
&lt;p>This defines that Prometheus scrapes our &lt;code>application&lt;/code> at port &lt;code>8080&lt;/code>. Note that the &lt;code>metrics_path&lt;/code> is &lt;code>/metrics&lt;/code> per
default. Prometheus will therefore query &lt;code>http://application:8080/metrics&lt;/code> every 15 seconds to get new metrics.&lt;/p>
&lt;p>For more information about the Prometheus configuration head over to the Prometheus &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#configuration" target="_blank" rel="noopener">configuration&lt;/a>
site.&lt;/p></description></item><item><title>Docs: 2.6 Application Tracing (optional)</title><link>/docs/02/part/26/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/02/part/26/</guid><description>
&lt;div class="alert alert-optional" role="alert">
&lt;h4 class="alert-heading">Optional Section&lt;/h4>
&lt;p>The following content is optional. If you have time, feel free to proceed.&lt;/p>
&lt;/div>
&lt;h2 id="opentracing-with-jaeger-tracing">OpenTracing with Jaeger Tracing&lt;/h2>
&lt;p>We use OpenTracing for the distributed tracing. Our tracing backend is Jaeger.&lt;/p>
&lt;h3 id="dependencies">Dependencies&lt;/h3>
&lt;p>Our application includes the following dependencies in the &lt;code>pom.xml&lt;/code>.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>GroupId&lt;/th>
&lt;th>ArtifactId&lt;/th>
&lt;th>Description&lt;/th>
&lt;th>Detailed information&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>io.quarkus&lt;/code>&lt;/td>
&lt;td>&lt;code>quarkus-smallrye-opentracing&lt;/code>&lt;/td>
&lt;td>MicroProfile OpenTracing implementation&lt;/td>
&lt;td>&lt;a href="https://github.com/eclipse/microprofile-opentracing/blob/main/spec/src/main/asciidoc/microprofile-opentracing-spec.asciidoc" target="_blank" rel="noopener">MicroProfile OpenTracing&lt;/a>
&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>io.opentracing.contrib&lt;/code>&lt;/td>
&lt;td>&lt;code>opentracing-jdbc&lt;/code>&lt;/td>
&lt;td>Provides traces for database queries.&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="configuration">Configuration&lt;/h3>
&lt;p>The following configurations is required in the &lt;code>application.properties&lt;/code> to setup the tracing:&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>quarkus.jaeger.endpoint=http://jaeger:14268/api/traces
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.jaeger.service-name=monolith-application
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.jaeger.sampler-type=const
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.jaeger.sampler-param=1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ul>
&lt;li>&lt;code>endpoint&lt;/code>: defines where we will send our metrics&lt;/li>
&lt;li>&lt;code>service-name&lt;/code>: the name of the current service&lt;/li>
&lt;li>&lt;code>sampler-type&lt;/code>: &lt;code>const&lt;/code> defines a constant sampling&lt;/li>
&lt;li>&lt;code>sampler-param&lt;/code>: percentage of request which are sampled. &lt;code>1&lt;/code> defines that we want to sample all requests.&lt;/li>
&lt;/ul>
&lt;p>Further we have to use the tracing enabled database driver.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>quarkus.datasource.db-kind=postgresql
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.datasource.jdbc.url=jdbc:tracing:postgresql://application-db:5432/admin
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.datasource.jdbc.driver=io.opentracing.contrib.jdbc.TracingDriver
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQLDialect
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Last we made the Quarkus log format to include the &lt;code>traceId&lt;/code> and &lt;code>spanId&lt;/code> in the logs. This is not necessary but will
help troubleshooting.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>
&lt;div class="alert alert-primary" role="alert">
&lt;h4 class="alert-heading">Configuration&lt;/h4>
The configuration listed above may slightly differ from the one used in the solution repository. This is because some
properties are overridden using environment variables in the &lt;code>docker-compose.yaml&lt;/code> file.
&lt;/div>
&lt;p>&lt;a href="https://raw.githubusercontent.com/acend/microservices-lab/main/solution/monolith/monolith-application/src/main/resources/application.properties" target="_blank" rel="noopener">full source application.properties&lt;/a>
&lt;/p>
&lt;h2 id="application-code">Application code&lt;/h2>
&lt;p>Using the configuration made is basically everything which is needed to get traces from our application. By default all requests to
RESTful endpoints are traced. Using the &lt;code>TracingDriver&lt;/code> provides spans for all database queries.&lt;/p>
&lt;p>If you want to customize the tracing you can annotate any class or method with the &lt;code>@Traced&lt;/code> annotation. You may also
disable the default tracing with &lt;code>@Traced(false)&lt;/code>. Further you may inject the &lt;code>Tracer&lt;/code> to your application code. Using
this tracer you can create custom spans in business methods or add tags to span.&lt;/p>
&lt;p>This snipped is from class &lt;code>ShopOrderService&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;div style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-java" data-lang="java">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#5c35cc;font-weight:bold">@ApplicationScoped&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#204a87;font-weight:bold">public&lt;/span> &lt;span style="color:#204a87;font-weight:bold">class&lt;/span> &lt;span style="color:#000">ShopOrderService&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// ...
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#5c35cc;font-weight:bold">@Inject&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">Tracer&lt;/span> &lt;span style="color:#000">tracer&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#5c35cc;font-weight:bold">@Traced&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">operationName&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#4e9a06">&amp;#34;createOrder&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">public&lt;/span> &lt;span style="color:#000">ShopOrder&lt;/span> &lt;span style="color:#000">createOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#000">ShopOrderDTO&lt;/span> &lt;span style="color:#000">shopOrderDTO&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">)&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">{&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">ShopOrder&lt;/span> &lt;span style="color:#000">shopOrder&lt;/span> &lt;span style="color:#ce5c00;font-weight:bold">=&lt;/span> &lt;span style="color:#204a87;font-weight:bold">new&lt;/span> &lt;span style="color:#000">ShopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">();&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#8f5902;font-style:italic">// ...
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8f5902;font-style:italic">&lt;/span> &lt;span style="color:#000">shopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">.&lt;/span>&lt;span style="color:#c4a000">persist&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">();&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#000">tracer&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">.&lt;/span>&lt;span style="color:#c4a000">activeSpan&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">().&lt;/span>&lt;span style="color:#c4a000">setTag&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">(&lt;/span>&lt;span style="color:#4e9a06">&amp;#34;order.id&amp;#34;&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">,&lt;/span> &lt;span style="color:#000">shopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">.&lt;/span>&lt;span style="color:#c4a000">id&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">);&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#204a87;font-weight:bold">return&lt;/span> &lt;span style="color:#000">shopOrder&lt;/span>&lt;span style="color:#ce5c00;font-weight:bold">;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ce5c00;font-weight:bold">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This will create a span for the method &lt;code>createOrder&lt;/code> and name it accordingly. Using the injected &lt;code>Tracer&lt;/code> we tag the span
with the just created &lt;code>order.id&lt;/code>.&lt;/p>
&lt;p>&lt;a href="https://raw.githubusercontent.com/acend/microservices-lab/main/solution/monolith/monolith-application/src/main/java/ch/puzzle/mm/monolith/order/control/ShopOrderService.java" target="_blank" rel="noopener">full source ShopOrderService.java&lt;/a>
&lt;/p>
&lt;h3 id="task-261---inspect-the-application-traces">Task 2.6.1 - Inspect the application traces&lt;/h3>
&lt;p>Start up your environment if not already running and point your browser to the Jaeger UI at &lt;a href="http://localhost:16686/" target="_blank" rel="noopener">http://localhost:16686/&lt;/a>
&lt;/p>
&lt;p>Issue requests as described in section 2.4&lt;/p>
&lt;ul>
&lt;li>Do you find traces for created orders? You may list all traces or use the tag filter &lt;code>order.id=X&lt;/code>&lt;/li>
&lt;li>How do traces look like if the operationName is not set?&lt;/li>
&lt;li>Do you see the tag &lt;code>order.id&lt;/code> on the span?&lt;/li>
&lt;li>What happens if you inject an exception as described in section 2.4?&lt;/li>
&lt;/ul>
&lt;details >
&lt;summary>Task Hint&lt;/summary>
&lt;p>Traces from application code with no explicit name are named by their class and method. If an exception is thrown, there
will be a tag &lt;code>error=true&lt;/code> on the span. The Jaeger UI will flag such spans with an exclamation mark.&lt;/p>
&lt;/details></description></item></channel></rss>