<?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 Florian Dambrine on Medium]]></title>
        <description><![CDATA[Stories by Florian Dambrine on Medium]]></description>
        <link>https://medium.com/@floriandambrine?source=rss-72fd1473b4e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MrLWCEGsTeEbTw3h.jpg</url>
            <title>Stories by Florian Dambrine on Medium</title>
            <link>https://medium.com/@floriandambrine?source=rss-72fd1473b4e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:44:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@floriandambrine/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[Golden Path Approach for CI/CD Using Drone.io]]></title>
            <link>https://medium.com/gumgum-tech/golden-path-approach-for-ci-cd-using-drone-io-947f09fe2c04?source=rss-72fd1473b4e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/947f09fe2c04</guid>
            <category><![CDATA[harness]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[starlark]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Florian Dambrine]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 19:15:13 GMT</pubDate>
            <atom:updated>2023-06-20T17:21:38.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BEkTUO3XM3kaQFUl" /><figcaption>Point Reyes National Seashore, Inverness, United States by <a href="https://unsplash.com/fr/photos/gyIRjKPXupE">Stephen Leonardi</a></figcaption></figure><h3>Introduction</h3><p>In the rapidly evolving landscape of software development, the ability to continuously integrate and deploy applications is crucial for achieving shorter development cycles, faster time-to-market, and improved overall software quality. However, implementing effective and efficient continuous integration and deployment (CI/CD) processes can be a daunting challenge, often plagued by complex pipelines, manual configuration, and inconsistent practices across teams.</p><p>Recognizing the need for standardized CI/CD pipelines, the concept of “Golden Path,” also known as <a href="https://www.slideshare.net/diannemarsh/the-paved-road-at-netflix">“Paved Road” from Netflix</a>, has gained traction in the industry. This approach emphasizes the creation of predefined, reusable, and easily configurable pipelines that serve as the foundation for consistent CI/CD workflows.</p><p>The <a href="https://gumgum.com/verity">GumGum Verity™</a> engineering team has been an early adopter of <a href="https://www.drone.io/">Drone.io</a> to handle CI/CD workflows and application deployments. While being happy with the flexibility that Drone provides through the use of containers to incorporate pre‑configured steps into a pipeline and the ability to write custom plugins, it was time to rethink certain aspects of the workflow to address some paint points the team was facing:</p><ol><li>How can we keep pipelines DRY and prevent copy pasting from projects to projects?</li><li>How can we decouple CI / CD from application deployment using a promotion rollback mechanism?</li><li>How can CI / CD deal with multi-arch support <em>arm</em> vs <em>linux/amd64</em> or even the need of specialized hardware like a GPU while remaining cost efficient?</li></ol><p>In this blog post, we will discuss the reconstruction of our Drone ecosystem, revolutionizing our CI/CD processes within the company. You will learn how we leveraged the versatility and flexibility of Drone and harnessed its potential to create an intuitive and standardized pipeline framework. By embracing the “Golden Path” approach, we envision a future where developers can effortlessly navigate the CI/CD landscape, focusing on delivering innovative features and enhancements rather than getting entangled in intricate pipeline configurations. Our goal is to provide a comprehensive solution that expedites software delivery, enhances collaboration, and elevates the overall quality of our applications.</p><h3>📦 Pipelines and Building Blocks</h3><p>As your team grows and the number of projects increases exponentially, it can become tedious to maintain consistent CI/CD pipelines across the board.</p><p>While Drone provides the ability to configure pipelines as code using a simple YAML file called <em>.drone.yml</em> that you commit to your git repository, it does not offer an easy way to reuse well-established building blocks to compose your pipeline.</p><p>As a result you may find yourself copy-pasting steps from other pipelines to craft your own, which is far from being ideal, especially if you make use of <a href="https://docs.drone.io/pipeline/environment/reference/">Drone environment variables</a> to write generic steps that will be 100% identical.</p><p>Here is an example of a generic step to publish a Docker container to the AWS ECR registry that can be reused across many projects as-is. The registry name is derived from the Git repository name, and the image tag will be associated with a Git tag (if any) or fallback to a short Git SHA (8 digits).</p><pre>### Generic step that can work for many projects with no edit required<br>- name: Publish Container to ECR<br>  image: plugins/ecr<br>  settings:<br>    repo: &quot;12345.ecr.amazonaws.com/namespace/${DRONE_REPO_NAME}&quot;<br>    tags:<br>      - &quot;${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}&quot;</pre><p>If we extrapolate this previous idea to other CI / CD building blocks, there is a good chance that the same team will reuse the same frameworks and the same build tools or dependency managers across projects, providing us with more opportunity to standardize workflows.</p><p>By mapping out your global CI/CD footprint you will be able to identify common patterns and building blocks that are necessary for creating your end to end pipelines, and ultimately your “Golden Paths”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-DQM0OtWT6k0oKTB" /><figcaption>CI / CD Footprint and Building Blocks Identification</figcaption></figure><h3>➰ Use Templates And Keep It DRY</h3><p>Once you have mapped out the CI/CD building blocks, it’s time to think about templates. Drone offers an out-of-the-box solution to leverage <a href="https://docs.drone.io/template/">templates</a> which can be written in plain YAML, using <a href="https://jsonnet.org/">Jsonnet</a> or <a href="https://github.com/bazelbuild/starlark/blob/master/spec.md">Starlark</a> (a dialect of Python originally developed for the <a href="https://bazel.build/">Bazel build tool</a>).</p><p>We chose to retain Starlark as a template engine due to its close proximity with Python, which makes it really easy for newcomers to pick up. Now, it is time to stitch the pipeline pieces together.</p><p>In an ideal world, building a “Golden Path” for a Python project using templates should resemble something like this:</p><ul><li><strong>CI Pipeline — </strong>Use the Python Building block to run CI steps</li><li><strong>Delivery Pipeline </strong>— Use the Docker building block to release the Python project as a container</li><li><strong>Deployment Pipeline — </strong>Use the <a href="https://medium.com/gumgum-tech/streamlining-your-kubernetes-adoption-with-helmfile-argocd-and-gitops-211937e21e29">Gitops Workflow</a> building block to deploy the new version</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u9E8Y-Kl2rdxUQYh" /><figcaption>Example Golden Path for a Python application deployed on Kubernetes using a GitOps workflow</figcaption></figure><p>According to the <a href="https://docs.drone.io/template/starlark/">Drone templates documentation</a>, templates can be used by setting the <em>kind</em> to <em>template</em>, the name of the base template to <em>load</em>, and a set of freeform template inputs in the <em>drone.yml</em> file:</p><p>We may be tempted to craft our “Golden Path” this way:</p><pre>### - - - - - - - - - -###<br>### Python Golden Path ###<br>### - - - - - - - - - -###<br><br>### Continuous integration for Python projects using Tox<br>---<br>kind: template<br>load: python_ci.starlark<br>data:<br>  image: python-tox:v3.10<br><br>### Continuous Delivery for Docker images<br>---<br>kind: template<br>load: container_cd.starlark<br>data:<br>  registry: &quot;12345.ecr.amazonaws.com/namespace/${DRONE_REPO_NAME}&quot;<br><br>### Continuous Deployment to K8s using Gitops<br>---<br>kind: template<br>load: gitops.starlark<br>data:<br>  artifact: &quot;12345.ecr.amazonaws.com/namespace/${DRONE_REPO_NAME}&quot;<br>  application: python-demo-app</pre><p>Unfortunately this is where you may become <strong>greatly disappointed</strong> 😱 when you realize that Drone only considers the first template and ignores the rest. After a few minutes googling, you land on this Github proposal: <a href="https://github.com/drone/proposal/issues/27">#27 Allow using multiple templates per .drone.yml file</a>. This renders the built-in templates provided by Drone unusable in our scenario.</p><h3>🛟 Drone Extensions To The Rescue</h3><p>Drone templates still remain the best option for implementing “Golden Paths”. Additionally, thanks to Drone extensibility, you can use a <a href="https://docs.drone.io/extensions/conversion/">conversion extension</a> to modify a <em>.drone.yml</em> configuration file before it gets parsed and processed by the system.</p><p>This is where you land on the <a href="https://github.com/drone/drone-convert-starlark">Drone Convert Starlark</a> conversion plugin and hope your dreams come true … 🙏</p><p>An interesting aspect of this project is to support the loading of other templates from the file system (to address the multi template import issue mentioned earlier). The only caveat here is to ensure that the templates are present on disk for the convert plugin to load.</p><p>If you treat your CI/CD templates as a separate project (which I believe you should, as it enables version control, deployment and rollback) it is relatively straightforward to package your custom templates in the Drone Convert Starlark plugin using the following <em>Dockerfile</em>:</p><pre>FROM drone/drone-convert-starlark<br><br>### Make Starlark templates accessible using: load(&quot;@custom//&lt;file.star&gt;&quot;)<br>ENV DRONE_STARLARK_REPO_PATHS=custom:/var/lib/drone/starlark/templates<br><br>COPY templates /var/lib/drone/starlark/templates</pre><p>This component is relatively simple to deploy on a Kubernetes cluster as it is a standalone component with no additional dependencies. Here is an infrastructure diagram showing the integration of the conversion extension:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ObBdsQkfKQnzr6To" /><figcaption>Drone Servers integrated with Drone Convert Starlark extension plugin</figcaption></figure><p>Let’s see what a “Golden Path” could look like with this new setup:</p><pre>### Python Golden Path ###<br><br>load(&quot;@custom//integration:python_ci.star&quot;, &quot;ci&quot;)<br>load(&quot;@custom//delivery:container_cd.star&quot;, &quot;cd&quot;)<br>load(&quot;@custom//deployment:gitops.star&quot;, &quot;deploy&quot;)<br><br>def main(ctx):<br>  return (<br>    ci(<br>      image=&quot;python-tox:v3.10&quot;<br>    )<br>    + cd(<br>      registry=&quot;12345.ecr.amazonaws.com/namespace/${DRONE_REPO_NAME}&quot;<br>    )<br>    + deploy(<br>      artifact=&quot;12345.ecr.amazonaws.com/namespace/${DRONE_REPO_NAME}&quot;,<br>      application=python-demo-app<br>    )<br>  )</pre><h3>🌟 It’s Time To Build Golden Paths !</h3><p>In the previous section, we showcased how to create a Drone pipeline using reusable building blocks and templates. Now, it’s time to organize the Drone template Git repository, which will serve as the hosting location for all the Starlark templates</p><p>Here is a suitable folder structure for building reusable blocks:</p><ol><li><strong>Golden Path </strong>— Assemble different set of pipelines to run an end-to-end workflow from CI, delivery to deployment by stitching smaller building blocks together (eg. Python to K8s / Python to Lambda / Webapp to Cloudfront)</li><li><strong>Pipelines </strong>— Set of<strong> </strong>Drone pipelines associated with their respective triggers (execute on push / on tag / on pull-request / promotion or rollback) that executes one or more workflows (Python CI workflow / Docker container workflow + security scanning workflow)</li><li><strong>Workflows — </strong>A sequence of steps to execute to achieve a given goal (A CI workflow commonly runs linting / checkstyle / unit tests)</li><li><strong>Steps </strong>— A configurable Drone step that calls a certain <a href="https://plugins.drone.io/">Drone plugin</a> or run simple shell commands inside a container (Publish container / Run Gradle version X / Execute AWS CLI commands / Cache artifact)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/0*lnhP9tS7H8XgJQAj" /><figcaption>Example layout of a Drone Starlark template git repository</figcaption></figure><p>👉 Tips: The <a href="https://github.com/drone/drone-convert-starlark#testing">Drone Cli</a> makes it easy to develop and test your golden paths! Simply start the Drone Convert Starlark container locally, mount your templates as a docker volume, and run the following command to validate your code:</p><pre># Exectute the drone-cli against a local server to ensure proper rendering<br># of .drone.star -&gt; .drone.yml<br><br>drone plugins convert \<br>  --repository test \<br>  --endpoint http://localhost:3000 \<br>  &lt;path&gt;/&lt;to&gt;/.drone.star</pre><h3>✂️ Decoupling CI / CD from Deployment</h3><p>In our previous implementation of Drone, we tightly coupled the CI/CD steps of a project with its deployment based on a set of Git events:</p><ul><li>Code pushed to a dev branch runs CI steps</li><li>Code changes merged to the <em>main / master </em>branch triggers CI + CD + Deployment to staging environment</li><li>Applying a tag to a commit triggers CI + CD + Deployment to production environment</li></ul><p>The downside of this approach is that it creates a tight coupling between CI / CD and deployment of your application. In the event of a deployment failure and the need for a rollback, the team is left with a single option: Restarting the build of the previous stable version to restore the service. This results in a full replay of the CI + CD + Deployment, while what is truly needed in this case is to rerun the only deployment part of the pipeline.</p><p>Drone provides and interesting feature called <a href="https://docs.drone.io/promote/">promotions/rollbacks</a> that can be leveraged to take a previous build and deploy it in a given environment (called target)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/0*iuiNU9gm7vP4-CHX" /><figcaption>Drone build promotion feature</figcaption></figure><p>It is now possible to update the deployment pipelines to use a promotion mechanism as part of its triggers:</p><ul><li>Only code from <em>main / master </em>branch or a <em>tagged commit </em>can be deployed to the staging environment</li></ul><pre>trigger:<br>  event:<br>    include: [ promote, rollback ]<br>  target:<br>    include: [ staging ]<br>  ref: [ refs/heads/master, refs/heads/main, refs/tags/** ]</pre><ul><li>Only Code from a <em>tagged commit </em>can be deployed to the production environment</li></ul><pre>trigger:<br>  event:<br>    include: [ promote, rollback ]<br>  target:<br>    include: [ production ]<br>  ref: [ refs/tags/** ]</pre><h3>💰 Cost Effectiveness &amp; Specialized Hardware</h3><p>With the rise of <a href="https://aws.amazon.com/ec2/graviton/?nc1=h_ls">AWS Graviton instances</a> and ARM based systems, which provides better cost-to-performance ratio compared to their x86 counter parts, or even the potential need to run a pipeline on an expensive GPU instance, it is legitimate to ask ourselves if our CI / CD environment is ready to build on specialized hardware in a cost effective manner.</p><p><a href="https://autoscale.drone.io/">Drone Autoscaler</a> is a standalone daemon that continuously polls your build queue and provisions or terminates server instances based on volume or pipeline needs.</p><p>When used in combination with <a href="https://docs.drone.io/pipeline/docker/syntax/routing/">pipeline routing</a>, you can achieve just-in-time provisioning of runners to execute your pipeline on specific hardware and shutdown when they become idle.</p><p>This brings us to the final infrastructure diagram for this new Drone setup which includes all the components put together, including the persistent layer to run <a href="https://docs.drone.io/server/ha/overview/">Drone in a HA fashion</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oovzB9cP_ukwYy7J" /><figcaption>Overall Drone 2.x Infrastructure deployment</figcaption></figure><h3>👏 Wrapping up</h3><p>The revamp of our build platform marks a significant milestone in our continuous integration and deployment journey. By embracing the concept of “Golden Paths” and standardized pipelines, we have paved the way for streamlined CI/CD practices within our team.</p><p>With the “Golden Path” platform we unlock new possibilities for scalability, maintainability, and reusability, ultimately leading to enhanced productivity and innovation.</p><p>Together, let us embrace the power of standardized pipelines, paving the way for a more efficient and seamless software delivery experience !</p><p>We’re always looking for new talent! <a href="https://gumgum.com/careers">View jobs</a>.</p><p>Follow us: <a href="https://www.facebook.com/gumguminc">Facebook</a> | <a href="https://twitter.com/gumgum">Twitter</a> | <a href="https://www.linkedin.com/company/167379/">LinkedIn</a> | <a href="https://www.instagram.com/gumgum/">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=947f09fe2c04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/golden-path-approach-for-ci-cd-using-drone-io-947f09fe2c04">Golden Path Approach for CI/CD Using Drone.io</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlining your Kubernetes adoption with Helmfile / ArgoCD and GitOps]]></title>
            <link>https://medium.com/gumgum-tech/streamlining-your-kubernetes-adoption-with-helmfile-argocd-and-gitops-211937e21e29?source=rss-72fd1473b4e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/211937e21e29</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Florian Dambrine]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 19:56:05 GMT</pubDate>
            <atom:updated>2022-01-31T22:04:38.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Photo of a playground" src="https://cdn-images-1.medium.com/max/1024/1*823HzBAC5v7JhY6G2u4w4w.jpeg" /><figcaption>Photo Credits — <a href="https://unsplash.com/@ferranfeixas">Ferran Feixas</a> <a href="https://unsplash.com/photos/jwkOaqUZtuM">https://unsplash.com/photos/jwkOaqUZtuM</a></figcaption></figure><p>In a previous article titled <a href="https://medium.com/gumgum-tech/stop-being-selfish-open-up-terraform-to-your-team-with-atlantis-9b21f40fd73e">Stop being selfish ! — Open up Terraform to your team with Atlantis</a>, we showcased how powerful and convenient it is to have a well defined Git workflow to manage the infrastructure as code using <a href="https://www.terraform.io/">Terraform</a> with <a href="https://www.runatlantis.io/">Atlantis</a>.</p><p>Using Git as a source of truth has really served us well over the past year and has inspired the <a href="https://gumgum.com/accreditation">GumGum Verity</a> team to build a similar workflow, with Git being at the center to deal with Kubernetes application deployments.</p><p>In this blog post you will learn how we leveraged popular cloud-native technologies to build a reliable GitOps workflow to streamline and ease the adoption of Kubernetes within the team.</p><h3>GitOps Principles</h3><p>Pioneered in 2017, GitOps was first brought up by <a href="https://www.weave.works/technologies/gitops/">Weaveworks in this article</a>. Here is a short quote extracted from it:</p><blockquote>GitOps is a way to do Kubernetes cluster management and application delivery. GitOps works by using <strong>Git as a single source of truth for declarative infrastructure and applications</strong>. With GitOps, the use of software agents can alert on any divergence between Git with what’s running in a cluster, and if there’s a difference, Kubernetes reconcilers automatically update or rollback the cluster depending on the case. With Git at the center of your delivery pipelines, developers use familiar tools to make pull requests to accelerate and simplify both application deployments and operations tasks to Kubernetes.</blockquote><p>This technique offers increased visibility on what is running on a given cluster as it is syncing the canonical desired system state (<a href="https://kubernetes.io/docs/reference/glossary/?all=true#term-manifest">Kubernetes manifests</a>) from a Git repository.</p><p>Before managing a cluster using GitOps workflows, the following must be in place:</p><blockquote><em>[1]</em> Describe the entire system declaratively</blockquote><blockquote><em>[2]</em> Version the canonical desired system state in Git</blockquote><blockquote><em>[3]</em> Automatically apply approved changes to the desired state</blockquote><blockquote><em>[4]</em> Ensure correctness and alert on divergence with software agents</blockquote><p>Let’s see in practice how you can achieve this with commonly used Kubernetes tools.</p><h3>Kubernetes plumbing</h3><p>Before we start, it is important to review the different actors involved with a Kubernetes cluster during its life time and especially how each of them contributes to a solution that inlines with the GitOps principles.</p><h4><strong>✅ Cluster infrastructure administration</strong></h4><p>Usually owned by a DevOps team, the cluster administrator responsibility is to deal with deployments and upgrades of Kubernetes clusters. Backed by a set of automations, the administrator ensures clusters can be provisioned / autoscaled / accessed by users / upgraded and destroyed in a timely manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0pqnTuUqf4XYObPvqvxyA.png" /><figcaption>Example of Kubernetes cluster setup with EKS for the control plane and Spot.io Ocean for worker nodes</figcaption></figure><p>This first layer of automation being purely infrastructure related is captured by our Terraform/Atlantis workflow which, if you noticed, follows similar principles to the GitOps ones:</p><ol><li>Infrastructure as code using <a href="https://www.terraform.io/">Terraform</a>/<a href="https://terragrunt.gruntwork.io/">Terragrunt</a> describes the system declaratively</li><li>The canonical desired state (Terraform state) is kept in S3 thanks to Terraform and allows resources tracking over time</li><li>Atlantis takes actions on your behalf based on the Git pull request activity</li></ol><h4>✅ Cluster shared services administration</h4><p>Now that the Kubernetes cluster has been deployed, it’s time to set up a couple of key components that will help your application developers enjoy a seamless experience and adopt a true GitOps experience!</p><p>These components will be installed using <a href="https://helm.sh/">Helm</a> charts, a common packaging format for Kubernetes. A chart is simply a collection of files that describe a related set of Kubernetes resources. Here is a list of Helm charts we automatically deploy to our cluster to prepare the stage for our GitOps workflow:</p><ul><li>📁 Logging with <a href="https://github.com/vmware/kube-fluentd-operator"><strong>kube-fluentd-operator</strong></a>: Logs forwarder based on <a href="https://www.fluentd.org/">Fluentd</a> that can plug into your central logging platform.</li><li>🚒 Monitoring with <a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack"><strong>kube-prometheus-stack</strong></a>: Prometheus ecosystem should be available so that developers can register their applications and track metrics in <a href="https://grafana.com/">Grafana</a>.</li><li>🔗 DNS with <a href="https://github.com/bitnami/charts/tree/master/bitnami/external-dns"><strong>external-dns</strong></a>: Developers should have the ability to create DNSs from Kubernetes itself to setup services seamlessly.</li><li>🔐 Secrets with <a href="https://github.com/bitnami-labs/sealed-secrets"><strong>sealed-secrets</strong></a>: Given that your application state will be stored in Git, you must ensure your secrets can be safely sealed in there.</li><li>🤖 GitOps with <a href="https://github.com/argoproj/argo-helm/tree/master/charts/argo-cd"><strong>argo-cd</strong></a> <strong>&amp; </strong><a href="https://github.com/argoproj/argo-helm/tree/master/charts/argocd-applicationset"><strong>argo-cd-applicationset</strong></a>: The GitOps agent must be deployed and configured to watch for its state from a Git source of truth.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OUzQ6qQPV3PFsUpCbmYVTw.png" /><figcaption>Kubernetes Cluster enabling GitOps workflows with key shared services deployed</figcaption></figure><h4>📚 It’s time to layout the code repository</h4><p>Now that the required Helm charts have been identified, it’s time to stitch everything together in a code repository that will help achieve the first GitOps principle:</p><blockquote><em>[1]</em> <em>Describe the entire system declaratively.</em></blockquote><p>To ease the orchestration of all those charts, we use a thin wrapper on top of <a href="https://helm.sh/">Helm</a> called <a href="https://github.com/roboll/helmfile">Helmfile</a>. It is a declarative spec for deploying Helm charts.</p><p>Here is an example repository layout that can hold the infrastructure presented earlier and our future applications (located in <em>gitops/</em>) that will be deployed in a GitOps fashion. The root <em>helmfile.yaml </em>file includes all the releases listed in the <em>ops/</em> folder. This way you can deploy all the components with a single command like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QR2lDlvMlIWrh-KOcZx9IA.png" /><figcaption>Helmfile code repository structure</figcaption></figure><h4>🐔 🥚 Solving the chicken and egg situation</h4><p>You may notice here that we need to install all those <em>ops/</em> Helm charts outside of the GitOps workflow to get the GitOps workflow setup 😅.</p><p>There are a couple of ways to solve this:</p><ul><li>You can move all those shared helm charts into your Terraform module so that they get automatically deployed upon cluster creation (and they do not sit anymore in the helmfile repo presented above).</li><li>Install them manually <strong>once</strong> and make sure they get added to the GitOps workflow themselves.</li></ul><blockquote><em>[2]</em> Version the canonical desired system state in Git</blockquote><p>Now that the Helmfile code repository is setup, we need to create a second Git repository that will this time host the canonical state of our applications synced by the GitOps agent.</p><p>👍 As a rule of thumb, I would suggest you dedicate the canonical state Git repository to a single cluster (think about it as the brain of your cluster, what sits in that repo also sits in your Kubernetes cluster)</p><p>To inline with this second principle, Helmfile will simply hydrate all the templates of the Helm charts located in <em>gitops/</em> to generate the <a href="https://kubernetes.io/docs/reference/glossary/?all=true#term-manifest">Kubernetes manifests</a> files.</p><p>The diagram below illustrates Helmfile template rendering for an application named <strong>demo </strong>with two different set of values for <em>production</em> and <em>staging</em> environment. It results in different releases rendered with different canonical state generations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oEur7slL_muzuuR2-iAjg.png" /><figcaption>Helmfile template makes it easy to generate plain Kubernetes manifests for GitOps</figcaption></figure><p>Once the canonical states have been rendered on the file system, it’s only a matter of pushing them to Git so that your GitOps agent can access them.</p><blockquote><em>[3]</em> Automatically apply approved changes to the desired state</blockquote><p>What’s great about relying on Git and source control is that you land on a well known interface that you use on a daily basis! Whether you want to control who can push to the repository or put restrictions on certain branches or event require reviewers approval before merge, you have the freedom to build the process that fits your day to day workflows.</p><p>This also provides room for automation using CI/CD pipelines to take actions on your behalf. In the example below, we followed our current software practices where staging deployments happen automatically when a PR is merged onto the main branch, and production is deployed based on a Git tag addition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHiDusYoOoAxWnMNZlBi2Q.png" /><figcaption>Helmfile templating step the can be integrated in a CI/CD pipeline</figcaption></figure><blockquote><em>[4]</em> Ensure correctness and alert on divergence with software agents</blockquote><p>This is where <a href="https://argo-cd.readthedocs.io/en/stable/">Argo-CD</a> enters the game! Once your Git canonical state repo is updated, Argo automatically reconciles your resources according to the new state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8tbhZB4SV2C0PvRGRoBvZg.png" /></figure><p>Thanks to its beautiful UI, it really helps engineers get a better sense of what their application is made of, and if it is in sync with the state stored in Git. It also provides great features like showing a diff of the resources that changed, push button or automated syncs, and notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8A7mdtEFPYQ3Rb3V5ue4Q.png" /><figcaption>ArgoCD UI showing an application that has gone out of sync with its canonical state</figcaption></figure><h3>Stitching everything together</h3><p>Now that the GitOps workflow is in place, it’s time to make things easy for developers so that they can work with their day to day business applications while seamlessly integrating with the GitOps pipeline previously configured.</p><p>In a docker world, a usual application code repository integrated with a CI/CD pipeline would run the following steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xe1D5GGwCFSzDIWZJaymwg.png" /><figcaption>Typical CI/CD pipeline for an application repository (Build / Tests / Publish / Notify)</figcaption></figure><p>Given that Kubernetes application manifests are tracked in a dedicated Git repository (including the docker image version), we will need to bridge the gap between those two pipelines if we don’t want developers to manually change the version each time their pipeline produces a new docker image.</p><p>This problem is actually pretty easy to solve. The application code repository CI/CD pipeline will be extended to automatically bump up the image version tag according to the docker image tag that was was published and commit this change to the Helmfile configuration repo. By connecting the two pipelines through Git, you end connecting the dots! The picture below summarizes a cascading pipeline execution from application development to Kubernetes deployment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nOm5T08Ry4PKGaeGpfXhzw.png" /><figcaption>Cascading execution of pipelines from application development to deployment</figcaption></figure><h3>Wrapping up</h3><p>Adopting GitOps principles using a well defined set of pipelines and workflows based on Git repositories has greatly helped our team get a better sense of how Kubernetes applications are made and deployed. This technique helped us reduce the friction and increased the ability for developers to quickly gain knowledge and confidence on Kubernetes.</p><p>To further reduce the potential amount of complexity introduced by the understanding of Helm charts, we made the call to rely as much as we can on the well known <a href="https://github.com/cloudposse/charts/tree/master/incubator/monochart">Monochart</a> from Cloudposse. It offers a simple interface to deploy pretty much any kind of application in Kubernetes and has templates for <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/">CRDs</a>. If you don’t know it yet, please go play with it, it can do a lot!</p><p><a href="https://github.com/cloudposse/charts/tree/master/incubator/monochart">charts/incubator/monochart at master · cloudposse/charts</a></p><p>I hope you now have better sense of what GitOps in practice means and how easily it can integrate into your day to day workflows!</p><pre>git commit -am &#39;Thank you for reading and happy GitOps !&quot;; git push</pre><p>We’re always looking for new talent! <a href="https://gumgum.com/careers">View jobs</a>.</p><p>Follow us: <a href="https://www.facebook.com/gumguminc">Facebook</a> | <a href="https://twitter.com/gumgum">Twitter</a> | <a href="https://www.linkedin.com/company/167379/">Linkedin</a> | <a href="https://www.instagram.com/gumgum/">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=211937e21e29" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/streamlining-your-kubernetes-adoption-with-helmfile-argocd-and-gitops-211937e21e29">Streamlining your Kubernetes adoption with Helmfile / ArgoCD and GitOps</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Frontflip: When a DevOps enters the JAMStack — Functional Preact / Hugo / AWS Amplify]]></title>
            <link>https://medium.com/gumgum-tech/the-frontflip-when-a-devops-enters-the-jamstack-functional-preact-hugo-aws-amplify-11a02d1d6c9d?source=rss-72fd1473b4e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/11a02d1d6c9d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[amplify]]></category>
            <category><![CDATA[jamstack]]></category>
            <category><![CDATA[hugo]]></category>
            <category><![CDATA[preact]]></category>
            <dc:creator><![CDATA[Florian Dambrine]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 18:21:44 GMT</pubDate>
            <atom:updated>2021-01-06T16:10:53.931Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Front Flip: When a DevOps Engineer Enters the JAMStack — Functional Preact/Hugo/AWS Amplify</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqxTc40A_2g_eNNEnnxWMQ.jpeg" /><figcaption>Photo: BENNI SCHMID — Copyright by <a href="https://www.gibbon-slacklines.com/en/team/benni-schmid/">https://www.gibbon-slacklines.com/</a></figcaption></figure><p>Relax and put your seat belt on… You’re about to enter my journey of an intense 2 weeks sprint I recently led, swapping my DevOps hat for a front-end one to build a full JAMStack website from the ground up deployed on AWS!</p><h3>Foreword &amp; Context</h3><p>The GumGum Verity team applies machine learning techniques to the text and imagery on web pages to identify the context of the advertising inventory and brand safety threats. It then delivers content-level data over a Rest API that help publishers, DSPs and advertisers place ads in safe and relevant contexts.</p><p>This API not only supports page level analysis, but also offers standalone endpoints for text, image and video classification.</p><p>It acts as a coordinator, orchestrating the flow of a request within pipelines made of a dozen micro-services until it has a full response that can be sent back to the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75AvT1b_8pVvL5t9N1a2Nw.png" /><figcaption>Visualization of Page processing steps</figcaption></figure><p>When a request gets stuck in the pipeline (no success nor response notification), identifying the culprit in such an infrastructure is like trying to find a needle in a haystack:</p><ul><li>What system did not respond to the request?</li><li>Did the request fail in the pipeline or did the caller miss the response?</li><li>Is the request response simply delayed due to lag in the pipeline?</li></ul><p>An API developer would go check the different back ends and look for the raw data corresponding to a request to be able to provide a response after investigation…</p><p>But for the rest of us, it sounds more like, “I don’t even know where this data is stored…”</p><p>It became clear to me that we needed a Web UI that will help visually display all the data for a request and make it easy for anyone to spot the problem rapidly.</p><p>The only thing is that our team is made of everything <em>except</em> front-end engineers. With my recent focus on enhancing team productivity, I took on this mission of building a Web UI from scratch.</p><h3>Front end for non Front end people…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmJP6-9grqe8nBqxL8zN1g.png" /><figcaption>Collection of JavaScript Frameworks : Copyright by <a href="https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f">Jose Aguinaga</a></figcaption></figure><p>We all know how vast the front-end eco-system is: from build tools and asset managers like <a href="https://webpack.js.org/">Webpack</a>, <a href="https://yarnpkg.com/">Yarn</a> and <a href="https://gruntjs.com/">Grunt</a>, to frameworks and libraries such as <a href="https://reactjs.org/">React</a>, <a href="https://preactjs.com/">Preact</a>, <a href="https://vuejs.org/">Vue</a> <a href="https://angular.io/">and Angular</a>, and even static site generators (SSG) like <a href="https://gohugo.io/">Hugo</a>, <a href="https://www.gatsbyjs.com/">Gatsby</a> and <a href="https://jekyllrb.com/">Jekyll</a>. You have a lot of options to build a website in 2020!</p><p>Given that my JS knowledge stopped at simple <a href="http://vanilla-js.com/">vanilla JS</a> and at most <a href="https://jquery.com/">JQuery</a>, I had to make wise choices to make sure this project would not go over my sprint and would remain within my skill set. Hence I came up with the following statements:</p><ul><li>Use a <strong>JS framework</strong> <strong>only when dynamism is required</strong> (Authentication / Retrieve data from AWS back ends / Manage complex UI interactions)</li><li>Use <strong>plain HTML</strong> <strong>when the content is static </strong>(modern libraries like <a href="https://animate.style/">Animate.style</a> can be leveraged to make your static HTML look more dynamic)</li></ul><h4>Choosing the Tech</h4><p>As a former DevOps Engineer, I am a big fan of the <a href="https://jamstack.org/">JAMStack</a> principles which I discovered while reading this great free <a href="https://www.netlify.com/oreilly-jamstack/">eBook from Netlify</a>:</p><ul><li><strong>JavaScript</strong>: Dynamic functionalities are handled by JavaScript. There is no restriction on which framework or library you must use.</li><li><strong>APIs</strong>: Server side operations are abstracted into reusable APIs and accessed over HTTPS with JavaScript. These can be third party services or your custom function.</li><li><strong>Markup</strong>: Websites are served as static HTML files. These can be generated from source files, such as Markdown, using a Static Site Generator.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*H5Gylm_FnV72IgPwpaqq1w.png" /><figcaption>Traditional Vs JAMStack — Copyright by <a href="https://jamstack.org/">https://jamstack.org/</a></figcaption></figure><p>This is something familiar to us as we have built our entire internal documentation using Hugo and the great <a href="https://themes.gohugo.io/hugo-theme-learn/">Hugo-Learn theme</a> !</p><p>Now we need to figure out how to plug a JavaScript workflow/framework into something as simple as a static website generator and make both tools co-exist!</p><h4>Adding an assets pipeline to Hugo</h4><p>While doing my research on Hugo and Webpack, I came across the <a href="https://github.com/netlify-templates/victor-hugo">Victor Hugo Netlify template on Github</a>. Simple enough for a newcomer to Webpack and JavaScript (like me), it appeared to be a solid starting point working from the get go.</p><h4>Choosing a JavaScript framework</h4><p>I always had somewhere in my mind, <em>“I should learn React one day…”</em> and landing on this article “<a href="https://www.smashingmagazine.com/2020/01/migration-from-wordpress-to-jamstack/">How Smashing Magazine Manages Content: Migration From WordPress To JAMstack</a>” made me discover <a href="https://preactjs.com/">Preact</a> (a 3kb alternative to React) which seemed really attractive.</p><p>Digging further in Google drove me to this article, <a href="https://medium.com/@_zouhir/preact-meets-cms-building-lightweight-portable-widget-components-e151622e2ac6">Preact meets CMS: Building Lightweight Portable Widget Components</a> from <a href="https://medium.com/u/1ea4ac63ade6">Zouhir</a> (<a href="https://www.youtube.com/watch?v=OODChHa012w">Podcast</a> available as well), which literally convinced me with <a href="https://github.com/zouhir/preact-habitat">Preact-habitat</a>.</p><blockquote>Preact-habitat is just an extension to Preact’s render function where I decided to provide more API. The concept of Preact habitat is pretty straight forward and can be summarised as :</blockquote><blockquote>&gt; Scan the DOM when the widget’s script is loaded.<br>&gt; Re-scan again when DOM is fully loaded.<br>&gt; Allow host CMS page to pass props via HTML.<br>&gt; Stay &lt; 1KB.</blockquote><blockquote>— Copyright by <a href="https://medium.com/u/1ea4ac63ade6">Zouhir</a></blockquote><p>This was the last piece of the puzzle ! Let’s recap where we are at so far with this stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7UUVKTWtpUjU0o7jVTtLQ.png" /><figcaption>Preact &amp; Hugo stitched together with Webpack</figcaption></figure><h3>Getting Started — Project Scaffolding</h3><p>One of the great thing I like about Preact is that it comes with <a href="https://github.com/preactjs/preact-cli">Preact-Cli</a> that helps you get started in seconds and allows you to create a project skeleton from a Github repository template.</p><p>I just had to glue together Hugo/Preact and Webpack to get my own template going (originally forked from the <a href="https://github.com/netlify-templates/victor-hugo">Victor Hugo Netlify template</a>).</p><p><a href="https://github.com/Lowess/preact-hugo">Lowess/preact-hugo</a></p><pre>################################################################<br>### Gettings Started - Docker way (no setup required)<br>################################################################</pre><pre>### Create project scaffolding using preact-cli from custom template</pre><pre>$ docker run --rm \<br>    -w /app \<br>    -v $(pwd):/app \<br>    lowess/preact-cli create Lowess/preact-hugo demo-app</pre><pre>### List project folder content</pre><pre>$ cd demo-app/</pre><pre>### Run project using &quot;npm run start&quot;</pre><pre>$ docker run --rm \<br>    --entrypoint=&quot;&quot; \<br>    -p 3000:3000 \<br>    -e HOST=0.0.0.0 \<br>    -w /app \<br>    -v $(pwd):/app \<br>    lowess/preact-cli npm run start</pre><pre>## Visit http://localhost:3000</pre><p>Or simply go check it out on Github pages: <a href="https://lowess.github.io/preact-hugo/">https://lowess.github.io/preact-hugo</a></p><p>The <strong>Static Content </strong>navigation drives you to a list of posts that are written in simple Markdown and generated by Hugo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXHZXBECVrQk0Zl7Np_NRQ.png" /><figcaption>Hugo statically built content</figcaption></figure><p>The <strong>Dynamic Content </strong>navigation loads a dynamic Preact-habitat widget that is built with our JavaScript tool chain and packaged along with the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e52uxoBUkjSH7ubSGJRe6A.png" /><figcaption>Preact widget injection in Hugo thanks to Preact-habitat</figcaption></figure><h4>Hugo JavaScript widget injection with Preact-habitat ?</h4><p>At this stage you might be wondering how Hugo injects the dynamic content as part of the build process. It’s pretty simple:</p><ul><li>Hugo searches for the layout to use for a given page in a <a href="https://gohugo.io/templates/lookup-order/">well defined order</a>. In our case, the <strong>layouts/dynamic/ </strong>section should override the default site behavior to do whatever is necessary to load the JavaScript widget. Here is an example of Hugo layout to do so:</li></ul><pre>layouts<br>├── _default         // Default layout for static pages and homepage<br>│   ├── baseof.html  // Main website structure<br>│   ├── list.html    // List of articles (eg. /static/)<br>│   └── single.html  // Single article (eg. /static/getting-started)<br>│<br>├── dynamic          // Override templates for /dynamic section<br>│   └── list.html    // Defines the logic to load JS widget<br>...</pre><ul><li>The default template is overridden by <strong>dynamic/list.html </strong>which defines the main content of the page:</li></ul><pre>{{ define &quot;main&quot; }}<br>  {{- &quot;&lt;!-- Preact component injection --&gt;&quot; | safeHTML }}<br>  {{ partial &quot;preact.html&quot; (dict <br>       &quot;widget&quot; .Site.Data.webpack.helloWidget<br>       &quot;data&quot; (dict &quot;name&quot; &quot;I am built with Preact&quot;)<br>     ) <br>  }}<br>{{ end }}</pre><p>This file calls a <a href="https://gohugo.io/templates/partials/">partial template</a> with proper arguments like the <strong>widget</strong> to load (path to <em>&lt;widget&gt;.js</em>) and the <strong>data</strong> (props passed as JSON to the widget component).</p><p>The partial template <strong>preact.html </strong>is simply implementing <a href="https://github.com/zouhir/preact-habitat#via-props-script">Preact-habitat logic to load and render the widget</a>:</p><pre>&lt;div class=&quot;preact&quot;&gt;<br>  {{- &quot;&lt;!-- Preact component --&gt;&quot; | safeHTML }}<br>  {{- $script := .widget }}<br>  {{- $data := .data }}</pre><pre>{{ with $script.css -}}<br>    &lt;link href=&quot;{{ relURL . }}&quot; rel=&quot;stylesheet&quot;&gt;<br>  {{- end }}</pre><pre>{{ with $script.js -}}<br>    {{ with $data -}}<br>      &lt;script type=&quot;text/props&quot;&gt;<br>        {{ . | jsonify }}<br>      &lt;/script&gt;<br>    {{- end }}<br>    &lt;script async src=&quot;{{ relURL . }}&quot;&gt;&lt;/script&gt;<br>  {{- end }}<br>&lt;/div&gt;</pre><p>Here is what the final render of this HTML page looks like:</p><pre>&lt;div class=&quot;content container-fluid p-0&quot;&gt;      <br>  &lt;!-- Preact component injection --&gt;  <br>  &lt;div class=&quot;preact&quot;&gt;<br>    &lt;!-- Preact component --&gt;<br>    &lt;script type=&quot;text/props&quot;&gt;        <br>      {&quot;name&quot;:&quot;I am built with Preact&quot;}      <br>    &lt;/script&gt;    <br>    <br>    &lt;script async src=&quot;<a href="https://lowess.github.io/preact-hugo/helloWidget.e5579.js">/preact-hugo/helloWidget.e5579.js</a>&quot;&gt;&lt;/script&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><h3>A Serverless back end with AWS Amplify</h3><h4>Authentication and GraphQL API</h4><p>One important criteria that really mattered to us was to have a fully managed authentication service that we could rapidly plug into and would help us perform operations in our AWS back ends securely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FKIt6eoLUkujLqrXLUDOCA.png" /><figcaption>AWS Amplify — An AWS SDK to build full stack application</figcaption></figure><p>The AWS Amplify SDK seemed to be a great fit as it offers OAuth authentication using <a href="https://docs.amplify.aws/lib/auth/social/q/platform/js">Cognito and supports federation with social providers such as Google</a>.</p><p>It also comes with <a href="https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/js">GraphQL API features</a> that let you plug into <a href="https://aws.amazon.com/appsync/">AWS AppSync</a> to handle the heavy lifting of securely connecting to data sources like AWS DynamoDB or Lambda. It also has a built in feature that will ensure that the user performing the request is currently authenticated in AWS Cognito.</p><p>Wow! Lots of concepts to digest! But watching <a href="https://www.youtube.com/watch?v=EOQqi6Yun7g">AWS Amplify with Amazon DynamoDB Single Table and Direct AWS Lambda Resolvers with Rick Houlihan</a> was helpful and confirmed this technical choice.</p><blockquote>The major key takeaway I learned from this video is the fact that AppSync now seamlessly integrates with <a href="https://aws.amazon.com/blogs/mobile/appsync-direct-lambda/">Lambda using direct resolvers</a>.</blockquote><blockquote>The lambda function will likely act as a giant <strong>SWITCH CASE </strong>that will, based on the name of the GraphQL query, perform a certain action (query DynamoDB records, fetch content from RDS, pre-sign an S3 URL…). The sky is the limit as long as you are within your VPC and you likely have access to anything you may want!</blockquote><blockquote>This means that your back end remains quite simple: <strong>A public and secured API Gateway (AppSync endpoint)</strong> and your <strong>business logic</strong> (<strong>in a single Lambda).</strong></blockquote><p>Here is a diagram that recaps how we deployed this Serverless infrastructure in order to leverage AWS Amplify SDK on the front end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZoqRdXz6khDSJ_cTQ9tsg.png" /><figcaption>AWS Amplify — AppSync Back end / Cognito Authentication layer</figcaption></figure><p>We now have all the pieces our application requires to serve the different features we want to implement, so now it’s time to actually write code.</p><h3>Thinking in JavaScript…</h3><p>I have to admit, it’s something. Coming from the back-end/infra world and mostly working with Python or Terraform on a daily basis, it sounded quite unnatural to write JavaScript at first…</p><p>As usual, when you don’t know, you look for best practices in documentation. I quickly understood that the (P)React world offered two ways of doing things:</p><ul><li>The former way of writing <strong>classes</strong></li><li>The newer way introduced in React v16.8 (2018) of using <strong>hooks </strong>(which also exist in <a href="https://preactjs.com/guide/v10/hooks/">Preact</a>)</li></ul><p>Watching <a href="https://www.youtube.com/watch?v=wXLf18DsV-I">90% Cleaner React With Hooks by Ryan Florence — React Conf 2018</a> was the trigger that led me to adopt a functional style using hooks over the former class definitions.</p><p>Here an implementation of Amplify authentication using Preact written in a functional style:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db49ee9d6ba0a10221f95322e62b1674/href">https://medium.com/media/db49ee9d6ba0a10221f95322e62b1674/href</a></iframe><h3>Conclusion</h3><p>Web development in 2020 offers tons of possibilities no matter what your skill set is! Remember that the good old SPA (single page application) is not the only choice and other approaches do have their pros as well (SEO, editable content from a CMS…).</p><p>This blog post also showcases the fact that static site generators like Hugo can actually be leveraged in more complex JAMStack projects or extended to use cases you might not think of (like turning your Hugo website into a static API according to this <a href="https://forestry.io/blog/build-a-json-api-with-hugo/">Forestry.io blogpost</a>, which is something we also did in this project).</p><blockquote>👉<strong> With that, I will let you go JAM on your stack now</strong></blockquote><h3>Resources</h3><ul><li><em>[ebook] </em><a href="https://www.netlify.com/oreilly-jamstack/">Modern Web Development on the Jamstack</a> from Netlify</li><li><em>[blogpost]</em> <a href="https://medium.com/@_zouhir/preact-meets-cms-building-lightweight-portable-widget-components-e151622e2ac6">Preact meets CMS: Building Lightweight Portable Widget Components</a> by Zouhir</li><li><em>[blogpost] </em><a href="https://www.smashingmagazine.com/2020/01/migration-from-wordpress-to-jamstack/">How Smashing Magazine Manages Content: Migration From WordPress To JAMstack</a> by Sarah Drasner</li><li><em>[blogpost]</em> <a href="https://forestry.io/blog/build-a-json-api-with-hugo/">Forestry.io — Enhance Your Hugo JSON API Using Custom Output Formats and Netlify Redirects</a> by Régis Philibert</li><li><em>[blogpost] </em><a href="https://forestry.io/blog/build-a-json-api-with-hugo/">Foresty.io — Build a JSON API With Hugo’s Custom Output Formats</a> by Régis Philibert</li><li><em>[video]</em> <a href="https://www.youtube.com/watch?v=EOQqi6Yun7g">AWS Amplify with Amazon DynamoDB Single Table and Direct AWS Lambda Resolvers with Rick Houlihan</a></li><li><em>[video] </em><a href="https://www.youtube.com/watch?v=wXLf18DsV-I">90% Cleaner React With Hooks by Ryan Florence — React Conf 2018</a></li></ul><p>We’re always looking for new talent! <a href="https://gumgum.com/careers">View jobs</a>.</p><p>Follow us: <a href="https://www.facebook.com/gumguminc">Facebook</a> | <a href="https://twitter.com/gumgum">Twitter</a> | <a href="https://www.linkedin.com/company/167379/">Linkedin</a> | <a href="https://www.instagram.com/gumgum/">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11a02d1d6c9d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/the-frontflip-when-a-devops-enters-the-jamstack-functional-preact-hugo-aws-amplify-11a02d1d6c9d">The Frontflip: When a DevOps enters the JAMStack — Functional Preact / Hugo / AWS Amplify</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop being selfish !  —  Open up Terraform to your team with Atlantis]]></title>
            <link>https://medium.com/gumgum-tech/stop-being-selfish-open-up-terraform-to-your-team-with-atlantis-9b21f40fd73e?source=rss-72fd1473b4e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b21f40fd73e</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[terragrunt]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[atlantis]]></category>
            <dc:creator><![CDATA[Florian Dambrine]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 18:16:50 GMT</pubDate>
            <atom:updated>2020-06-25T18:16:50.365Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stop being selfish ! — Open up Terraform to your team with Atlantis</h3><h3><strong>What is Terraform ?</strong></h3><p><a href="https://www.terraform.io/">Terraform</a> is a powerful software from <a href="https://www.hashicorp.com/">Hashicorp</a> that allows you to write <a href="https://en.wikipedia.org/wiki/Infrastructure_as_code">infrastructure as code</a> in a declarative way to provision and manage any cloud, infrastructure, or service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUVctbFK6f_bf1K3lm1UmQ.png" /><figcaption>Terraform Workflow (Source: <a href="https://www.terraform.io/">https://www.terraform.io/</a>)</figcaption></figure><p>The terraform plan command (similar to git diff output) is used to create an execution plan. Terraform performs a refresh, and then determines what actions are necessary to achieve the desired state specified in the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fw6uoPbb4kkEMM1rBgIWuA.png" /><figcaption>Output generate by terraform plan command (Source: <a href="https://github.com/dmlittle/scenery">https://github.com/dmlittle/scenery</a>)</figcaption></figure><p>Once the execution plan looks good, terraform apply command is used to apply the changes required to reach the desired state of the configuration according to the plan.</p><p>Ops engineers are usually responsible of operating such infrastructure software, but what if we could change that and unblock developers to build even faster ?</p><h3>Infrastructure ownership ?</h3><p>It is well known that DevOps engineers are usually known as “Gods” due to their high set of privileges to operate a cloud environment. Tools like Terraform often requires this set of privileges specially if the goal is to capture 100% of resources as code (IAM, EC2, RDS, R53, …).</p><p>As powerful as it can be, Terraform can also be heavily destructive if not used wisely. This is why most of the time its usage is restricted to a limited amount of engineers (mostly DevOps) within the company.</p><p>Part of the daily routine of a DevOps / Automation engineer working with Terraform is to write a <a href="https://www.terraform.io/docs/modules/index.html">Terraform module</a> (a set of resources logically grouped together) that captures the needs of a new piece of software in order to automate its setup.</p><blockquote>Modules are what libraries are to software engineers — A set of <strong>functions</strong> that can be called with <strong>input parameters</strong>.</blockquote><p>Let’s take an example to better illustrate this statement. Here is an architecture diagram of an existing AWS environment (<strong><em>green</em></strong>) and the infrastructure required by a new project (<strong><em>yellow</em></strong>) that needs to be captured as code. Let’s assume that the <strong><em>green</em></strong> environment is an image metadata API and the <strong><em>yellow </em></strong>one is a new feature to process images metadata asynchronously and store them in S3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*I-7JRHsdFioqTLFZeBL6rA.png" /><figcaption>Infrastructure diagram of an existing environment on the left and a new project requirements on the right</figcaption></figure><p>The resulting Terraform module may look like this:</p><pre>terraform-modules<br>├── autoscaling     # Module used to setup <strong><em>green</em></strong> infra<br>│   └── *.tf<br>├── database        # Module used to setup <strong><em>blue</em></strong> infra<br>│   └── *.tf<br>├── load-balancer   # Module used to setup <strong><em>purple</em></strong> infra<br>│   └── *.tf<br><em>---------------------------------------------------------------<br># New module<br>--------------------------------------------------------------<br></em>└── new-project      # New module to setup <strong><em>yellow</em></strong> infra<br>    ├── s3.tf.       #-- Create S3 bucket<br>    ├── sqs.tf       #-- Create SQS queue<br>    ├── outputs.tf.  #-- Return important values to the caller <br>    └── variables.tf #-- Input variables provided by module users</pre><p>A module can be instantiated that way using <a href="https://terragrunt.gruntwork.io/">Terragrunt</a> (a thin wrapper for Terraform):</p><pre><em># File: mycloud/production/async-images/terragrunt.hcl</em></pre><pre><em># Terragrunt will copy the Terraform configurations specified by the<br># source parameter.</em></pre><pre><em>terraform</em> {<br>  source = &quot;&lt;path&gt;/terraform-modules//new-project&quot;)}&quot;<br>}</pre><pre><em># These are the variables (defined in variables.tf) we have to pass <br># in to use the module specified in the source above.</em></pre><pre>inputs = {<br>  environment = &quot;production&quot;<br>  s3_bucket_name = &quot;s3-async-images&quot;<br>  sqs_queue_name = &quot;sqs-async-images&quot;<br>}</pre><p>Wait a minute… The skills required to write a Terraform module is surely on the Ops team, but <strong>any developer </strong>with minimum guidance and tooling can easily write the above file (&lt;10 lines worth of content) or contribute to such a repository !</p><p>If tomorrow your team needs a similar setup for asynchronous page and video processing. It is as trivial as making new calls to the same module but with different input variables !</p><p>There are a lot of advantages opening up <a href="https://en.wikipedia.org/wiki/Infrastructure_as_code">infrastructure as code</a> repositories to your developer teams:</p><ul><li>Raise awareness on the infrastructure setup helping developer to better understand how all pieces stick together.</li><li>Reduce time to troubleshoot issues as developers gained a global vision on the overall infrastructure.</li><li>Remove potential blockers by enabling more people to do Ops work.</li><li>Constraint Ops to think about real code practices for Terraform (Pull request, code reviews, CI / CD pipeline, no Terraform from laptop).</li></ul><p>Let’s see how you can enable anyone in your team run Terraform/Terragrunt automations safely !</p><h3>Here comes Atlantis !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*Qwm1roOKHXCzdxfCoOlPBQ.png" /><figcaption><a href="https://www.runatlantis.io/">Atlantis</a></figcaption></figure><p><a href="https://www.runatlantis.io/">Atlantis</a> is an application for automating Terraform via pull requests. It is deployed as a standalone application into your infrastructure. No third-party has access to your credentials.</p><p>It listens for <a href="https://github.com/">GitHub</a>, <a href="https://about.gitlab.com/">GitLab</a> or <a href="https://bitbucket.org/product">Bitbucket</a> webhooks about Terraform pull requests. It then runs terraform plan and comments with the output back on the pull request.</p><p>When you want to apply, comment atlantis apply on the pull request and Atlantis will run terraform apply and comment back with the output.</p><figure><img alt="Atlantis Pull request review workflow on Bitbucket" src="https://cdn-images-1.medium.com/max/1024/1*cZARUvF51z82H4zv8klpjQ.png" /><figcaption>Atlantis Pull request workflow on Bitbucket Cloud</figcaption></figure><p>I won’t detail much how to get Atlantis up and running as it’s already well explained in the <a href="https://www.runatlantis.io/docs/">documentation</a>. Here is a high level overview of how Atlantis interact in your workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*2fqG0qW0eL4IqBo8Yi-LWQ.png" /><figcaption>Atlantis Workflow</figcaption></figure><blockquote>At <a href="https://medium.com/u/9d14b5de3c57">GumGum</a> the Machine Learning Engineering team operates an infrastructure made of <strong>80+ Terragrunt instantiation </strong>(provisioning <strong>~1500 </strong><a href="https://www.terraform.io/docs/providers/aws/index.html">AWS resources</a>)<strong> </strong>using<strong> 20 Terraform modules</strong> across <strong>multiple regions</strong> and<strong> accounts</strong>.</blockquote><p>From a simple Cloudwatch Alarm to the <a href="https://docs.confluent.io/current/platform.html#cp-platform">Confluent Platform</a>, Terraform manages our infrastructure on a daily basis.</p><p>Given that the volume of resources managed as code and as a former Senior DevOps Engineer who transitioned back to Software engineering (at 30%), it was more than obvious to enable the team to do Terraform on their own using Atlantis.</p><p>Because the purpose of this post is “stop being selfish !”, I will share some interesting tweaks we did to run Atlantis at scale.</p><h3>Custom Workflows with Atlantis</h3><p>As mentioned earlier we use <a href="https://terragrunt.gruntwork.io/">Terragrunt</a> to keep our Terraform code DRY and maintainable but can Atlantis fit our needs ?</p><ul><li>Yes ! Atlantis developers thought about this use case and offered a way to define <a href="https://www.runatlantis.io/docs/custom-workflows.html#use-cases">custom workflows</a> ! It’s a matter of adding the Terragrunt binary to the official atlantis docker image</li></ul><p>Here is the custom <a href="https://hub.docker.com/repository/docker/lowess/atlantis">Atlantis docker image</a> we use in production that you can find on <a href="https://github.com/Lowess/docker-atlantis">Github</a>:</p><pre>### Dockerfile</pre><pre># Grab image to collect tools from<br>FROM lowess/terragrunt:0.12.24 as tools</pre><pre># Official atlantis image<br>FROM runatlantis/atlantis:v0.13.0<br>COPY --from=tools /usr/local/bin /usr/local/bin<br>COPY --from=tools /opt/.terraform.d /opt/.terraform.d<br>COPY --from=tools /root/.terraformrc /home/atlantis/.terraformrc<br>COPY --from=tools /root/.terraformrc /root/.terraformrc</pre><h3>Rendering atlantis.yaml on the fly</h3><p>Atlantis relies on an atlantis.yaml configuration file, located under your repository root folder (this is what defines which repositories should be under its governance).</p><p>If you want the ability to run Terraform modules individually you will need to list every single path where you have module instantiations...</p><p>A reason to do that is to<strong> speed up</strong> Atlantis plan / applyas it will just act on an individual module instead of trying to plan-all / apply-all an entire folder of modules (Does not hurt but runs for modules that were not changed)</p><pre><em>### &lt;repo&gt; terragrunt layout</em></pre><pre>&lt;repo&gt;/&lt;path&gt;/prod/cloudwatch-alerts/<br>├── dynamodb-pages-reads<br>│   └── terragrunt.hcl<br>└── dynamodb-images-reads<br>    └── terragrunt.hcl</pre><pre><em>### &lt;repo&gt;/atlantis.yaml</em></pre><pre>---<br>version: 3</pre><pre>automerge: true</pre><pre>projects:</pre><pre>  - name: dynamodb-pages-reads<br>    dir: ./&lt;path&gt;/prod/cloudwatch-alerts/dynamodb-pages-reads<br>    workflow: terragrunt<br>    autoplan:<br>      enabled: true<br>      when_modified:<br>        - &quot;./terraform/modules/**/*.tf&quot;<br>        - &quot;**/*.tf&quot;<br>        - &quot;**/terragrunt.hcl&quot;</pre><pre>  - name: dynamodb-images-reads<br>    dir: ./&lt;path&gt;/prod/cloudwatch-alerts/dynamodb-images-reads<br>    workflow: terragrunt<br>    autoplan:<br>      enabled: true<br>      when_modified:<br>        - &quot;./terraform/modules/**/*.tf&quot;<br>        - &quot;**/*.tf&quot;<br>        - &quot;**/terragrunt.hcl&quot;</pre><pre>   ...<br>   [A LONG LIST OF PROJECTS]<br>   ...</pre><p>Because it’s just inhuman to maintain such a file manually (ours is ~400 lines), here is a <a href="https://gist.github.com/Lowess/28bcba7b10cc495b9cbf7d06b5b9fb06">Github Gist Snippet</a> that you can use to generate your atlantis.yaml file with <a href="https://pre-commit.com/">Pre-commit</a> or a simple shell script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e95e9de020ecd8d75527971d71299ca6/href">https://medium.com/media/e95e9de020ecd8d75527971d71299ca6/href</a></iframe><h3>Speed-up Atlantis plan / apply</h3><p>With <a href="https://github.com/runatlantis/atlantis/releases/tag/v0.13.0">Atlantis v0.13 release</a> there was the introduction of parallelism options (parallel_plan / parallel_apply ) 🎉 Yeah !</p><p>Unfortunately this feature is for now limited to <a href="https://www.terraform.io/docs/state/workspaces.html">Terraform workspaces</a> which are not used by Terragrunt… As per this <a href="https://github.com/runatlantis/atlantis/issues/260#issuecomment-637694897">Github discussion on #260</a> it seems doable “<em>in theory”</em> to do it with Terragrunt but unfortunately I did not get luck and ran into unreliable Terraform init steps…</p><p><a href="https://github.com/runatlantis/atlantis/issues/260#issuecomment-637694897">Run plan/apply for multiple projects in parallel · Issue #260 · runatlantis/atlantis</a></p><p>Feel like we can’t do better ? Well there are other knobs to tweak !</p><p>Thanks to this great article from <a href="https://learn.hashicorp.com/terraform/development/running-terraform-in-automation#pre-installed-plugins">Hashicorp blogpost</a> (Which I recommend you to read) We decided to pre-bake all the plugins we are mostly using in terraform so that they don’t need to be downloaded from the <a href="https://registry.terraform.io/">Hashicorp registry</a>.</p><p><a href="https://learn.hashicorp.com/terraform/development/running-terraform-in-automation#pre-installed-plugins">Running Terraform in Automation</a></p><p>Given that it is a recommended practice to constrain <a href="https://www.terraform.io/docs/configuration/terraform.html#specifying-required-provider-versions">only the minimum allowed version</a> in modules, we can easily pre-download the ones we use all over the place in order to make them directly available to Terraform. You can find an example in this <a href="https://github.com/Lowess/docker-terragrunt/">Github repository</a>.</p><p>This literally speeded up Atlantis feedback loop on pull requests !</p><p><a href="https://github.com/Lowess/docker-terragrunt/blob/master/Dockerfile">Lowess/docker-terragrunt</a></p><h3>Conclusion</h3><p>Running Terraform from CI / CD pipelines is far from being trivial if you try to do it on your own… Fortunately Atlantis came to the rescue to ease this process.</p><p>As of today I have seen great engagement and enthusiasm from my peers discovering DevOps daily basis operations !</p><p>If you want to be successful with this product here is my two cents:</p><ul><li>Run a POC on Atlantis (<a href="https://www.runatlantis.io/guide/testing-locally.html">You deploy it locally</a>)</li><li>Identify low risks infrastructure pieces that can be controlled by Atlantis workflow</li><li>Onboard your developers by doing a high level knowledge transfer on Terraform / Terragrunt</li><li>Make sure to <a href="https://www.runatlantis.io/docs/apply-requirements.html#supported-requirements">require approval</a> of an Ops person before applying code in production</li><li>Enjoy a better experience and a full developer worrkflow moving forward !</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b21f40fd73e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/stop-being-selfish-open-up-terraform-to-your-team-with-atlantis-9b21f40fd73e">Stop being selfish !  —  Open up Terraform to your team with Atlantis</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Karrot — Kafka Lag Reporting at Scale]]></title>
            <link>https://medium.com/gumgum-tech/karrot-kafka-lag-reporting-at-scale-b32061dcc604?source=rss-72fd1473b4e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b32061dcc604</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[lag]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[prometheus]]></category>
            <dc:creator><![CDATA[Florian Dambrine]]></dc:creator>
            <pubDate>Mon, 02 Dec 2019 18:16:01 GMT</pubDate>
            <atom:updated>2019-12-02T18:16:01.309Z</atom:updated>
            <content:encoded><![CDATA[<h3>Karrot — Kafka Lag Reporting at Scale</h3><p><a href="https://kafka.apache.org/">Kafka</a> is a really powerful distributed publish / subscribe software that helps you build complex asynchronous applications. GumGum was an early adopter of this technology and is nowadays running hundreds of brokers across multiple clusters.</p><h4>Kafka monitoring is a must</h4><p>Kafka cluster operations are a thing on their own (scaling clusters in and out, recovering from a dead broker, reassigning partitions across the cluster…) but if you want to build performant client applications based on Kafka you want to pay close attention to your consumers:</p><ul><li>Are they able to keep up with the incoming traffic (consumer lag) ?</li></ul><blockquote><em>Kafka Consumer Lag is an indicator of how much lag there is between Kafka producers and consumers. In other words, how far behind is your consumer compared to the latest produced message in the topic the consumer is reading from.</em></blockquote><ul><li>Is the consumer group in a stable state (consumer rebalancing) ?</li></ul><blockquote><em>Rebalance/Rebalancing: the procedure that is followed by a number of distributed processes that use Kafka clients and/or the Kafka coordinator to form a common group and distribute a set of resources among the members of the group (source : </em><a href="https://cwiki.apache.org/confluence/display/KAFKA/Incremental+Cooperative+Rebalancing%3A+Support+and+Policies"><em>Incremental Cooperative Rebalancing: Support and Policies</em></a><em>).</em></blockquote><p>In a microservice world, whether you run on VMs, ECS or Kubernetes, you may want to adjust the number of running instances / tasks / pods based on the consumer lag, thus making Kafka lag reporting a critical piece of your infrastructure.</p><p>In a Cloud provider like AWS, most of the auto scaling actions get triggered by a<a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html"> CloudWatch alarm</a>. This means that the computed lag for a consumer must be posted to the CloudWatch API in order to be able to adjust the size of an autoscaling group or an ECS service based on this custom metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NCpUvSy6SivbaZrr" /><figcaption>Autoscaling based on Consumer Lag — Consumer lag (orange) / Application instance count (green)</figcaption></figure><p>Running such applications at scale requires solid monitoring especially when Kafka is at the heart of the infrastructure. In a previous blog post, we talked about how we rolled<a href="https://medium.com/gumgum-tech/prometheus-monitoring-at-scale-war-stories-from-the-gumgum-trenches-f66393c52d0a"> Prometheus as a new monitoring solution for our infrastructure</a> to help us collect real time metrics about our systems. It was more than obvious to us that Kafka lag should be made available to <a href="https://prometheus.io/">Prometheus</a> / <a href="https://grafana.com/">Grafana</a> using a<a href="https://prometheus.io/docs/instrumenting/exporters/"> custom exporter</a>.</p><p>It was time for GumGum to improve it’s rusty lag reporting solution in order to fit today’s needs:</p><ul><li>Consumer lag must be reported to CloudWatch in order to trigger ECS autoscaling.</li><li>Consumer lag must be reported to Prometheus so that engineers can access a single monitoring UI (Grafana) to inspect application performance.</li></ul><h4>Rebuild or not rebuild a Consumer lag reporting service — That is the question ?</h4><p>GumGum is a heavy consumer of open source projects. Whenever possible, we try to not rebuild the wheel and leverage existing solutions especially to reduce the overhead of maintaining in-house solutions which are not business specific.</p><p>While looking for a better lag reporting solution years ago we came across<a href="https://github.com/linkedin/Burrow"> Burrow</a> from LinkedIn which is a monitoring companion for Kafka with multiple interesting features:</p><ul><li>NO THRESHOLDS! Groups are evaluated over a sliding window.</li><li>Multiple Kafka Cluster support</li><li>Automatically monitors all consumers using Kafka-committed offsets</li><li>Configurable support for Zookeeper-committed offsets</li><li>Configurable support for Storm-committed offsets</li><li>HTTP endpoint for consumer group status, as well as broker and consumer information</li><li>Configurable emailer for sending alerts for specific groups</li><li><strong>Configurable HTTP client for sending alerts to another system for all groups</strong></li></ul><p>As listed above, Burrow is doing all the heavy lifting around consumers lag monitoring exposing this data over a REST API for multiple clusters. One built-in feature retained our attention, the ability to forward the consumer lag information to an HTTP client.</p><h4>Here comes 🥕<a href="https://github.com/Lowess/karrot">Karrot</a> !</h4><p>We are thrilled to announce the release of<a href="https://github.com/Lowess/karrot"> Karrot</a>, a Kafka lag reporter processing events from Burrow !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Wv1iTfvi4pbT-Gs2" /><figcaption>Karrot Github repository</figcaption></figure><p><a href="https://github.com/Lowess/karrot">Karrot</a> is a simple<a href="https://flask.palletsprojects.com/en/1.1.x/"> Python Flask Webapp</a> that ingests Burrow events sent by Burrow Notifiers which responds to consumer group status evaluations and makes HTTP calls to an outside server, Karrot.</p><p>The core feature of Karrot is simple, Take an incoming JSON event sent by Burrow and forward this metrics to multiple services (CloudWatch, Prometheus, and more if needed…).</p><p>Here is a diagram to help understand the overall infrastructure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AZrhup4mfvHg57xw" /><figcaption>Infrastructure Overview — Karrot / Burrow</figcaption></figure><p>In its first version, Karrot answers our problematic of multi-destination lag reporting by offering a Prometheus lag exporter as well as a CloudWatch lag reporter !</p><p>As shown above it relies on Burrow to send JSON event notifications. This can be achieved using the following Burrow configuration:</p><pre><em>### Section to append in /etc/burrow/burrow.toml</em></pre><pre># Other Burrow settings<br>…</pre><pre>[notifier.karrot]<br>class-name=&quot;http&quot;<br>interval=30<br>threshold=1<br>group-blacklist=&quot;^.*(console-consumer-|python-kafka-consumer-).*$&quot;<br>group-whitelist=&quot;^.*$&quot;<br>send-close=true<br>url-open=&quot;<a href="http://karrot-nlp.k8s.sx.ggops.com/burrow">http://&lt;KARROT_DNS&gt;/burrow</a>&quot;<br>url-close=&quot;<a href="http://karrot-nlp.k8s.sx.ggops.com/burrow">http://&lt;KARROT_DNS&gt;/burrow</a>&quot;<br>template-open=&quot;/etc/burrow/templates/events.tmpl&quot;<br>template-close=&quot;/etc/burrow/templates/events.tmpl&quot;</pre><pre><em>### Content of /etc/burrow/templates/events.tmpl</em></pre><pre>{<br>  &quot;Event&quot;: {{ jsonencoder . }}<br>}</pre><p>Every time Burrow detects an update on a consumer group, events are being passed down to Karrot which will happily ingest the data and distribute it to multiple destinations (CloudWatch, Prometheus).</p><h4>Give 🥕Karrot a shot !</h4><p>If you are running on Kubernetes, you can easily get started with our<a href="https://github.com/Lowess/helm-charts/tree/master/charts/karrot"> Karrot open source helm charts</a> (lucky you we also wrote the first<a href="https://github.com/Lowess/helm-charts/tree/master/charts/burrow"> Burrow open source helm chart</a>).</p><p>Create a <strong>values.yaml </strong>file (reduced to its minimal content) to provide your Kafka and Zookeeper clusters you want to monitor and deploy it on <a href="https://github.com/kubernetes/minikube">Minikube</a>:</p><pre><strong><em>### </em></strong><em>Content of </em><strong><em>values.yaml</em></strong></pre><pre>burrow:<br>  enabled: true</pre><pre>  burrow:<br>    config:<br>      cluster:<br>        mycluster:<br>          servers:<br>            - &lt;KAFKA_DNS&gt;:9092</pre><pre>      consumer:<br>        mycluster:<br>          servers:<br>            - &lt;KAFKA_DNS&gt;:9092<br>      <br>      notifier:<br>        karrot:<br>          className: http<br>          templateClose: events.tmpl<br>          templateOpen: events.tmpl<br>          urlClose: <a href="http://karrot.default.svc.cluster.local/burrow">http://karrot.default.svc.cluster.local/burrow</a><br>          urlOpen: <a href="http://karrot.default.svc.cluster.local/burrow">http://karrot.default.svc.cluster.local/burrow</a><br>      <br>      zookeeper:<br>        rootPath: /burrow-karrot<br>        servers:<br>          - &lt;ZOOKEEPER_DNS&gt;:2181</pre><pre><em>### Add the Repository to Helm</em></pre><pre>$ helm repo add lowess-helm<a href="https://lowess.github.io/helm-charts"> https://lowess.github.io/helm-charts</a></pre><pre><em>### Install Karrot &amp; Burrow with Helm</em></pre><pre>$ helm install --name karrot \<br>      lowess-helm/karrot \<br>      -f <strong><em>values.yaml</em></strong> \<br>      --set karrot.env.AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \<br>      --set karrot.env.AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY</pre><p>On Minikube you can directly access the Karrot service using <strong><em>minikube ip</em></strong><em> </em>and the service <strong><em>nodePort</em></strong><em>:</em></p><pre><em>### Compute service URL</em></pre><pre>$ export KARROT_URL=&quot;http://$(minikube ip):$(kubectl get svc karrot -o=jsonpath=&#39;{.spec.ports[].nodePort}&#39;)&quot;</pre><pre><em>### Show service URL</em></pre><pre>$ echo ${KARROT_URL}<br><a href="http://192.168.99.111:30495/">http://192.168.99.111:30710</a> # &lt;-- The output should look like this</pre><pre><em><br>### Open service URL in your default browser</em></pre><pre>$ open ${KARROT_URL}</pre><p>In a web browser you can navigate the different API endpoints and more particularly the <strong>${KARROT_URL}/metrics </strong>Prometheus endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VzcRkJF3xuUCV-uJ" /><figcaption>Karrot Prometheus metrics endpoint</figcaption></figure><p>From now on, it’s fairly straight forward to configure Prometheus to scrape those metrics and display them in Grafana (Please note that exported metrics are all prefixed with <strong><em>karrot_</em></strong>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mi0IBlTJwC3NiHru" /></figure><h4>References</h4><ul><li>Github Karrot repository:<a href="https://github.com/Lowess/karrot/"> https://github.com/Lowess/karrot/</a></li><li>Karrot DockerHub:<a href="https://hub.docker.com/repository/docker/lowess/karrot"> https://hub.docker.com/repository/docker/lowess/karrot</a></li><li>Karrot Readthedocs:<a href="https://karrot.readthedocs.io/en/latest/#"> https://karrot.readthedocs.io/en/latest/#</a></li><li>Karrot &amp; Burrow Helm-Charts:<a href="https://github.com/Lowess/helm-charts/"> https://github.com/Lowess/helm-charts/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b32061dcc604" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gumgum-tech/karrot-kafka-lag-reporting-at-scale-b32061dcc604">Karrot — Kafka Lag Reporting at Scale</a> was originally published in <a href="https://medium.com/gumgum-tech">GumGum Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>