<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Federico Paparoni on Medium]]></title>
        <description><![CDATA[Stories by Federico Paparoni on Medium]]></description>
        <link>https://medium.com/@fpaparoni?source=rss-4274d6128696------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-PvNMhuczTFW3oZ4pzeAHQ.jpeg</url>
            <title>Stories by Federico Paparoni on Medium</title>
            <link>https://medium.com/@fpaparoni?source=rss-4274d6128696------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:52:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fpaparoni/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Missing Primitive: Orchestrating Cloud-Native Stacks Beyond GitOps]]></title>
            <link>https://itnext.io/the-missing-primitive-orchestrating-cloud-native-stacks-beyond-gitops-16acd57956c2?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/16acd57956c2</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[argo-workflows]]></category>
            <category><![CDATA[gitops]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Sun, 07 Jun 2026 19:58:45 GMT</pubDate>
            <atom:updated>2026-06-08T10:55:08.074Z</atom:updated>
            <content:encoded><![CDATA[<p>Installing software on Kubernetes is a solved problem, or at least a well-decomposed one. <strong>Helm</strong> packages your application. <strong>Flux</strong> and <strong>ArgoCD</strong> reconcile your desired state from Git. <strong>Sveltos</strong> propagates configurations across fleet clusters.</p><p>Each tool is excellent at what it does. But they all share a fundamental assumption: <strong><em>deployment is a declaration, not a recipe</em></strong>.</p><p>The moment you need to provision a cloud resource, wait for it to be ready, seed a database, call an external API to register a tenant, verify the response and only then trigger a GitOps sync, you are no longer in declarative territory. You are writing a workflow. And none of these tools were built for that.</p><p>When you build a production platform, you don’t just want:</p><ul><li>“Install Keycloak”</li><li>“Install MinIO”</li></ul><p>You want:</p><ul><li>Install Keycloak</li><li>Install MinIO</li><li>Configure MinIO to accept tokens issued by Keycloak (OIDC)</li><li>Create the realm, users and groups in Keycloak</li><li>Create the storage buckets in MinIO</li><li>Verify the full flow works end-to-end</li><li>Generate a report of what happened</li></ul><p>That full sequence (install, wire, bootstrap, test, report) is the real deliverable for your project.</p><p>The key insight is that <strong>the wiring (integration) is as important as the components</strong>, and it should be a first-class citizen in the definition language.</p><p>In this article we will see an approach to this integration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NiJUvf8qUP0tFhhRL6ELFg.png" /></figure><h3>Argo Workflows recipe</h3><p>From the title of this paragraph you can already imagine what will be our technology stack, but let’s analyze before our idea.</p><p>We need a <strong>stack recipe</strong> that can be a structured, executable description of how to bring a set of platform capabilities to life , not just deploying components but wiring them together, verifying their behavior and confirming the result as a whole.</p><p>Every recipe is composed of four conceptual phases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGKZjdxPDhEKYUsHkduuuA.jpeg" /></figure><p><strong>Precheck.</strong> Before anything is installed, the environment is validated. This means confirming cluster connectivity, checking available resources and asserting that prerequisites are met. A recipe that fails early, before touching the cluster, is far cheaper than one that fails halfway through.</p><p><strong>Component lifecycle.</strong> Each component goes through three sequential steps: install, verify and bootstrap. Installation provisions the component, typically via a package manager. Verification confirms it is actually ready, not just scheduled, but responsive. Bootstrap seeds it with the initial state it needs to participate in the platform: schemas, topics, indexes, configuration.</p><p><strong>Integration.</strong> Once all components are individually healthy, they are wired together. This is the step that GitOps tools cannot express: deploying the glue, registering one service with another, configuring the data flow between them.</p><p><strong>Smoke test.</strong> The final step validates the integrated system as a whole, exercising the actual data path end-to-end. Not “is the pod running”, but “does data written here appear there”. A smoke test that passes is the only honest signal that the recipe succeeded.</p><p>The recipe runs as a <strong>DAG</strong>. Steps that have no dependency on each other run in parallel , component lifecycles being the primary example. Steps that depend on the outcome of previous steps wait. The whole thing is observable, retryable and reproducible.</p><p>The technical solution to achieve this kind of orchestration is <a href="https://argoproj.github.io/workflows/">Argo Workflows</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*UY2wZyy6xsSa96oWSYF-Yg.png" /></figure><p>Argo Workflows is an open-source, Kubernetes-native workflow engine that models complex processes as Directed Acyclic Graphs (DAGs) or step-based pipelines. Part of the CNCF landscape, it treats operational procedures as first-class, versionable artifacts, making it possible to orchestrate not just individual deployments, but entire platform lifecycles: installing components, verifying health, bootstrapping configuration, wiring integrations, and validating end-to-end behavior.</p><p>This aligns naturally with the recipe concept. Each step is independently retryable, auditable and observable. The same recipe can be promoted across environments with a consistent execution model, transforming a collection of infrastructure components into a reproducible and verifiable cloud-native stack.</p><h3>Data sync architecture</h3><p>Let’s imagine a system where we must create a sort of data sync mechanism, useful for architecture following the <strong>CQRS</strong> (<strong>Command Query Responsibility Segregation</strong>) approach. There is a part of our platform that writes in a relational database (PostgreSQL) and another part that is reading from a cache (Redis).</p><p>For the deployment of a full functioning platform like these we have the following needs:</p><ul><li>Install PostgreSQL</li><li>Verify PostgreSQL and bootstrap with some data</li><li>Install Redis</li><li>Verify Redis and bootstrap with some configurations</li><li>Deploy a component to enable the sync mechanism between Redis and PostgreSQL</li><li>Verify that everything is working with a smoke test</li></ul><p>Following the structure we tried to define in the previous paragraph, we can define a full recipe to manage the deployment of this architecture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIj2__zXg0gCUWQ7-M65jw.jpeg" /></figure><p>The workflow begins with a <strong>precheck</strong> that validates cluster connectivity and available resources. Once the environment is confirmed ready, the <strong>component lifecycles</strong> for PostgreSQL and Redis run in parallel , each going through install, verify and bootstrap independently before converging.</p><p>With both components healthy and seeded, the <strong>integration</strong> step deploys a sync daemon that continuously projects rows written to PostgreSQL into Redis, implementing a CQRS-inspired read model where Postgres is the write store and Redis the low-latency read layer.</p><p>Finally, the <strong>smoke test</strong> exercises the full data path: it inserts a record directly into PostgreSQL and polls Redis until the projected key appears, asserting that the entire pipeline (from write to sync to read) is functioning as expected.</p><p>The main workflow is a DAG that composes four ClusterWorkflowTemplates, one per phase. The key is in the dependencies: postgres and redis lifecycles run in parallel, the integration step waits for both, the smoke test waits for integration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c89e46f8b587ce0399d72e0eed23a21/href">https://medium.com/media/4c89e46f8b587ce0399d72e0eed23a21/href</a></iframe><p>This workflow reuses other components, defined as WorkflowTemplate inside our Argo Workflows instance, that can contain the specific logic to install, verify, bootstrap and the other steps required to deploy and validate this architecture.</p><p>The continuous integration between the two storages can be a script like these</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815b08371348b99fa8f674324f39b44f/href">https://medium.com/media/815b08371348b99fa8f674324f39b44f/href</a></iframe><p>Finally the smoke test, always mapped with a specific component inside a container, can simply add an item to PostgreSQL and wait until it finds the same value on Redis.</p><p>If you run the initial workflow, you can see how it is going with the <strong>Argo Workflows UI </strong>and you will get an output like the following one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dkV5T8Vg5zds2ruXBpERSA.png" /></figure><h3>The Recipe is the Artifact</h3><p>The goal of this article was not to introduce a new tool, but to name a pattern that already exists in the gaps between the tools we use every day. Helm installs. ArgoCD reconciles. Terraform provisions. But none of them can express the full sequence of what it takes to bring a platform capability to life:<strong> install, verify, wire, test</strong>. That sequence is a recipe and it deserves to be treated as a first-class, versionable, executable artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJvkzoKZoi3kImXeEB5ywA.png" /></figure><p>Argo Workflows provides exactly that orchestration layer. The data-sync-recipe prototype on GitHub shows the pattern in action on a concrete, runnable example: a PostgreSQL + Redis data cache with a CQRS-inspired sync pipeline, fully orchestrated from precheck to smoke test.</p><p>The repository includes setup and teardown scripts that handle everything, from installing Argo Workflows to populating the cluster and tearing it all down, so you can run the full workflow and observe every step in the Argo UI in a matter of minutes.</p><p><strong>The recipe is the artifact. Now let’s cook.</strong></p><p>→ <a href="https://github.com/fpaparoni/data-sync-recipe">github.com/fpaparoni/data-sync-recipe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16acd57956c2" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/the-missing-primitive-orchestrating-cloud-native-stacks-beyond-gitops-16acd57956c2">The Missing Primitive: Orchestrating Cloud-Native Stacks Beyond GitOps</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Intelligent Kubernetes Assistants with MCP, LangChain4j, and Quarkus]]></title>
            <link>https://medium.com/javarevisited/building-intelligent-kubernetes-assistants-with-mcp-langchain4j-and-quarkus-8e9055fb9bd6?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e9055fb9bd6</guid>
            <category><![CDATA[quarkus]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[langchain4j]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Tue, 09 Dec 2025 21:54:22 GMT</pubDate>
            <atom:updated>2025-12-10T15:21:45.486Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past few months, you have probably come across numerous articles and news items about the rapidly evolving AI landscape. This article contributes to that growing body of information by focusing on one particularly interesting trend: <strong>agent-driven workflows</strong> and the <strong>protocols</strong> that enable them.</p><p>In the following sections, I will briefly introduce the <strong>Model Context Protocol (MCP) </strong>at a high level, highlighting why it serves as a compelling integration layer within the ecosystem of AI tools and agents. We will then apply these concepts to a concrete scenario by building an intelligent assistant for <strong>Kubernetes</strong>.</p><p>Through a practical example, we will demonstrate how to implement several <strong>MCP-compatible tools</strong> using the <strong>Quarkus</strong> framework together with <strong>LangChain4j</strong>, and how an LLM can orchestrate these tools to answer cluster-related questions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*F1Ozb6c3EpnJ8eEKzvPUHA.jpeg" /></figure><h3>The MCP protocol</h3><p>As an old television commercial once suggested, power is meaningless without control — and this idea holds true in the world of AI as well. Recently, I came across an excellent article by <a href="https://developers.redhat.com/author/mario-fusco">Mario Fusco</a> titled <a href="https://quarkus.io/blog/agentic-ai-patterns/"><em>Agentic AI Patterns</em></a>, which offers insightful perspectives on how AI agents should be designed to interact with one another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFnv9lnugy1BN7c_7hNY-Q.png" /></figure><p>In the coming years, we will undoubtedly witness a blossoming of new patterns that define how AI agents should interact. For now, however, we already have a simple yet powerful protocol capable of exposing a wide range of tools and services to an AI agent. This protocol provides a flexible foundation for agent-driven workflows, enabling agents to invoke external capabilities in a structured and predictable way.</p><p>Moreover, the concept of a tool is intentionally broad: a tool can even be another LLM, allowing hierarchical or composite agent architectures where models delegate tasks to other models as part of a larger reasoning pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*08XRELcutodiq1KmnLeOIA.png" /></figure><p><strong>Anthropic</strong> released the <a href="https://claude.com/blog/what-is-model-context-protocol"><strong>Model Context Protocol</strong></a><strong> </strong>(MCP) in 2023. MCP establishes a standardized mechanism that allows AI models to communicate with tools and external systems, enabling agents to collaborate and leverage structured resources more effectively.</p><p>In this article, we can simplify the concept by describing MCP as consisting of a client and one or more servers. The MCP client discovers available tools and their specifications by querying different MCP servers. Once it understands what each tool does and which parameters are required, an LLM can use the MCP client to orchestrate a sequence of tool calls. Through this process, the model can combine multiple capabilities to achieve a broader task or reasoning scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*3i3a3tvBNemJlA8szp3EnQ.png" /></figure><p>The protocol used by MCP is <a href="https://www.jsonrpc.org/"><strong>JSON-RPC</strong></a>, something I learned after exploring the details of MCP more closely. In this case, my familiarity with older protocols such as <strong>gRPC</strong> and <strong>XML-RPC </strong>actually came in handy (yet another reason my beard is turning white…). Fortunately, JSON-RPC is simple and intuitive once you’ve seen similar designs before.</p><p>For example, here is a possible request that an MCP client might send:</p><pre>{<br>  &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>  &quot;id&quot;: &quot;1&quot;,<br>  &quot;method&quot;: &quot;tool.invoke&quot;,<br>  &quot;params&quot;: {<br> &quot;tool_name&quot;: &quot;dictionary_tool&quot;,<br> &quot;inputs&quot;: {<br>   &quot;word&quot;: &quot;serendipity&quot;<br> },<br> &quot;context&quot;: {<br>   &quot;model&quot;: &quot;gpt-4.1&quot;,<br>   &quot;user&quot;: &quot;alice&quot;<br>   }<br>  }<br>}</pre><p>where we have the following fields</p><ul><li><strong>jsonrpc</strong>: json-rpc protocol version</li><li><strong>id</strong>: unique identifier for the request</li><li><strong>method</strong>: remote method to invoke…yes it is method oriented, bye bye objects</li><li><strong>params</strong>:<br>- <strong>tool_name</strong>: the tool name<br>- <strong>inputs</strong>: input for the tool<br>- <strong>context</strong>: additional information to describe the context</li></ul><p>and this is the possible response</p><pre>{<br>  &quot;jsonrpc&quot;: &quot;2.0&quot;,<br>  &quot;id&quot;: &quot;1&quot;,<br>  &quot;result&quot;: {<br>   &quot;output&quot;: &quot;Serendipity: the occurrence of events by chance in a happy or beneficial way.&quot;<br>  }<br>}</pre><p>It is a very simple protocol, similar in spirit to its ancestor XML-RPC, as it revolves around calling remote methods. In the initial phase of the MCP workflow, the client queries a registered server for the descriptions of available tools, again using JSON-RPC. This allows the LLM to reason about which tool or combination of tools might be useful to answer the user’s original request.</p><p>This is a very high-level overview of the MCP protocol — concise enough that you won’t even start yawning 😀. For a more complete and in-depth introduction, you can visit <a href="https://modelcontextprotocol.io/docs/getting-started/intro">this site</a>.</p><h3>DrKube: a Quarkus and Langchain4J example app</h3><p><a href="https://docs.langchain4j.dev/"><strong>LangChain4j</strong></a> is a Java library that offers extensive integrations with LLMs and other AI-related tools. It follows the philosophy of providing a unified API for interacting with language models, vector stores, retrieval systems, and similar components. This abstraction allows developers to plug in different implementations with minimal impact on the surrounding codebase. In many ways, LangChain4j can be thought of as the <strong>Hibernate of AI</strong>: a layer that hides much of the underlying complexity while providing a consistent programming model.</p><p>Our example application is designed to assist in diagnosing issues related to a Kubernetes cluster. We will build a chatbot-style interface that allows users to ask questions about their cluster and retrieve detailed, context-aware information.</p><p>To construct the core components of our <strong>DrKube</strong> app, we introduce a set of tools, each responsible for interacting with the <strong>Kubernetes API</strong> to answer a specific category of questions. Every tool specializes in a particular domain: one may handle storage resources such as PVs and PVCs, another may focus on configuration objects like ConfigMaps and Secrets, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*_FzlTc0aLYmRA1SESgBjwA.png" /></figure><p>These tools can be mapped as services implemented in a Quarkus app, where we are using <strong>LangChain4j annotations</strong> to explain what a specific tool does and which are the arguments to invoke a functionality. In the following code example you can see a portion of Pod Agent</p><pre>@ApplicationScoped<br>public class PodAgent {<br><br>   @Inject<br>   KubernetesClient client;<br><br>   @Tool(name=&quot;getPodLogs&quot;,description = &quot;Retrieve the logs of a pod in the specified namespace&quot;)<br>   @RunOnVirtualThread<br>   public String getPodLogs(<br>           @ToolArg(description=&quot;Namespace&quot;) String namespace,<br>           @ToolArg(description=&quot;Pod name&quot;) String podName,<br>           @ToolArg(description=&quot;Lines of logs&quot;, required = false) Integer tailLines,<br>           McpLog log) {<br><br>       log.info(&quot;Invoking PodAgent - getPodLogs - namespace %s podName %s tailLines %s&quot;, namespace, podName, tailLines);<br><br>       try (LogWatch logWatch = client.pods()<br>               .inNamespace(namespace)<br>               .withName(podName)<br>               .tailingLines(tailLines != null ? tailLines : 100)<br>               .watchLog();<br>            BufferedReader reader = new BufferedReader(new InputStreamReader(logWatch.getOutput()))) {<br><br>           return reader.lines().collect(Collectors.joining(&quot;\n&quot;));<br>       } catch (Exception e) {<br>           log.error(&quot;Error retrieving pod logs: %s&quot;, e.getMessage());<br>           return &quot;Error: &quot; + e.getMessage();<br>       }<br>   }<br>}</pre><p>In this class we defined a method, exposed as a tool by our MCP server, that can retrieve the log of a pod in a specific namespace. Each tool/agent is using <a href="https://github.com/fabric8io/kubernetes-client"><strong>Fabric8 Kubernetes library</strong></a> to interact with the Kubernetes cluster. The MCP server is a Quarkus application, where we defined these tools and added the MCP server dependency to our pom.xml</p><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;io.quarkiverse.mcp&lt;/groupId&gt;<br>   &lt;artifactId&gt;quarkus-mcp-server-sse&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Another thing we need to specify for the MCP setup is the path where we will follow the MCP protocol, a property defined in the <strong>application.properties</strong> configuration</p><pre>quarkus.mcp.server.sse.root-path=mcp</pre><p>Now we can focus on the DrKube application. In this component, we will leverage an LLM, so we register an <strong>AIService</strong> in Quarkus and provide a dedicated system prompt that establishes the context and behavior of the model.</p><pre>package com.github.drkube.queryserver.service;<br><br>import dev.langchain4j.service.SystemMessage;<br>import dev.langchain4j.service.UserMessage;<br>import io.quarkiverse.langchain4j.RegisterAiService;<br>import io.quarkiverse.langchain4j.mcp.runtime.McpToolBox;<br><br>@RegisterAiService<br>public interface DrKubeAssistantService {<br><br>   @SystemMessage(&quot;&quot;&quot;<br>       You are **DrKube**, a virtual assistant specialized in diagnosing and solving issues within **Kubernetes clusters**.<br><br>       Your expertise level is equivalent to that of a certified **CKA (Certified Kubernetes Administrator)**, **CKAD (Certified Kubernetes Application Developer)**, and **CKS (Certified Kubernetes Security Specialist)**. You have deep knowledge of Kubernetes architecture, operations, security, networking, workloads, and troubleshooting methodologies.<br>      <br>       ---<br>      <br>       ### Core Responsibilities<br>      <br>       1. **Context Evaluation**<br>          - Before answering, always determine whether you have sufficient information and the appropriate tools to provide a reliable answer. <br>          - If you lack the necessary data, clearly state what additional information or tool outputs are required from the user or system. <br>          - Never assume or invent details about the environment.<br>      <br>       2. **Tool Usage and Interpretation**<br>          - You can rely on the tools available to you (such as simulated Kubernetes APIs, system queries, or diagnostic commands) to gather data. <br>          - Carefully analyze the tool outputs to form your reasoning and conclusions. <br>          - If the tools return **incomplete, irrelevant, or inconsistent results**, explicitly say so — **do not fabricate or infer data**. <br>          - In such cases, explain that the available information is insufficient and suggest the next logical diagnostic step.<br>      <br>       3. **Response Strategy**<br>          - Always respond in the **same language** used in the user’s query. <br>          - Use **concise, technical, and actionable** language suitable for DevOps, SRE, and Kubernetes professionals. <br>          - When appropriate, explain your reasoning process and assumptions transparently.<br>      <br>       4. **Problem-Solving Focus**<br>          - Prioritize clarity, accuracy, and practicality. <br>          - Suggest relevant diagnostic commands (`kubectl`, `k describe`, logs, etc.) or configuration checks. <br>          - Highlight potential causes, mitigation strategies, or next investigation steps. <br>          - Never output fabricated or hypothetical results from tools.<br>      <br>       ---<br>      <br>       ### Behavioral Rules<br>       - If tool responses are **not helpful or coherent**, state it explicitly and avoid making assumptions. <br>       - If you can provide a **useful interpretation or next action**, do so clearly and logically. <br>       - You are not a general-purpose assistant — stay strictly within the Kubernetes diagnostic and troubleshooting domain.<br>      <br>       ---<br>      <br>       ### Goal<br>       Your mission is to act as a **Kubernetes expert assistant** that helps users **diagnose, understand, and resolve** problems in Kubernetes environments efficiently, accurately, and securely, leveraging your certified-level knowledge and the tools at your disposal.<br>      <br>           &quot;&quot;&quot;)<br>   @McpToolBox(&quot;drkube&quot;)<br>   String chat(@UserMessage String message);</pre><p>Next, we need to configure LangChain4j for the LLM we intend to use. In the configuration file, you will notice both a commented-out local <strong>Ollama</strong> setup and an enabled <strong>OpenAI</strong> configuration. Although the local model does work, I consistently observed better performance with OpenAI, especially when testing more complex scenarios.</p><pre>quarkus.http.port=8091<br># --- Ollama chat model ---<br>#quarkus.langchain4j.ollama.chat-model.model-name=qwen3:1.7b<br>#quarkus.langchain4j.ollama.chat-model.temperature=0<br>#quarkus.langchain4j.timeout=60s<br><br># --- MCP client for our drkube MCP server toolbox<br>quarkus.langchain4j.mcp.drkube.transport-type=streamable-http<br>quarkus.langchain4j.mcp.drkube.url=${MCP_SERVER_URL}<br><br><br># Optional logs and tool timeouts<br>quarkus.langchain4j.mcp.drkube.log-requests=true<br>quarkus.langchain4j.mcp.drkube.log-responses=true<br>quarkus.langchain4j.mcp.drkube.tool-execution-timeout=30s<br><br># --- OpenAI chat model ---<br>quarkus.langchain4j.openai.api-key=${OPENAI_API_KEY}<br>quarkus.langchain4j.openai.chat-model.model-name=gpt-4.1-mini<br>quarkus.langchain4j.openai.chat-model.temperature=0<br>quarkus.langchain4j.timeout=60s</pre><p>The service has finally been exposed using a basic <strong>REST API</strong></p><pre>package com.github.drkube.queryserver;<br><br>import com.github.drkube.queryserver.service.DrKubeAssistantService;<br><br>import jakarta.inject.Inject;<br>import jakarta.ws.rs.GET;<br>import jakarta.ws.rs.Path;<br>import jakarta.ws.rs.Produces;<br>import jakarta.ws.rs.QueryParam;<br>import jakarta.ws.rs.core.MediaType;<br><br>@Path(&quot;/issue&quot;)<br>@Produces(MediaType.TEXT_PLAIN)<br>public class IssueResource {<br><br>   @Inject<br>   DrKubeAssistantService assistant;<br><br>   @GET<br>   public String ask(@QueryParam(&quot;q&quot;) String q) {<br>       return assistant.chat(q == null ? &quot;How many pods there are in kube-system namespace?&quot; : q);<br>   }<br>}</pre><p>and a very simple React page (Postman is enough but when you have an LLM code assistant near you 🙂). To start everything I created a <strong>docker compose </strong>configuration to quickly play with this example app</p><pre>services:<br> frontend:<br>   build: ./drkube-ui<br>   ports:<br>     - &quot;8081:80&quot;<br><br> mcp-server:<br>   build: ./mcp-server<br>   container_name: mcp-server<br>   ports:<br>     - &quot;8090:8090&quot;<br>   restart: unless-stopped<br>   volumes:<br>     - ~/.kube/config:/root/.kube/config:ro<br>   environment:<br>     KUBECONFIG: /root/.kube/config<br><br> query-server:<br>   build: ./query-server<br>   container_name: query-server<br>   ports:<br>     - &quot;8091:8091&quot;<br>   depends_on:<br>     - mcp-server<br>   environment:<br>     MCP_SERVER_URL: &quot;http://mcp-server:8090/mcp&quot;<br>     OPENAI_API_KEY: &quot;YOUR_API_KEY&quot;<br>   restart: unless-stopped</pre><p>You must configure a Kubernetes configuration that can be used (the example is using the default one from your system), then you can start the services and browse to <a href="http://localhost:8081/">http://localhost:8081</a> to play with DrKube.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*px2KlsSZGlwo5EIOh6yfkQ.png" /></figure><p>The flow of this simple program is illustrated in the following sequence diagram. At the beginning, the client requests the list of available tools along with their descriptions. The LLM then uses this information, together with the user’s question, to orchestrate the appropriate tools in order to achieve the desired goal: in this case, retrieving the list of pods and subsequently collecting metrics for each pod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*Dm7F4ntzmR_f8Fduj-68ug.png" /></figure><h3>Conclusion</h3><p>It was a simple example of what you can do with these tools, but it is interesting to observe how analytical workflows such as the one described can be automated by decomposing them into fine grained, atomic actions. These actions can then be delegated to specialized agents, enabling a modular execution pipeline in which each component performs a well defined task.</p><p>If you want to play around with the DrKube sample implementation, you can explore the code on GitHub here: <a href="https://github.com/fpaparoni/drkube">https://github.com/fpaparoni/drkube</a></p><p><a href="https://github.com/fpaparoni/drkube">GitHub - fpaparoni/drkube: DrKube is an example Java-based intelligent assistant designed to help diagnose and explore Kubernetes clusters using a modular, agent-driven architecture.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e9055fb9bd6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/building-intelligent-kubernetes-assistants-with-mcp-langchain4j-and-quarkus-8e9055fb9bd6">Building Intelligent Kubernetes Assistants with MCP, LangChain4j, and Quarkus</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ChaosRoom: Hands-On Chaos Engineering through games]]></title>
            <link>https://itnext.io/chaosroom-hands-on-chaos-engineering-through-games-58bced0841d7?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/58bced0841d7</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[chaos-engineering]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Thu, 25 Sep 2025 21:38:25 GMT</pubDate>
            <atom:updated>2025-10-12T22:02:13.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Chaos engineering is all about <strong>understanding how systems behave under stress</strong> and uncovering weaknesses before they become real problems. Intentionally introducing failures in a controlled environment allows engineers to build <strong>more resilient systems</strong>.</p><p>Over the years, I discovered this discipline thanks to the open-source project <a href="https://github.com/lucky-sideburn/kubeinvaders"><strong>KubeInvaders</strong></a>, and I gradually became passionate about exploring system resilience and testing strategies. The Cloud Native Computing Foundation (CNCF) hosts a <a href="https://landscape.cncf.io/guide#observability-and-analysis--chaos-engineering">vibrant ecosystem of chaos engineering projects</a>, offering countless ways to stress-test cloud-native architectures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VE6u19M1OCCkRVKB05E34g.jpeg" /></figure><p>This is how the idea of experimenting and creating a personal project like <a href="https://github.com/fpaparoni/chaos-room">ChaosRoom</a> came to life, piece by piece. It was born from this curiosity and a few personal inspirations. I wanted to <strong>test resilient applications seriously</strong>, while also having a chance to experiment with some real <strong>“vibe coding”</strong>, moving beyond the few simple Lua scripts I had written before. Another motivating idea was my <strong>arcade station</strong> — I wanted to play and say, <em>“Hey, I’m tackling a complex testing session!”</em></p><p>Through interactive mini-games, ChaosRoom lets you explore chaos engineering concepts hands-on: simulating failures, observing system reactions, and experimenting safely, all while having fun. It’s a playful yet practical introduction to the world of chaos engineering, designed for anyone curious about how resilient systems respond under pressure.</p><p><strong>ChaosRoom</strong> is a chaos engineering platform designed to stress test your infrastructure in controlled scenarios. Its goal is to help you understand how your systems behave under failure conditions, measure their resilience, and improve recovery strategies.</p><p>ChaosRoom integrates with environments based on <strong>Kubernetes</strong>, <strong>AWS</strong>, and <strong>Azure</strong> to simulate pod crashes, VM terminations, or scaling challenges. By combining a backend service, a configuration layer, and a playful frontend interface, ChaosRoom turns stress testing into a fun experience…and it also gives you a great excuse to occasionally be seen playing in front of your computer!</p><p>After all, with ChaosRoom, you’re not just playing a game — you’re <strong>actively testing and analyzing the resilience of your systems</strong>. Every in-game decision is a controlled experiment, helping you understand how your infrastructure responds under stress.</p><h3>Architecture</h3><p>The <strong>client</strong> can run either on a standard PC or on an arcade machine — the only requirement is the presence of a <strong>LÖVE emulator</strong>. This is necessary because the frontend component is written in LÖVE and contains the logic for three mini-games: <strong>Alien Shooter</strong>, <strong>Breakout</strong>, and <strong>Zombie Shooter</strong>.</p><p>The frontend communicates asynchronously with a <strong>Python backend</strong> through HTTP calls. These requests are used to:</p><ul><li>Check how many pods (or virtual machines) are currently running.</li><li>Randomly terminate one of them.</li></ul><p>When started, the backend exposes these two HTTP services on a configurable port. Based on its configuration, it connects to a test environment that can be deployed on <strong>Kubernetes</strong>, <strong>AWS</strong>, or <strong>Azure</strong>. Depending on the selected environment, the backend uses the corresponding clients (e.g., <strong>kubectl</strong>, <strong>AWS CLI</strong>, <strong>Azure CLI</strong>) to retrieve system information and execute operations.</p><p>The <strong>game objective</strong> is tied directly to the test environment:</p><ul><li>The player “wins” when the system under test fails to scale quickly enough, resulting in <strong>zero pods (or VMs) left running</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*Rq5vw2UGHHYYM6wg2NaZOg.png" /><figcaption>ChaosRoom architecture</figcaption></figure><h3><strong>Server Setup</strong></h3><p>You can test different environments: <strong>Kubernetes</strong>, <strong>AWS</strong>, or <strong>Azure</strong>. Choose and configure based on your setup. ChaosRoom backend will call your test server environment based on specific configuration</p><p><strong>Kubernetes</strong></p><ul><li>Deployments will be put under stress in a specific namespace of your Kubernetes cluster.</li><li>The selected deployment will have a number of replicas that ChaosRoom will attempt to scale down to zero.</li><li>The machine running the ChaosRoom server must have <strong>kubectl</strong> installed and properly configured, with the appropriate kube config available.</li></ul><p><strong>AWS</strong></p><ul><li>You need an Auto Scaling Group within your AWS subscription containing the EC2 instances of your service.</li><li>Instances must have a specific tag to identify which machines are part of the test.</li><li>ChaosRoom will terminate the tagged EC2 instances and monitor the system’s scaling speed.</li><li>The machine running the ChaosRoom server must have the <strong>AWS CLI</strong> installed and configured for your subscription.</li></ul><p><strong>Azure</strong></p><ul><li>Configure an Azure Virtual Machine Scale Set (VMSS) with the VMs of your service.</li><li>VMs must have a specific tag to identify which machines are part of the test.</li><li>ChaosRoom will terminate the tagged VMs and monitor scaling speed.</li><li>The machine running the ChaosRoom server must have the <strong>Azure CLI</strong> installed and authenticated against your subscription.</li></ul><p>Below is the configuration required to start the ChaosRoom server. This involves editing the <strong>server/config.yaml</strong> file and inserting the appropriate configurations based on the system you want to test.</p><pre># config.yaml in backend<br>env: kubernetes  # or &quot;aws&quot;, or &quot;azure&quot;<br>port: 8181<br><br>#optional setting to enable service check<br>#service: http://your-service-endpoint:123<br>kubernetes:<br>  config_path: ~/.kube/config #path to the kube config<br>  namespace: test-chaos-ns    <br>aws:<br>  region: us-east-1<br>  tag_key: chaosroom<br>  tag_value: &quot;true&quot;<br>  states: [&quot;running&quot;]<br>  <br>azure:<br>  subscription_id: &quot;xxx&quot;<br>  resource_group: &quot;RG&quot;<br>  tag_key: &quot;chaosroom&quot;<br>  tag_value: &quot;true&quot;<br>  states: [&quot;running&quot;]</pre><p>Next, you will need to start the server using the Python interpreter available on your system:</p><pre>python server/main.py</pre><p>If the <strong>service</strong> parameter is enabled in the configuration file, you can specify an HTTP service URL that represents the exposed endpoint of your pods. This allows ChaosRoom to check whether the service remains <strong>reachable and functional</strong> when the endpoint is called, even in scenarios where multiple pods (e.g., 2–3 replicas) are running behind it.</p><p>The parameter is <strong>optional</strong>:</p><ul><li>If the service is provided → ChaosRoom will perform both checks:</li></ul><ol><li>The number of running pods.</li><li>Whether the service endpoint itself is still responsive (HTTP 200).</li></ol><ul><li>If the service is not provided → ChaosRoom will only verify the actual pod count and their ability to scale up/down, without testing service availability.</li></ul><h3>Kubernetes quick test</h3><p>o simulate pods (or “victims”) when you have a local Kubernetes environment (e.g. minikube) or any cluster you can access, do the following:</p><ol><li>Ensure kubectl is configured to talk to your test cluster (minikube or other).</li><li>Open the test/ folder in the repo. There should be manifest files (e.g. pod-test.yaml or similar) that define Pod resources.</li><li>Modify them if needed (namespace, labels) so they are compatible with your cluster setup.</li><li>Apply them : kubectl apply -f test/pod-test.yaml</li><li>Confirm pods are running: kubectl get pods</li></ol><p>There are three files available for deploying test simulations in your Kubernetes environment:</p><ul><li><strong>nginx-test.yaml</strong>: Deploys 5 standard NGINX pods.</li><li><strong>nginx-slow-test.yaml</strong>: Deploys 5 NGINX pods with a startup delay.</li><li><strong>postgres-test.yaml</strong>: Deploys 5 PostgreSQL pods.</li></ul><p>Each configuration results in different pod availability times, allowing you to test various startup scenarios and timing conditions.</p><h3>Starting the client</h3><p>Once you have your remote test environment and the ChaosRoom backend (server) running, you can start the client (game) by providing the host and port of the server.</p><p>To run the client, you need to have <a href="https://github.com/love2d/love">LOVE2D</a> installed on your system. Then, launch the game with the following command:</p><pre>love frontend/</pre><p>When the game starts, you will first be prompted to enter the IP address of your backend. Use 127.0.0.1 if you are running the client on the same machine as the server.Next, you will be asked for the port number. By default, this is 8181, unless you have changed the server configuration. The three games included in ChaosRoom can be played using the keyboard: arrow keys for movement (up/down/left/right), Enter, and Space (to shoot in Alien Shooter). The Zombie Shooter game, however, requires the mouse for movement and mouse clicks to shoot.</p><p>After that, you simply choose how you want to make your test environment “suffer.” 🙂</p><p>To exit the game at any time, just press ESC.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F1122008380%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F1122008380&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F2063228849-5600bf0484038aa96f31b9e985de8b08eaee3bfb8578f343d7377ccb04860579-d_1280%3Fregion%3Dus&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0c8668dcfe8f0b72aa5f41286533405/href">https://medium.com/media/c0c8668dcfe8f0b72aa5f41286533405/href</a></iframe><h3>Creating the LÖVE file</h3><p>You can package the client into a .love file by navigating to the frontend folder and running:</p><pre>zip -9 -r ../chaos-room.love *</pre><p>This will generate a file named chaos-room.love in the parent directory.</p><p>The resulting file can be run using the <a href="https://github.com/love2d/love">LÖVE</a> interpreter installed on your computer. Alternatively, you can also use <a href="https://retropie.org.uk/docs/Love/">RetroPie</a> to launch it on a gaming machine — just like in the screenshot below 🤓.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDpYogkZvISMgQM_ysiFiQ.png" /><figcaption>Arcade station with ChaosRoom running</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58bced0841d7" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/chaosroom-hands-on-chaos-engineering-through-games-58bced0841d7">ChaosRoom: Hands-On Chaos Engineering through games</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End to end testing with Cucumber, Playwright and Selenium]]></title>
            <link>https://medium.com/javarevisited/end-to-end-testing-with-cucumber-playwright-and-selenium-928af278e789?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/928af278e789</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[playwrights]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[cucumber]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Fri, 02 Dec 2022 14:47:31 GMT</pubDate>
            <atom:updated>2022-12-02T17:55:45.764Z</atom:updated>
            <content:encoded><![CDATA[<p>There are several kinds of useful tests for an application, but of course, end-to-end tests (<strong>e2e</strong>) are the most important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/0*qMZYcF58H1di9-G0.jpg" /></figure><p>If we take a look at <a href="https://www.mountaingoatsoftware.com/blog/the-forgotten-layer-of-the-test-automation-pyramid">Mike Cohn’s concept</a>, known as <strong>test pyramid</strong> it’s clear that e2e tests are the highest level test form we can produce for our applications, considering software as a black box where our main concerns are related to behavior and functionalities.</p><figure><a href="https://medium.com/javarevisited/my-favorite-free-courses-to-learn-selenium-web-drive-for-automation-testing-2f248c8fe6aa"><img alt="" src="https://cdn-images-1.medium.com/max/315/0*JC9Fw0VQz-H-k5eB.png" /></a></figure><p>The knowledge of how our system must work and the possibility to register and check it in an “automated way” can be useful when introducing new features/developments and we want to be sure to avoid regression problems. In addition to this, automated tests can be useful also if we want to simulate a load test.</p><p>One interesting approach can be to define application behavior, describing the interaction between the user and the browser. There are many frameworks and libraries we can use for these tests and <strong>BDD</strong> with <strong>Gherkin</strong> syntax, <a href="https://medium.com/javarevisited/cucumber-testcontainer-a-bdd-perfect-match-956cf62cdf47">as seen here</a>, can be a great solution to describe functionalities.</p><h3>Gherkin and the example project</h3><p>Let’s imagine our system has a frontend <strong>Angular</strong> application, which can invoke services from several backend endpoints (we don’t care about this). We will use an example login/registration project coming from <a href="https://jasonwatmore.com/post/2020/04/28/angular-9-user-registration-and-login-example-tutorial">this article</a> and it’s available inside <a href="https://github.com/fpaparoni/test-e2e">this Github repository</a> with all sources related to this article.</p><p>We want to describe some scenarios related to the user registration functionality</p><figure><a href="https://medium.com/javarevisited/my-favorite-free-courses-to-learn-selenium-web-drive-for-automation-testing-2f248c8fe6aa"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SgvnTYNFDN7J3AGY.png" /></a></figure><p>Gherkin syntax required to describe this sort of scenarios is pretty simple, as you can find from the next feature file, where we created 4 scenarios when registration doesn’t work and 1 where everything goes well</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fe4f0cb7c9ca52b2cc0b60fb9f2e5a0/href">https://medium.com/media/7fe4f0cb7c9ca52b2cc0b60fb9f2e5a0/href</a></iframe><h3>Selenium &amp; Cucumber test implementation</h3><p>As we said, there are a lot of tools to create e2e tests and in this article, we will use <a href="https://www.selenium.dev/">Selenium</a> and <a href="https://cucumber.io/">Cucumber</a>. <a href="https://medium.com/javarevisited/my-favorite-free-courses-to-learn-selenium-web-drive-for-automation-testing-2f248c8fe6aa"><strong>Selenium</strong></a>, an opensource project born in 2004, is often considered the de-facto standard framework for end-to-end web testing nowadays.</p><p>We can find a lot of projects and extensions related to Selenium and, despite its age, it’s a very useful and complete tool.</p><p>Our test project will use <a href="https://medium.com/javarevisited/top-7-courses-to-learn-selenium-for-java-and-c-developers-to-learn-automation-testing-free-and-e91637cd9622?source=---------19------------------">Selenium </a>to drive the browser, following the scenarios describe using Gherkin and executed by <a href="https://medium.com/javarevisited/top-7-courses-to-learn-selenium-for-java-and-c-developers-to-learn-automation-testing-free-and-e91637cd9622?source=---------19------------------">Cucumber</a>. Let’s add some <strong>Maven</strong> dependencies to our pom.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8282099be88b8c2d32cf0d7982aa8324/href">https://medium.com/media/8282099be88b8c2d32cf0d7982aa8324/href</a></iframe><p>Previously defined Gherkin scenarios will be saved within a feature file, used by Cucumber to drive the execution of the tests.</p><p>Now we can set up the Selenium engine, using a simple utility class that creates a <strong>WebDriver</strong> class instance. If we want to choose a specific browser, we must download into our environment its driver. In the following list, you can find browsers used in this project and the related env properties you must setup (also from the command line when you launch the final test program)</p><ul><li><strong>Chrome</strong> : <a href="http://chromedriver.chromium.org/">ChromeDriver</a> (webdriver.chrome.driver=path/to/the/driver)</li><li><strong>Firefox</strong>: <a href="https://github.com/mozilla/geckodriver/releases">GeckoDriver</a> (webdriver.gecko.driver=path/to/the/driver)</li></ul><p>Using <strong>test-browser</strong> env variable you can choose which browser to use, the default choice will be Chrome</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e9a9edbb79805d555b7b30228b4fa58/href">https://medium.com/media/0e9a9edbb79805d555b7b30228b4fa58/href</a></iframe><p>Adding <a href="https://javarevisited.blogspot.com/2021/04/junit-interview-questions-with-answers.html#axzz6w2HbPhVo"><strong>JUnit</strong> <strong>After</strong> annotation</a> we can choose something to do at the end of the single test execution. If our scenario is failed we save a screenshot from the browser, using Selenium, so we can later investigate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89844b8896e5e7c05605e1af2b7ea4d9/href">https://medium.com/media/89844b8896e5e7c05605e1af2b7ea4d9/href</a></iframe><p>The final step of our implementation is to use Selenium API to describe the interaction with the front-end application. You can write it from the scratch or you can also use <a href="https://www.selenium.dev/selenium-ide/"><strong>Selenium IDE</strong></a>, a browser plugin.</p><p>My favorite approach is to use Selenium IDE to create a draft version and then I can refactor it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cef9625f0f62a2ac73ddf64f3a00928a/href">https://medium.com/media/cef9625f0f62a2ac73ddf64f3a00928a/href</a></iframe><p>As you can see, our test implementation tries to replicate what is the user interaction with the browser. For example, when I want to be sure about the registration, I will check for the text “Registration successful” on the page.</p><h3>Playwright &amp; Cucumber test implementation</h3><p>Using the same feature file we can use another interesting tool: <a href="https://playwright.dev/"><strong>Playwright</strong></a>.</p><p>This is a <strong>Microsoft</strong> open-source project, providing a complete API to create end-to-end tests. There are multiple bindings of this project and here we will use the <a href="https://github.com/microsoft/playwright-java">Java implementation</a>.</p><p>Compared to <a href="https://javarevisited.blogspot.com/2020/08/top-5-courses-to-learn-selenium-for.html#axzz6oau61e3Q">Selenium </a>it’s a newer project, with interesting features and it’s probably more “compatible” with modern web applications but we have to evaluate the maturity of this project using it on some real implementations.</p><p>Let’s add the dependency to our pom.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8c28b21d7a2fdd4e3aaf670b62b3f8c/href">https://medium.com/media/a8c28b21d7a2fdd4e3aaf670b62b3f8c/href</a></iframe><p>Test case implementation will follow the same “schema” we used for Selenium. So we must define a test class to match Cucumber with Playwright</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0c57a0495758fd57296143003b5d608/href">https://medium.com/media/a0c57a0495758fd57296143003b5d608/href</a></iframe><p>there is also the definition of the Setup class, where we choose the browser and setup some parameters</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41e639ea57c944e93d52de42f3ee747d/href">https://medium.com/media/41e639ea57c944e93d52de42f3ee747d/href</a></iframe><p>Playwright doesn’t have as a prerequisite the browser driver installation because if it isn’t available Playwright will automatically download it during the first test execution.</p><p>In addition to this, we have a very interesting feature (not available in Selenium): <strong>video</strong> registration of our tests.</p><p>Finally, we have to implement the test cases using Playwright API (it seems a little bit readable compared to Selenium, but it is a personal point of view)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0749fce21ad06201cbf012d07023caff/href">https://medium.com/media/0749fce21ad06201cbf012d07023caff/href</a></iframe><p>We can now manage the failed test execution using the Playwright feature to record the video. If the scenario is failed we can add this <strong>WebM</strong> video to the Cucumber report</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98b4b441232570ed5af4a13356ea8b99/href">https://medium.com/media/98b4b441232570ed5af4a13356ea8b99/href</a></iframe><h3>Let’s start testing</h3><p>We must start the Angular application. You can enter the <strong>angular-9-registration-login-example</strong> folder, to create a <a href="https://medium.com/javarevisited/5-best-docker-courses-for-java-and-spring-boot-developers-bbf01c5e6542"><strong>Docker</strong> </a>image using the following command</p><p>docker build --no-cache -t bddfe .</p><p>and then you can start it</p><p>docker run -p 80:80 -t bddfe</p><p>If you point your browser to <a href="http://localhost/">http://localhost</a> you should see the application working. Now you can launch tests (remember to define <strong>webdriver.gecko.driver </strong>or<strong> webdriver.chrome.driver</strong> in your env or you must pass this additional parameter only for Selenium)</p><p>mvn install -Dtest-browser=firefox</p><p>You will see some “<em>browser windows dancing</em>” on your computer and, after the execution of the tests, you can control the results using <strong>Cucumber</strong> reports in the <strong>target/cucumber_reports/</strong> folder</p><figure><a href="https://javarevisited.blogspot.com/2019/05/top-5-courses-to-learn-docker-and-kubernetes-for-devops.html#axzz7DP5DDtxT"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PMeucwSJVmo_r0g0.png" /></a></figure><p>We used two different end-to-end test engines (Selenium and Playwright) with the same feature file so we will have two different Cucumber reports.</p><p>If we want to simulate an error we can change the check on the string “Registration successful” to “doh” e launch again the tests. In the Selenium report, we will see a screenshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4rAKLIjGTRjqZ3wDBl07tA.png" /></figure><p>and in Playwright we will have a video of our problem</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F777367770%3Fh%3Dc012a615ea%26app_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F777367770&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1559897866-9b387f616374c336f36a0c3f2faf5db27c1ec0fe9c7ef71ff74e2dc50f6f0af4-d_640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="800" height="450" frameborder="0" scrolling="no"><a href="https://medium.com/media/702be5bcc0e8bcb30399000d19c64b1e/href">https://medium.com/media/702be5bcc0e8bcb30399000d19c64b1e/href</a></iframe><h3>Conclusions</h3><p>Test project implementation used in this article shows the possibility to use a library to describe end-to-end tests (Cucumber) and other tools to simulate these test using a real browser driver (Selenium and Playwright).</p><p>These libraries also provide different language implementations, so you can recreate this mashup also using <a href="https://medium.com/javarevisited/top-10-free-typescript-courses-to-learn-online-best-of-lot-44bce9da41d1">Typescript</a>, <a href="https://medium.com/javarevisited/7-best-python-online-courses-for-beginners-to-learn-programming-abe12cecb1ad">Python </a>or <a href="https://medium.com/javarevisited/5-best-c-c-sharp-programming-courses-for-beginners-in-2020-494f7afc7a5c">C#</a>.</p><p>Inside this <a href="https://github.com/fpaparoni/test-e2e">repository</a> you can find the source code related to this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=928af278e789" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/end-to-end-testing-with-cucumber-playwright-and-selenium-928af278e789">End to end testing with Cucumber, Playwright and Selenium</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cucumber & Testcontainer: a BDD perfect match]]></title>
            <link>https://medium.com/javarevisited/cucumber-testcontainer-a-bdd-perfect-match-956cf62cdf47?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/956cf62cdf47</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[testcontainer]]></category>
            <category><![CDATA[bdd]]></category>
            <category><![CDATA[cucumber]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 22:18:03 GMT</pubDate>
            <atom:updated>2022-06-06T08:38:21.373Z</atom:updated>
            <content:encoded><![CDATA[<p>In some project, the need of an automated and powerful test layer is seen as something not really useful for the good outcome of the project…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*Cg_3CmTx8Zi-NI82.jpeg" /></figure><p>Luckily, there are many projects where the test phase is significant, with proven positive consequences for the general quality of the source code. We have so many frameworks, libraries and methodologies to use. In this article, we will see how the use of two tools, <strong>Cucumber</strong> and <strong>Testcontainer</strong>, helps us to create a perfect environment for our tests.</p><h3>Behavior Driven Design</h3><p>Different types of tests can be performed on our software, and obviously, each of these can be implemented with different techniques and tools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*EE_f6HgQZMl_7GMY.png" /></figure><p>A famous approach is <strong>TDD</strong> (Test Driven Design) which can be summarized (really shortly) by defining a test case for our software and then implementing software that satisfies it. The test flow will be the following</p><ul><li>Test definition</li><li>Test implementation</li><li>Test execution : first execution will fail, because our software doesn’t satisfy it</li><li>Software implementation</li><li>Test execution without problems</li></ul><p>Another great approach in test development is <strong>BDD</strong> (Behavior Driven Design). In that case, we must define, using a simple domain-specific language, the desired behavior of our software.</p><p>To define a test scenario, we can use a simple language based on the keywords <strong>Given When Then</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FMTTpGA21RYlhNPOvu7oGw.png" /></figure><p>A simple scenario can be the following one</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/480a909ad74591c30105652f228180d6/href">https://medium.com/media/480a909ad74591c30105652f228180d6/href</a></iframe><p>This language syntax (<a href="https://cucumber.io/docs/gherkin/"><strong>Gherkin</strong></a>) helps us define scenarios that can describe the behavior of our system. Test frameworks, like <strong>Cucumber</strong>, read this feature’s description and try to execute it.</p><h3>Cucumber: setup</h3><p><a href="https://cucumber.io/">Cucumber</a> is a test framework available for the most important programming languages. Using it we can map a feature description written in Gherkin to some test code implementations.</p><p>This article will use <strong>Cucumber-JVM</strong>, in a <strong>Spring Boot</strong> project with <strong>JUnit 5</strong> as principal test engine. The first thing we can see is the dependencies to add in our pom.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9445173d5d9a3f283174ad08d1dceb26/href">https://medium.com/media/9445173d5d9a3f283174ad08d1dceb26/href</a></iframe><p>The <a href="https://github.com/fpaparoni/bddfun">example project</a> will provide simple <strong>REST</strong> endpoints to manage two resources related to a blog engine: authors and posts. Let’s define some scenarios that our API will satisfy using the Gherkin language.</p><p>Some scenarios in a first feature file about author resource</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b604a335786e4fca9181df637b92231/href">https://medium.com/media/8b604a335786e4fca9181df637b92231/href</a></iframe><p>and some others related to post resource</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4878d6b5c1ae576c563f2bf2ef987e6d/href">https://medium.com/media/4878d6b5c1ae576c563f2bf2ef987e6d/href</a></iframe><p>Now we must start telling our project it must use Cucumber, and the scenario definitions will be available under the <strong>src/test/resources/bdd</strong> folder</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33f767badacc2083d7ea98658f9d1491/href">https://medium.com/media/33f767badacc2083d7ea98658f9d1491/href</a></iframe><p><strong>@IncludeEngines</strong> annotation is to specify the Cucumber engine for our tests and <strong>@SelectClasspathResource</strong> must be used to add our feature files.</p><p>Among the other settings, using <strong>@ConfigurationParameter,</strong> we ask Cucumber to produce an HTML test execution report.</p><p>If we start the build now, without any source definitions, we should receive an error like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11a4dc5fac249e6fd8efe6bdf0683a7b/href">https://medium.com/media/11a4dc5fac249e6fd8efe6bdf0683a7b/href</a></iframe><p>We can start with implementing the test cases, but before doing it, let’s look at <a href="https://rest-assured.io/"><strong>REST Assured</strong></a>, a powerful library that can be our swiss army knife for the test cases implementation.</p><h3>REST Assured</h3><p>If you must develop all the test cases using some Java libraries, like <strong>Spring RestTemplate</strong>/<strong>WebClient</strong> or something else, you will probably create a lot of boilerplate code.<a href="https://rest-assured.io/"><strong> REST Assured </strong></a>offers a fluent syntax to develop powerful but simple test code implementations.</p><p>To add the library you must import these dependencies</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5acca7b6081f985d79a967d470ffdde/href">https://medium.com/media/b5acca7b6081f985d79a967d470ffdde/href</a></iframe><p>Imagine you have a “colors” REST endpoint, providing a list of colors like this</p><pre>[&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;]</pre><p>using REST Assured you write a simple test case like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea8c8649739c999e97abdf0b7e5f0542/href">https://medium.com/media/ea8c8649739c999e97abdf0b7e5f0542/href</a></iframe><p>or if you want to submit something, in a scenario similar to our test project, you can write this test case</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ade231f0602b76bba39c94f1cec71cb3/href">https://medium.com/media/ade231f0602b76bba39c94f1cec71cb3/href</a></iframe><p>Its fluent API can be used to develop quick test cases like these or, as in our project, to bind these methods to our test scenarios.</p><h3>Cucumber: test implementation</h3><p>We can start our test cases implementation with some common steps</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/301abe4b0f17d39b6d1b493dc70711c3/href">https://medium.com/media/301abe4b0f17d39b6d1b493dc70711c3/href</a></iframe><p>This class is in the package that Cucumber will scan to find the step implementations, as previously defined in our setup. As you can see, <strong>@Then</strong> annotations are bounded to <strong>Then</strong> keywords described in some scenarios.</p><p>In addition to this, we created an utility class, <strong>CucumberContextHolder</strong>, that can be useful saving some test context information. Now we are using it to keep the response from REST Assured calls.</p><p>In these steps, we are simply checking the HTTP status code. Now we go further to the other actions defined in this scenario</p><pre>Scenario: 001 - Save author OK</pre><pre>   Given a username &#39;federico&#39;<br>   And an email &#39;federico.paparoni@xyz.mail&#39;<br>   And a bio &#39;Federico Paparoni wants to write something about Cucumber &amp; Testcontainer&#39;<br>   When I submit this information to save a new user<br>   Then I receive a correct response</pre><p>and this is the implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6610262a8f34d69ae11e0b5c06068954/href">https://medium.com/media/6610262a8f34d69ae11e0b5c06068954/href</a></iframe><p>In these steps we are creating an author (Given steps) and then sending it to the REST endpoint using REST Assured (When step).</p><p>Using the same approach we can implement all the steps, also trying to build something that isn’t available in our system. For example this step</p><pre>Given a system without the author with username &#39;goofy&#39;</pre><p>requires an author already saved in our blog engine. So we can suppose that our database already has this author, or we can save it during the setup of the Given step. I prefer the latter choice, so I implemented this condition in that way</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc9c86bbb0c54e120d67dd5a17cc1d87/href">https://medium.com/media/fc9c86bbb0c54e120d67dd5a17cc1d87/href</a></iframe><p>Gherkin syntax offers a lot of features like the option to insert list of values in the scenario (<a href="https://github.com/cucumber/cucumber-jvm/tree/main/datatable">DataTables</a>). If you have repeated steps like these</p><pre>Feature: My feature</pre><pre>   Scenario: 001<br>      Given a username &#39;federico&#39;<br>      And an email &#39;federico.paparoni@xyz.mail&#39;<br>      And a bio &#39;Federico Paparoni wants to write something about Cucumber &amp; Testcontainer&#39;</pre><pre>...<br>...</pre><pre>   Scenario: 002<br>      Given a username &#39;federico&#39;<br>      And an email &#39;federico.paparoni@xyz.mail&#39;<br>      And a bio &#39;Federico Paparoni wants to write something about Cucumber &amp; Testcontainer&#39;</pre><pre>...<br>...</pre><pre>   Scenario: 003<br>      Given a username &#39;federico&#39;<br>      And an email &#39;federico.paparoni@xyz.mail&#39;<br>      And a bio &#39;Federico Paparoni wants to write something about Cucumber &amp; Testcontainer&#39;</pre><pre>...<br>...</pre><p>you can use the <strong>Background</strong> keyword</p><pre>Feature: Posts</pre><pre>Background: Author already saved<br>   Given an author with username &#39;federico&#39; already saved<br>   And a post by author with username &#39;federico&#39; already saved</pre><pre>...<br>...</pre><p>These steps will map to Java methods as the previous seen, but Cucumber will repeat it for every scenario of a single feature</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b539c2e14e9b191b821467e5674f2994/href">https://medium.com/media/b539c2e14e9b191b821467e5674f2994/href</a></iframe><h3>Testcontainer</h3><p>Once you create tests with Cucumber, you can use a database like <strong>H2</strong>, but you won’t realize something more sophisticated than a Hello World. In an actual project, you will probably use some particular database feature (relational or not relational), so your test case will not work in a realistic environment.</p><p><a href="https://www.testcontainers.org/"><strong>Testcontainer</strong></a> provide us a simple way to use containers inside our tests, so we can integrate with a database, a browser, a queue messaging system or everything that can be placed in a container.</p><p>In this article we will use Testcontainer to start a <strong>PostgreSQL</strong> database, defined by this <strong>Dockerfile</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/148aa2a46f473426540b6b0f5cb67c0b/href">https://medium.com/media/148aa2a46f473426540b6b0f5cb67c0b/href</a></iframe><p>We wrote also some scripts to create some tables for our blog engine software. To start build you can launch the following command</p><pre>docker build -t bddfun-database .</pre><p>Now we can add Testcontainer to our project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74e2ab26e79719c07a050d4a19379d79/href">https://medium.com/media/74e2ab26e79719c07a050d4a19379d79/href</a></iframe><p>To launch Testcontainer, we can use three different approaches. The simplest is to use a particular <strong>JDBC URL</strong> that will trigger a kind of magic in the JDBC <strong>DriverManager</strong>, and without so much effort, we will have a running instance of PostgreSQL</p><pre>spring.datasource:<br>  url: jdbc:tc:postgresql:14.3:////&lt;DatabaseName&gt;<br>  driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver</pre><p>This instance will be a plain one, so we must manage scripts in our codebase and launch them. Another approach is <strong>@Testcontainers</strong> and <strong>@Container</strong> annotations</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db1cd4e6f13304cdad1c8f6f8376bc7f/href">https://medium.com/media/db1cd4e6f13304cdad1c8f6f8376bc7f/href</a></iframe><p><strong>@DynamicPropertySource</strong> will dynamically save the database properties in our context, and we will have a different PostgreSQL, which will start from our <strong>bddfun-database</strong> container, running for every single test.</p><p>It can be helpful to have a completely new database for every single test, but for a project with many test cases it can extend the build time too much.</p><p>The last option, chosen for this article, will provide us a complete start/stop control of a container for our tests</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0de154f55f38271407f86ba5e82dac76/href">https://medium.com/media/0de154f55f38271407f86ba5e82dac76/href</a></iframe><p>Using this approach we also applied the <strong>@CucumberContextConfiguration</strong> to this class, so Cucumber knows that this will be the context used for our tests. Our project is using Spring Boot so we also added <strong>@SpringBootTest</strong> annotation.</p><p>This configuration gives us a single instance of our custom database, managed by the methods with <strong>@BeforeAll</strong> and <strong>@AfterAll</strong> Cucumber annotations (similar to JUnit).</p><p>Now running the build, if we also remember to develop the REST endpoints of our blog software (!!!), we should have the following report (<strong>cucumber-reports.html</strong>) generated under <strong>target</strong> folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/0*evk5OF_qCAgP578h.png" /></figure><h3>Bonus track: Mockito</h3><p>Our system will probably be something more sophisticated than a simple Spring Boot application using a database, so we must suppose our test cases should provide an easy way to mock external system.</p><p>If we have a container of our external system we can use Testcontainer, but sometimes this approach can lead to a lot containers running in our build (many containers, lot of memory, huge building time..).</p><p><a href="https://site.mockito.org/"><strong>Mockito</strong></a> is a testing framework and can be integrated in this testing scenario with Cucumber and Spring Boot. If we want to mock a service we can do it with the @MockBean annotation</p><pre>@MockBean<br>private MyRemoteService myRemoteService;</pre><p>This mock must be placed in the same class where we put @CucumberContextConfiguration, so Cucumber will know we are using a mock for this service.</p><p>Later in our test we can mock the service</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c29be80275f9cf2270e494c3e65fc370/href">https://medium.com/media/c29be80275f9cf2270e494c3e65fc370/href</a></iframe><h3>Example project</h3><p>Source code of this article can be found in this <a href="https://github.com/fpaparoni/bddfun">Github repository</a></p><p><a href="https://github.com/fpaparoni/bddfun">GitHub - fpaparoni/bddfun</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=956cf62cdf47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/cucumber-testcontainer-a-bdd-perfect-match-956cf62cdf47">Cucumber &amp; Testcontainer: a BDD perfect match</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tracing in Spring Boot with OpenTracing/OpenTelemetry]]></title>
            <link>https://medium.com/swlh/tracing-in-spring-boot-with-opentracing-opentelemetry-dd724134ca93?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd724134ca93</guid>
            <category><![CDATA[tracing]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <category><![CDATA[opentracing]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Fri, 22 Jan 2021 16:37:09 GMT</pubDate>
            <atom:updated>2021-11-08T11:09:32.616Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*s2Pv7PXNtRfUInPKZf5_zg.png" /><figcaption>Photo by <a href="https://www.flickr.com/photos/61423903@N06/">FutUndBeidl</a></figcaption></figure><p>Distributed systems require something to trace what is happening inside a software architecture, useful for a lot of things (first of all troubleshooting).</p><p>If our system is composed of a lot of microservices, it’s important to understand if a specific service has performance issues that can be critical for the whole architecture. Generally speaking, a <strong>Trace</strong> is the representation of a connected operations sequence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*_CPPcMKMu7XUWiHYvAPlWQ.png" /></figure><p>Inside every <strong>Trace</strong> we find a list of <strong>Span</strong>, the abstraction related to a single command inside our architecture. Every Span can contain additional data that can be useful to better describe what is happening (start/end date, log, tag).</p><p>According to these general concepts there are a lot of different implementations that can be used. <a href="https://opentracing.io/"><strong>OpenTracing</strong></a> is an API definition of this concepts and can used if we don’t want to be bound to a specific implementation/vendor/tool.</p><p>OpenTracing and <a href="https://opencensus.io/"><strong>OpenCensus</strong></a> projects have merged to form <a href="https://opentelemetry.io/"><strong>OpenTelemetry</strong></a>, <a href="https://www.cncf.io/">CNCF</a> project that will probably be the most used reference API for tracing in the next future. These API are really similar and in this article we will use both with two Spring Boot sample projects.</p><h3>Jaeger</h3><p>There are many possible tracing implementations, in this article we use <a href="https://www.jaegertracing.io/"><strong>Jaeger</strong></a>, <strong>CNCF</strong> project initially developed by <strong>Uber</strong>. One of the possible architecture that can be used in Jaeger is shown in the following image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*UKRDDvjdKuOCoV34bke5wA.png" /></figure><p>A client inside our application send traces/spans to a collector, which saves it in a database. Finally we have graphical UI to search amoung the stored data.</p><p>To quickly launch a local Jaeger enviroment, we use <a href="https://hub.docker.com/r/jaegertracing/all-in-one">jaegertracing/all-in-one</a> Docker image, which includes all the components required by our examples.</p><h3>Example architecture</h3><p>In this article we have a simple interaction between three components, two applications and a database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*zk0e9YAfRLr_Kosr1uDEwg.png" /></figure><p>Application A expose a HTTP service, which call another HTTP service exposed from Application B. Finally there is query to a DB.</p><h3>OpenTracing</h3><p>The example applications use <strong>Spring Boot</strong>, so we can add to our project a <strong>starter</strong> which enables OpenTracing/Jaeger without doing so much.</p><p>We must add the following dependency to <strong>pom.xml</strong></p><pre>&lt;dependency&gt;<br> &lt;groupid&gt;io.opentracing.contrib&lt;/groupid&gt;<br> &lt;artifactid&gt;opentracing-spring-jaeger-cloud-starter&lt;/artifactid&gt;<br> &lt;version&gt;3.2.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>Thanks to this dependency our applications are automatically instrumented with a OpenTracing agent, that will create traces/spans related to internal operations (app, db, cache etc. etc.).</p><p>In addition to this we can set some <strong>properties</strong> to specify application name and Jaeger endpoint</p><pre>opentracing:<br>  jaeger:<br>    service-name: OpenTracingAppA<br>    enabled: TRUE<br>    udp-sender:<br>      host: jaeger</pre><p>The application A make a simple HTTP call and then a database query (in memory H2). You can see the simple code in the <a href="https://github.com/fpaparoni/tracing">github project</a>. There is only a specific reference to tracing API, because I added a simple portion of code that can be useful to programmatically add traces/spans</p><pre>Tracer tracer = GlobalTracer.get();<br>Tracer.SpanBuilder spanBuilder = tracer.buildSpan(&quot;CustomSpan&quot;)<br>        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);<br> <br>Span span = spanBuilder.start();<br>Tags.COMPONENT.set(span, &quot;AppAController&quot;);<br>span.setTag(&quot;testtag&quot;, &quot;test&quot;);<br>span.finish();</pre><h3>OpenTelemetry</h3><p>For the <strong>OpenTelemetry</strong> example we will have two similar project, but without any dependency. We will set an OpenTelemetry agent to the start of application, as reported in the <strong>Dockerfile</strong></p><pre>FROM openjdk:11-jre<br>RUN mkdir -p /app/bin<br>COPY ./target/opentelemetry-app-b.jar /app/bin<br>COPY opentelemetry-javaagent-all.jar /app/bin<br>CMD java -Dotel.exporter=jaeger \<br>         -Dotel.exporter.jaeger.endpoint=jaeger:14250 \<br>         -Dotel.exporter.jaeger.service.name=OpenTelemetryAppB \<br>         -Dapplication.home=/app/bin/ \<br>         -Dapplication.name=OpenTelemetryAppB \<br>         -javaagent:/app/bin/opentelemetry-javaagent-all.jar \<br>         -jar \<br>         /app/bin/opentelemetry-app-b.jar</pre><p>Parameters specify Jaeger host and our application name, as we did in the previous example for OpenTracing using a property file.</p><h3>Let’s trace</h3><p>Now using a <strong>docker-compose</strong> file we will start all our example applications</p><pre>version: &quot;3.6&quot;<br>services:<br>  jaeger:<br>    image: jaegertracing/all-in-one<br>    ports:<br>      - 5775:5775/udp<br>      - 6831:6831/udp<br>      - 6832:6832/udp<br>      - 5778:5778<br>      - 16686:16686<br>      - 14268:14268<br>      - 14250:14250<br>      - 9411:9411<br> <br>  opentracing-app-b:<br>     build: opentracing-app-b<br>     ports:<br>      - 8081:8081<br> <br>  opentracing-app-a:<br>     build: opentracing-app-a<br>     ports:<br>      - 8080:8080<br> <br>  opentelemetry-app-b:<br>     build: opentelemetry-app-b<br>     ports:<br>      - 9082:9082<br> <br>  opentelemetry-app-a:<br>     build: opentelemetry-app-a<br>     ports:<br>      - 9081:9081</pre><p>To launch the whole example you can execute <strong>build.sh</strong> script, which build projects and then start them using docker-compose. Once started you can browse to the following url to register some traces</p><p><a href="http://localhost:8080/test-tracing">http://localhost:8080/test-tracing</a> (OpenTracing)</p><p><a href="http://localhost:9081/test-tracing">http://localhost:9081/test-tracing</a> (OpenTelemetry)</p><p>Finally you can go to Jaeger UI <a href="http://localhost:16686/search">http://localhost:16686/search</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wfcdEbooX7I2G9-rctu_dw.png" /></figure><p>There are a combo list with services and using the search we can see the traces related to a specific service, with a quick overview that tell us also the response time of traces. If want to see the details of a trace we can click on it.</p><p>This is the OpenTracing example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*t5GJoTYJzCrahagB9frpuQ.png" /></figure><p>and the OpenTelemetry one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouYjfDSMV87j9k235tM_XQ.png" /></figure><h3>Conclusion</h3><p>Informations stored in traces/spans can be really useful, also because in these example projects we didn’t use specific code (except for custom span). We can have a very good level of details about a specific operation, as you can see from OpenTelemetry screenshot which reported all the app/classes involved in the call.</p><p>It is better to use the agent, because doing so we haven’t nothing in our project related to a specific API/Exporter and we can change the implementation in the future without any change to our codebase.</p><p>In <a href="https://opentelemetry.io/">OpenTelemetry</a> website we can see there are already implemented Exporters for opensource project (<strong>Jaeger</strong>, <strong>Zipkin</strong>, <strong>Prometheus</strong>), main cloud provider (<strong>AWS</strong>, <strong>Azure</strong>, <strong>Google</strong>) and also some famous monitoring service (<strong>Datadog</strong>, <strong>New relic</strong>).</p><p><a href="https://github.com/fpaparoni/tracing">fpaparoni/tracing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd724134ca93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/tracing-in-spring-boot-with-opentracing-opentelemetry-dd724134ca93">Tracing in Spring Boot with OpenTracing/OpenTelemetry</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuration with Spring Cloud Kubernetes]]></title>
            <link>https://faun.pub/configuration-with-spring-cloud-kubernetes-1e73d404b340?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e73d404b340</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[configmap]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-cloud-kubernetes]]></category>
            <category><![CDATA[spring-cloud]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 17:39:58 GMT</pubDate>
            <atom:updated>2021-01-23T20:00:34.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQOg-gOysLsaIWhfIVAbPQ.jpeg" /><figcaption>Spring Cloud Kubernetes</figcaption></figure><p>Every application needs a configuration, usually on a separated property file that can be read at runtime and this configuration probably changes with the environment. Also, cloud native applications need configurations and in this article, we will see how to use Kubernetes ConfigMap to provide this sort of configuration to our Spring application</p><h3>Kubernetes Configmap</h3><p>In Kubernetes, we have <strong>ConfigMap</strong>, a native component useful to manage configurations. ConfigMap enables us to separate configurations from Pod (and obviously from our application). Data contained in ConfigMap can be injected in the definition of the Pod using different strategies, for example, we can see it as environment variables. In the following example, we can see the creation of a ConfigMap, using a properties file as a source.</p><pre>federico@test:~$ kubectl create configmap test --from-file=configmap.properties <br>configmap/test created<br>federico@test:~$ kubectl describe configmaps test<br>Name:         test<br>Namespace:    default<br>Labels:       &lt;none&gt;<br>Annotations:  &lt;none&gt;</pre><pre>Data<br>====<br>configmap.properties:<br>----<br>myconfig.properties1=First property<br>myconfig.properties2=Second property<br>myconfig.subconfig.properties1=First sub property<br>myconfig.subconfig.properties2=Second sub property<br>Events:  &lt;none&gt;</pre><p>Now we can use these properties from our Pod</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: test-configmap-pod<br>spec:<br>  containers:<br>    - name: test-container<br>      image: k8s.gcr.io/busybox<br>      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;env&quot; ]<br>      env:<br>        - name: MYCONFIGMAP_INFORMATION<br>          valueFrom:<br>            configMapKeyRef:<br>              name: test<br>              key: configmap.properties<br>  restartPolicy: Never</pre><p>Once the Pod started, it will see MYCONFIGMAP_INFORMATION among the environment variables and it will contain the data of configmap.properties.</p><h3>Fabric8</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*oeNBhRAXZ02-KLhe" /><figcaption>Fabric8</figcaption></figure><p>We can see the ConfigMap data from the command line tool <strong>kubectl</strong> or using libraries that access through <strong>Kubernetes API</strong>. There is a <a href="https://github.com/fabric8io/kubernetes-client">famous Java client library</a> provided by <a href="http://fabric8.io/"><strong>Fabric8</strong></a>, that can be used to read configuration data from ConfigMap. In the next example, you can see a simple Java class reading from ConfigMap</p><pre>import org.slf4j.Logger;<br>import org.slf4j.LoggerFactory;</pre><pre>import io.fabric8.kubernetes.api.model.ConfigMap;<br>import io.fabric8.kubernetes.api.model.DoneableConfigMap;<br>import io.fabric8.kubernetes.client.Config;<br>import io.fabric8.kubernetes.client.ConfigBuilder;<br>import io.fabric8.kubernetes.client.DefaultKubernetesClient;<br>import io.fabric8.kubernetes.client.KubernetesClient;<br>import io.fabric8.kubernetes.client.dsl.Resource;<br>/**<br> * Example read ConfigMap using Fabric8 library<br> *<br> */<br>public class Fabric8Example {<br>  private static final Logger logger = LoggerFactory.getLogger(Fabric8Example.class);</pre><pre>public static void main(String[] args) throws InterruptedException {<br>    Config config = new ConfigBuilder().build();<br>    KubernetesClient client = new DefaultKubernetesClient(config);<br>    String namespace = &quot;default&quot;;<br>    String name = &quot;test&quot;;<br>    try {<br>      Resource&lt;ConfigMap, DoneableConfigMap&gt; configMapResource = <br>        client.configMaps().inNamespace(namespace).withName(name);<br>      ConfigMap configMap=configMapResource.get();<br>      logger.info(configMap.getData().toString());<br>    } finally {<br>      client.close();<br>    }<br>  }<br>}</pre><p>This library can also be used to write additional properties to the ConfigMap and many other utilities related to the Kubernetes environment. You can read the official documentation at the URL <a href="https://github.com/fabric8io/kubernetes-client">https://github.com/fabric8io/kubernetes-client</a></p><h3>Spring Cloud Kubernetes</h3><p><strong>Spring Cloud Kubernetes</strong> is an implementation of <strong>Spring Cloud</strong> abstraction and makes it possible to manage Kubernetes native component. This implementation also uses the previously seen Fabric8 client library to bring Kubernetes features in the <em>Spring Cloud world</em>.</p><p>In the official documentation, available at <a href="https://github.com/spring-cloud/spring-cloud-kubernetes">https://github.com/spring-cloud/spring-cloud-kubernetes</a>, you can find a lot of features that can be used with this Spring starter, but in this article, we will see only the part related to <strong>ConfigMap</strong>, so now we will define a <strong>Spring Boot</strong> project with the necessary dependencies</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;<br>&lt;project xmlns=&quot;<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>&quot;<br> xmlns:xsi=&quot;<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br> xsi:schemaLocation=&quot;<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <a href="http://maven.apache.org/xsd/maven-4.0.0.xsd">http://maven.apache.org/xsd/maven-4.0.0.xsd</a>&quot;&gt;<br> &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br> &lt;groupId&gt;com.javastaff.spring&lt;/groupId&gt;<br> &lt;artifactId&gt;k8config&lt;/artifactId&gt;<br> &lt;version&gt;1.0&lt;/version&gt;<br> &lt;description&gt;example project for spring properties on kubernetes&lt;/description&gt;</pre><pre>&lt;parent&gt;<br>  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>  &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>  &lt;version&gt;2.1.6.RELEASE&lt;/version&gt;<br> &lt;/parent&gt;</pre><pre>&lt;properties&gt;<br>  &lt;java.version&gt;1.8&lt;/java.version&gt;<br> &lt;/properties&gt;</pre><pre>&lt;dependencies&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;<br>   &lt;scope&gt;runtime&lt;/scope&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-cloud-starter-kubernetes-config&lt;/artifactId&gt;<br>   &lt;version&gt;1.0.2.RELEASE&lt;/version&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>   &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;<br>   &lt;artifactId&gt;lombok&lt;/artifactId&gt;<br>  &lt;/dependency&gt;<br> &lt;/dependencies&gt;<br>&lt;/project&gt;</pre><p>It is a Spring Cloud application and we can define the bootstrap.yml file, where we can specify where Spring Cloud Kubernetes can retrieve our ConfigMap</p><pre>management:<br>  endpoint:<br>    restart.enabled : true<br>    health.enabled : true<br>    info.enabled : true</pre><pre>spring:<br>  application:<br>    name: k8config<br>  cloud:<br>    kubernetes:<br>      reload:<br>        period: 1000<br>        enabled: true<br>      config:<br>        enabled: true<br>        name: k8config<br>        namespace: default<br>        sources:<br>         - name: myk8config</pre><p>Using this configuration Spring Cloud Kubernetes will read the ConfigMap named <strong>myk8config</strong> from the default namespace. The information available in the ConfigMap will be injected as properties in the Spring context and the properties will be also updated if something changes it (<strong>spring.cloud.kubernetes.reload.enabled=true</strong>).</p><p>In our SpringBoot application, we defined an object mapped with @ConfigurationProperties, so if there is a similar hierarchy in the properties we will have this object populated.</p><pre>package com.javastaff.spring.k8config;</pre><pre>import java.io.Serializable;</pre><pre>import org.springframework.boot.context.properties.ConfigurationProperties;<br>import org.springframework.context.annotation.Configuration;</pre><pre>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.NoArgsConstructor;</pre><pre>@Configuration<br>@ConfigurationProperties(prefix = &quot;myconfig&quot;)<br>@Data @AllArgsConstructor @NoArgsConstructor<br>public class Config implements Serializable{</pre><pre>private static final long serialVersionUID = -8900976432592584351L;<br> private String properties1;<br> private String properties2;<br> private SubConfig subconfig;<br>}</pre><p>Finally, there is a REST endpoint with a GET mapping that returns debug informations about our properties</p><pre>package com.javastaff.spring.k8config;</pre><pre>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RestController;</pre><pre>@RestController<br>public class TestConfigController {<br> <br> @Autowired<br> private Config config;<br> <br> @Value(&quot;${single.property}&quot;) <br> private String singleProperty;<br> <br>    @GetMapping<br>    public String load() {<br>     StringBuilder sb=new StringBuilder();<br>     sb.append(&quot;single.property : &quot;)<br>       .append(singleProperty)<br>       .append(&quot; ----- &quot;)<br>       .append(&quot;config: &quot;)<br>       .append(config.toString());<br>        return sb.toString();<br>    }<br>}</pre><p>If you start the Spring Boot project and browse to <a href="http://localhost:8080/">http://localhost:8080</a> you will see the ConfigMap data. In the <a href="https://github.com/fpaparoni/spring-cloud-configmap">Github project</a>, you can find the sources of this simple example.</p><p>Have fun with Spring Cloud Kubernetes :)</p><p><a href="https://github.com/fpaparoni/spring-cloud-configmap">fpaparoni/spring-cloud-configmap</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p>👋 <a href="https://faun.dev/join"><strong>Join FAUN today and receive similar stories each week in your inbox!</strong></a><strong> </strong>️ <strong>Get your weekly dose of the must-read tech stories, news, and tutorials.</strong></p><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬</p><figure><a href="https://www.faun.dev/join?utm_source=medium.com/faun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cT0_laE4iPcqW1qrbstAg.gif" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e73d404b340" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/configuration-with-spring-cloud-kubernetes-1e73d404b340">Configuration with Spring Cloud Kubernetes</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Weekly check for Lambda functions]]></title>
            <link>https://fpaparoni.medium.com/weekly-check-for-lambda-functions-67f65293598?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/67f65293598</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Sun, 20 May 2018 09:48:33 GMT</pubDate>
            <atom:updated>2018-05-20T13:02:07.466Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNjyHDXlfh_ZeojiQtjG6A.jpeg" /><figcaption><a href="https://www.pexels.com/photo/gray-and-black-mixer-164907/">Photo by Pixabay from Pexels</a></figcaption></figure><p>When you use AWS Lambda functions, among different regions, for different projects, you will probably run out of control. Keep track of the resources on the AWS platform can be difficult and Lambda functions are one of these resources.</p><p>Some time ago I read <a href="https://medium.com/epsagon/the-curse-of-dead-lambda-functions-228bf812c10a">this interesting article</a> from <a href="https://medium.com/@nitzanshapira">Nitzan Shapira</a>, where you can find a useful script to collect informations about the execution of your Lambda functions, using the log streams all over the regions. I modify this script to create a Lambda function (another?!?!) that can send these informations by email on a scheduled check</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKoHrChL9Yi22tHgefzi1Q.png" /><figcaption>Weekly check for Lambda functions</figcaption></figure><p>I setup a CloudWatch Event rule to trigger every Friday at twelve o’clock</p><blockquote><strong>cron(0 12 ? * FRI *)</strong></blockquote><p>then I simply modified the original script to create an HTML table with data collected from log streams, using <a href="https://www.decalage.info/python/html">HTML.py</a>. Then using <a href="https://aws.amazon.com/ses/">Amazon SES</a> these informations can be sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*-cQn8HtLnynQod1Eb-1abA.png" /></figure><p>If you want to use or if you want to get your hands dirty with this script, you can find it in the following Github repository</p><p><a href="https://github.com/fpaparoni/list-lambdas/">fpaparoni/list-lambdas</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67f65293598" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NodeJS URL shortener with Azure Function, CosmosDB and Azure Function Proxies]]></title>
            <link>https://fpaparoni.medium.com/nodejs-url-shortener-with-azure-function-cosmosdb-and-azure-function-proxies-e0188ebf2427?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0188ebf2427</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[cosmosdb]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Tue, 17 Apr 2018 14:47:05 GMT</pubDate>
            <atom:updated>2018-04-17T14:47:05.309Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I show how to create a simple application to shorten URL, using CosmosDB and Azure Function. The architecture of this simple application is the following one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*MeM-jQozMKIwqYRr-4jaPA.png" /></figure><p>There are two main functionalities in this application</p><ul><li>Creation of a new short URL</li><li>Retrieve real URL address</li></ul><p>These two functionalities can be easily mapped to two Azure Functions, which writes/reads data from a data repository (<strong>Azure CosmosDB</strong>). Azure Function Proxy can be used in front of these functions, using a unique URL for this application and two different HTTP methods, <strong>GET</strong> and <strong>POST</strong>, to manage <strong>READ</strong> and <strong>CREATE</strong> function respectively.</p><h3><strong>CosmosDB setup</strong></h3><p>The CosmosDB setup is really simple because we need a single database with a single collection to manage these two functionalities. The collection will hold all the documents with the following data structure</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8810682deb02b6452d493faba3a6da/href">https://medium.com/media/ee8810682deb02b6452d493faba3a6da/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*10NJ4AhdsgGK38pgR2oWJw.png" /></figure><h3><strong>Create URL Function</strong></h3><p>After the creation of the Function App that contains our functions, we can start with the creation of “Create URL” function. This function receives the original URL, creates a shorter version of this URL, saves it on CosmosDB and returns the new short URL as response. The code of this function is the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b78230ef0d65b4c0f3e3c6b8305d566/href">https://medium.com/media/0b78230ef0d65b4c0f3e3c6b8305d566/href</a></iframe><p>The main module function receives context and request. Using the <a href="https://www.npmjs.com/package/shortid"><strong>shortid</strong></a> npm module we generate a unique short URL, put it in a data structure with original URL and try to insert it in our CosmosDB collection.</p><p>As you can see from <strong>processResponse</strong> function, if everything goes well we generate a 200 response code but if we find a duplicate key (difficult but possible) we generate another id and try another insert.</p><p>CosmosDB settings are stored as three different properties in the Azure Function configuration, so we can obtain them using the global variable <strong>process.env</strong> .</p><h3><strong>Read URL Function</strong></h3><p>The read function is really simple because we have to query CosmosDB using the URL parameter. If the address is available in the collection, we redirect the request to the original address, otherwise, we reply with an error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc256382de8b2411a505844862019400/href">https://medium.com/media/cc256382de8b2411a505844862019400/href</a></iframe><h3><strong>Proxy setup</strong></h3><p>The two functions that create and read short URLs can be tested with the function URL as you can see from the following cURL commands</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fce846e4ee82e9063c9299ec8ae540e2/href">https://medium.com/media/fce846e4ee82e9063c9299ec8ae540e2/href</a></iframe><p>We can expose these functions using a single URL with Azure Function Proxies. We create two different proxies, that use the same route but with different HTTP method so we can match two different functions. The GET method will call the read function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*-ShFmaA5Bp9SN_AY0HIhkQ.png" /></figure><p>and the POST will manage the creation of the new URL, using the POST data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*pYN2s9tdwpyZoBLApXpFiA.png" /></figure><p>Finally to test it you can create a new URL</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b5c31da8522a5f06531ffc5521156e5/href">https://medium.com/media/8b5c31da8522a5f06531ffc5521156e5/href</a></iframe><p>and retrieve the original one</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1990aecc621681a7ddeb5799c7ef469/href">https://medium.com/media/c1990aecc621681a7ddeb5799c7ef469/href</a></iframe><h3><strong>Conclusion</strong></h3><p>It’s a simple example, but it is useful to understand some tools we can use to build an application using the <strong>serverless</strong> way on the <strong>Azure</strong> platform. You can find the functions code in this <a href="https://github.com/fpaparoni/azure-url-shortener">git repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0188ebf2427" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello Cloud : a Serverless journey]]></title>
            <link>https://fpaparoni.medium.com/hello-cloud-a-serverless-journey-e4a5da225d7a?source=rss-4274d6128696------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4a5da225d7a</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[openwhisk]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <dc:creator><![CDATA[Federico Paparoni]]></dc:creator>
            <pubDate>Fri, 16 Mar 2018 15:59:15 GMT</pubDate>
            <atom:updated>2018-03-18T21:27:02.167Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>an alternative way to waste time and discover how to make a funny Serverless Hello World with 4 languages and 4 public cloud providers</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WU2L0jdHDrcNOg0pHdrZLQ.jpeg" /><figcaption><a href="https://www.pexels.com/photo/architecture-buildings-business-city-325185/">Photo by Aleksandar Pasaric from Pexels</a></figcaption></figure><p>Serverless (or FaaS) is the buzzword of the moment in IT world, so after reading various articles I started writing examples on different public cloud platforms. Each of these is giving away a free tier where you can play with a lot of services and, of course, you can find a sort of Serverless engine.</p><p>I don’t want to explain what Serverless is, where can be used and what could be the benefits of using this approach, but I simply want to see how the different type of Serverless engine, with several languages and trigger mechanism, can be used together.</p><h3><strong>The architecture of Hello Cloud</strong></h3><p>The starting point of this example is a GIT repository, which is monitored by an <a href="https://www.ibm.com/cloud/functions">IBM Cloud Function</a> trigger that receives every push event. From this Python function we make an HTTP POST request to a <a href="https://cloud.google.com/functions/">Google Cloud Function</a>, developed in Node.JS.</p><p>This script receives the information triggered by the HTTP request and create a new JSON file in an S3 bucket. The creation of a new file in S3 triggers an event, captured by an <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> Java function.</p><p>The content of this file is used to create a new Document in a CosmosDB collection and the final step is a C# <a href="https://azure.microsoft.com/en-en/services/functions/">Azure Function</a> triggered by a timer every five minutes, which check the items in the collection and send an email using SendGrid service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjmOO21ws-NGI0oxPYc3IQ.png" /><figcaption>Hello Cloud architecture</figcaption></figure><p>It’s a bit crazy flow but it’s useful to discover the different events integration available on the most famous public cloud providers. So let’s see how deep the rabbit hole goes…</p><h3><strong>IBM Cloud Function</strong></h3><p>IBM Cloud Function is based on <a href="https://openwhisk.apache.org/">Apache OpenWhisk</a> project and provides an interesting framework to create trigger/event/action. The action is where we insert our code and in this platform we can use JavaScript, Swift, Python, Java, PHP, Docker, Go and arbitrary executables to create action (for more details read <a href="https://console.bluemix.net/docs/openwhisk/openwhisk_actions.html#openwhisk_actions">this</a>).</p><p>There is already available a system utility, <a href="https://console.bluemix.net/docs/openwhisk/openwhisk_github.html#openwhisk_catalog_github">whisk.system/github</a>, that we can use to capture Github event. From the <a href="https://console.bluemix.net/docs/cli/reference/bluemix_cli/bx_cli.html#bluemix_cli">bx command line utility</a>, we create a package with this utility and our settings</p><pre>bx wsk package bind /whisk.system/github myGitCloud <br>    --param username GITHUB_USERNAME <br>    --param repository GITHUB_REPO <br>    --param accessToken GITHUB_ACCESS_TOKEN</pre><p>After the creation of the package, we can initialize a new trigger that will user push events from the utility</p><pre>bx wsk trigger create myGitTriggerCloud<br>     --feed myGitCloud/webhook <br>     --param events push</pre><p>It’s time to start coding, so let’s see a simple Python function that receives the <a href="https://developer.github.com/v3/activity/events/types/#pushevent">push event</a> and make an HTTP POST request to a Google Cloud Function using some data from the triggered event</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa2b74da3b4f9420c4ee0f90e7ad768c/href">https://medium.com/media/fa2b74da3b4f9420c4ee0f90e7ad768c/href</a></iframe><p>We can now upload this code to BlueMix, creating an action in our repository and a rule that will fire this action when the myGitTriggerCloud is called</p><pre>bx wsk action create helloCloud step1.py<br>bx wsk rule create gitPushCloud myGitTriggerCloud helloCloud</pre><h3><strong>Google Cloud Function</strong></h3><p>The Serverless solution provided by Google can be used to offer a service triggered by a simple HTTP request. We will use Node.JS because it is the only development runtime available in this platform (some other runtimes can be useful to have more choices). The code receives a request from the IBM Cloud Function with Github event and uploads a new JSON file into an S3 bucket</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7375736c0b7488f5bb87badf575b05b8/href">https://medium.com/media/7375736c0b7488f5bb87badf575b05b8/href</a></iframe><p>The function is simple and uses <a href="https://www.npmjs.com/package/s3fs">s3fs</a> module to upload the new file. In the end, we return the HTTP 200 status code so the caller can check if everything goes well. To upload this function to the Google platform, we can use the useful <a href="https://cloud.google.com/compute/docs/gcloud-compute/">gcloud compute</a> command-line tool from the directory with our Node.JS module</p><pre>gcloud beta functions deploy helloCloud — trigger-http</pre><p>And now also the Google part of this journey is completed</p><h3><strong>AWS Lambda</strong></h3><p>AWS Lambda is the most mature Serverless platform available, mainly due to its launch in 2014 while other platforms are younger. The supported languages are Java, C#, Node.JS, Python and Go; in this example we use Java to catch the S3 event triggered by a new file in the bucket and then there is the creation of a new object in the CosmosDB collection, using the content of the JSON file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bec9ebe0e9eacbc730631dce5e2178aa/href">https://medium.com/media/bec9ebe0e9eacbc730631dce5e2178aa/href</a></iframe><p>We firstly receive the S3 event which has only bucket name and the key of the object. Using AWS S3 client we retrieve the related JSON and then create the new object on CosmosDB. It’s a bad practice to use variables like user/account in your code so here we are using the environment variables defined in the AWS Lambda console.</p><h3><strong>Azure Function</strong></h3><p>The last step of our journey is Azure Function, Microsoft Serverless proposal integrated in the Azure platform and which supports C#, JavaScript, F# and Java languages (Python, PHP, TypeScript, Batch, Bash and PowerShell are experimental). For the final step we use a C# function that is periodically called by a timer. Using the concept of <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#supported-bindings">binding</a> we have two integrations :</p><ol><li>CosmosDB input binding with the list of documents in a specific collection</li><li>SendGrid output binding so we can use this external platform to send email from Azure</li></ol><p>We can find the bindings in the function.json file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73e315ae5a0f938613b64680da799ecc/href">https://medium.com/media/73e315ae5a0f938613b64680da799ecc/href</a></iframe><p>The binding file is also used to provide a DocumentDB client to C# code, in order to delete the objects. The function, called every five minutes, simply reads the objects passed as argument and uses it to create the content for an email.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc58aaaefaaaae5894ff41f81d8aaf11/href">https://medium.com/media/dc58aaaefaaaae5894ff41f81d8aaf11/href</a></iframe><h3><strong>Conclusion</strong></h3><p>Finally, we receive an email with details of every push. This journey was a funny joke but I used it to explore and show how Serverless architectures are interesting, especially for integration of events inside a complex cloud platform. You can find the code samples in <a href="https://github.com/fpaparoni/hellocloud">this GIT repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4a5da225d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>