<?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 Akhlaq Malik on Medium]]></title>
        <description><![CDATA[Stories by Akhlaq Malik on Medium]]></description>
        <link>https://medium.com/@imalik8088?source=rss-f59e4dcbe256------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vWkMWLONY_nJy6iGNJJEqA.png</url>
            <title>Stories by Akhlaq Malik on Medium</title>
            <link>https://medium.com/@imalik8088?source=rss-f59e4dcbe256------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:13:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imalik8088/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[Kafka, where are all my messages ?]]></title>
            <link>https://medium.com/@imalik8088/kafka-where-are-all-my-messages-95002de7ef38?source=rss-f59e4dcbe256------2</link>
            <guid isPermaLink="false">https://medium.com/p/95002de7ef38</guid>
            <category><![CDATA[mirrormaker]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Akhlaq Malik]]></dc:creator>
            <pubDate>Wed, 26 Jan 2022 13:14:19 GMT</pubDate>
            <atom:updated>2022-01-26T13:14:19.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9EV6JmX4x-q9tX1Nd75qw.jpeg" /></figure><p><a href="https://imalik8088.de/posts/kafka_where_are_all_my_messages/">original blogpost </a>on my website</p><p>Recently I got the chance to help a customer moving from a Helm based deployment of Apache Kafka in Kubernetes to the Strimzi, which manages the deployment of Kafka in Kubernetes with an operator. In the final phase, I had to transfer the data to the newly deployed Apache Kafka.</p><h3>Setting the scope</h3><p>The customer is using compacted topics (cleanup.policy=compact and log.rentention.ms=-1) as the default configuration for all topics in Apache Kafka, so they’re using it somehow like a database where messages are produced with an unique ID and are nulled afterwards when it is required to delete a message.</p><p>I’ve used Kafka Mirror Maker 2 and the appropriate resources provided by Strimzi KafkaMirrorMaker2 to transfer the data. The setup and configuration of the MirrorMaker2 resource was quite intuitive and self-explanatory. But we were missing messages based on the total count between the original and the mirrored topic. This was quite annoying, and there was not an obvious pattern or ratio between the topics. Looking through millions of messages and comparing them wouldn’t be smart either 😀.</p><p>I was a bit surprised by the result and behavior — how would one build a resilient event-sourcing architecture if not every message in a compacted topic would be mirrored? The confusion and questions are still not fully answered yet in my head. My assumption was that the first and the last value of the same message key in a Kafka consumer batch are being mirrored and the state changes of the same key in between are ignored or better to say, compacted. In order to verify my assumption, to make sure that the customer is not losing any data, and to avoid sleepless nights, I’ve written a Python script to compare the contents of the topics.</p><h3>Fetching the data</h3><p>Before dumping the messages of a topic, I was running the Mirror Maker and made sure that the consumer lag was already down to zero. One thing to note here is that the throughput of topics were luckily not very high. This made my life a bit easier during the stopping of the data fetching process. For fetching the messages, including the key, timestamp, partition, and value, into a file, I’ve used the following command in the CLI:</p><pre>/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \<br>--property print.key=true \<br>--property print.timestamp=true \<br>--property print.partition=true \<br>--property key.separator=&#39;::&#39; \<br>--topic topicxx \<br>--from-beginning &gt; /tmp/topicxx.txt</pre><p>Fetching data from the old and mirrored topic should be done at best in the same terminal and in background, so that both processes could be stopped simultaneously. The output of the files should look like this.</p><pre># output of the the topicxx.txt<br>CreateTime:1637768143839::Partition:2::KEY1::VALUE1CreateTime:1637768153839::Partition:0::KEY2::VALUE1<br>CreateTime:1637768163339::Partition:2::KEY1::null<br>CreateTime:1637768163839::Partition:2::KEY1::VALUE2</pre><h3>The comparing script</h3><p>In the final step, I’ve compared the output with the attached Python script: python diff-kafka-messages.py old-topic.txt mirrored-topic.txt. Before going through the script, I’d like to show you the output of the comparison.</p><pre>------------- STARTING CHECK -------------<br>parsing old-topic.txt<br>parsed messages: 394 and 178 unique messages<br>parsing mirrored-topic.txt<br>parsed messages: 345 and 178 unique messages<br>************ STATISTICS ************<br>msg keys not found in old-topic.txt set()<br>msg keys not found in mirrored-topic.txt set()<br>modified {}<br>same value 178</pre><p>The starting block gives one an overview of the message count and the unique messages in a topic based on the key. The more interesting part is in the statistics block, where in an ideal scenario, the first three values are empty, as in the example. The first two are quite self-explanatory. The modified block outputs the difference if the key exists in both topics, but the last value of a message is not the same. The last output should ideally have the same count as the uniqueness of the messages in one topic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af9a13473f52d2ab8962c0f180bd40a9/href">https://medium.com/media/af9a13473f52d2ab8962c0f180bd40a9/href</a></iframe><p>Mainly, this script consists of three main functions, 1) parsing the files, 2) reordering based on the key, and 3) comparing the two inputs. One limiting factor could be the in-memory processing, so this might probably get stuck with a very large amount of topic (GB’s).</p><h3>Conclusion</h3><p>Luckily I was able to verify my assumptions like mentioned in the post with the script with whom I was able to double-check the successful migration to a Strimzi based deployment for a production environment in the insurance sector. The customer was quite happy, reassured with the result and was able to go forward with the migration of all Apache Kafka clients to the newly deployed Strimzi without having the feeling of missing any data, without having the same overall message count in the topics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95002de7ef38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tired of repeated gitlab-ci files? Includes to the rescue!]]></title>
            <link>https://medium.com/@imalik8088/tired-of-repeated-gitlab-ci-files-includes-to-the-rescue-17225532812a?source=rss-f59e4dcbe256------2</link>
            <guid isPermaLink="false">https://medium.com/p/17225532812a</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <dc:creator><![CDATA[Akhlaq Malik]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 08:01:01 GMT</pubDate>
            <atom:updated>2019-02-04T08:01:01.096Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bhX95aDIc38Cq1N1jRYh-Q.jpeg" /></figure><p>Building pipelines aka Continuous Integration and Continuous Delivery (CI/CD) are not really new buzzwords in the tech industry or as sexy as bitcoin and friends, but I’m still quite excited about the recent release of the GitLab CE 11.7 Version which was released on <a href="https://about.gitlab.com/2019/01/22/gitlab-11-7-released/">22nd January 2019</a>. In this post we will have a look to newly added feature in GitLab CI where we will</p><blockquote>MAKE THE GITLAB-CI.YML DRY AGAIN</blockquote><h3>TL;DR</h3><p>As of GitLab CE version 11.7, you can use include commands to include your tasks from other .yml files. This is a big deal, because you don‘t have to repeat your self in each of your projects any more. Especially in projects that consist of a large number of microservices sharing (parts) of the pipeline definition is major win.</p><p>Follow me for the <a href="https://gitlab.com/imalik8088/gitlab-ci-include-test"><strong>demo project</strong></a> and the <a href="https://gitlab.com/imalik8088/gitlab-ci-pipeline">shared repo for job definitions</a>.</p><h3>GitLab</h3><p>Even after the acquisition of Github by Microsoft, I still am a big fan and daily visitor of Github to look for new things around in the tech projects of my interest.</p><p>However, since approx. 1.5 years I‘m often confronted with GitLab installations at work and customers to serve as the internally hosted git service and I‘m kind of getting more and more to know about the strength of GitLab and the ecosystem around that, which is actually quite impressive. GitLab helps you as a developer to be more productive where it avoiding switches between for example Jenkins for your pipeline and code repository in Gogs.</p><h3>Introduction</h3><p>Writing pipelines in Gitlab CI is quite an easy task when compared to writing Jenkins pipelines, at least for me. To be honest, I’m still trying to hide my Jenkins stuff that is related to private projects. On the other hand, GitLab CI is quite easy to understand and has great <a href="https://docs.gitlab.com/ce/ci/yaml/">documentation</a> where you can start right away without learning any special programming language (e.g. Groovy).</p><h3>Usage of Include Tag</h3><p>So the central part of this post is the newly available <a href="https://docs.gitlab.com/ce/ci/yaml/#include">include tags</a> feature in the Gitlab CE 11.7 version. Using them, you have the possibility to <strong>include</strong> other CI definitions, therefore allowing you to re-use your jobs from other files outside of your main repository. It is also possible to include remote .yaml files from other organizations. In the following, I will present some practical examples and some personal experience with this new feature.</p><p>In the following sections we will build the following pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*jZaB0jPK6MBz6b3othJZnw.png" /><figcaption><a href="https://gitlab.com/imalik8088/gitlab-ci-include-test/pipelines/45549758">Demo pipeline for this Post</a></figcaption></figure><h3>1. Include snippets from the same repo to build your pipeline</h3><p>The simplest way to extract your pipeline jobs from the main .gitlab-ci.yml is to move out the job definitions to a separate directory inside the same repo. In the following example, I moved the job definitions to the ci directory.</p><pre>.<br>├── .gitlab-ci.yml<br>├── ci<br>│   └── local-job.yml</pre><p>The local-job.yml file echos some variable and also demonstrates the functionality to override job definitions that have already been defined in the main gitlab-ci.yml file, here the script and variables keys.</p><pre>include:<br>  - local: &#39;/ci/local-job.yml&#39;</pre><pre>variables:<br>  OVERRIDE_VAR: &quot;OVERRIDE VALUE IN CI FILE&quot;<br>  VAR1: &quot;OVERRIDE VAR 1 FROM CI FILE&quot;<br>  DEBUG: &#39;TRUE&#39;<br><br>local-job:<br>  script:<br>    - echo &quot;OVERRIDE FROM SCRIPT BLOCK OF MAIN GITLAB CI&quot;<br>    - echo $OVERRIDE_VAR</pre><pre># --- OUTPUT OF THE JOB<br># $ echo &quot;before_script from &#39;include-local&#39; task&quot;<br># <strong>before_script</strong> from &#39;include-local&#39; task  <br># $ echo &quot;OVERRIDE FROM SCRIPT BLOCK OF MAIN GITLAB CI&quot;<br># OVERRIDE FROM SCRIPT BLOCK OF MAIN GITLAB CI  <br># $ echo $OVERRIDE_VAR<br># OVERRIDE VALUE IN CI FILE</pre><h3>2. Include a job definition from another repository within the same organization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*WUTAQWkub7zJgHVMP-I-DA.jpeg" /></figure><p>Having some parts of your build in a separate file can help clean up big pipeline definitions, but especially with multiple repositories this is still too much repetition. For this use-case, GitLab also allows you to include from a another repository in the same organization:</p><pre>include:<br>  - project: &#39;imalik8088/gitlab-ci-pipeline&#39;<br>  file: &#39;/maven-package.yml&#39;<br><br>maven-package:<br>  artifacts:<br>    paths:<br>      - target/gitlab-ci-1.0-SNAPSHOT.jar</pre><p>This includes a file called maven-package.yml from the same GitLab organization but a <strong>different</strong> repository. Here again, you are able to change the default behavior by overriding the blocks or variables. This job definition will <strong>expand </strong>the original job definition, where we are defining a project-specific artifact where a .jar by the java application is been used to define it as an artifact in the context of GitLab. This comes in quite handy when you don’t want any defaults but project-specific definition.</p><h3>3. Include a job definition from a URL</h3><p>The third and last option we will look at, is to include a job definition file via an arbitrary URL. This is even more powerful than the previous options, because you are free to query any http endpoint that returns the file. Here is an example of that:</p><pre>include:<br>  - remote: &#39;https://gitlab.com/imalik8088/gitlab-ci-pipeline/raw/master/build-docker.yml&#39;</pre><pre>build-docker:<br>  variables:<br>    IMAGE_NAME: gitlab-ci-java<br>  dependencies:<br>    - maven-package</pre><p>In this job definition, we are building a docker image. You have to define usually some extra code if you want to use docker in your CI (better known as Docker-in-Docker). This ceremony is now hidden inside an external job definition. The main steps can still be overridden which leads to more concise pipelines where the boilerplate can be hidden behind the scenes. In this example, we are depending on the maven-package job where the artifact is transferred to this job definition and is used to build the docker image including the compile, test .jar from a previous stage.</p><h3>Notes</h3><ul><li>One thing to note here is, that although you are defining your stages in the remote job definition you have to list all of the stage in the main .gitlab-ci file which defines the order in which jobs will be executed.</li><li>I have included in the demo project a <a href="https://gitlab.com/imalik8088/gitlab-ci-include-test/blob/master/old-without-includes.yml">gitlab ci file</a> from a personal project were its about <strong>125 lines</strong> of code and lot of repetitions. We can imagine how this gitlab ci file can benefit from the new feature described in this post and almost every organization have repetitive jobs like build, test, coverage, build docker images, deploy, etc.</li></ul><h3>Conclusion</h3><p>Gitlab and Gitlab CI have been build in the era of cloud-native applications and the whole integration of GitLab and CI/CD makes the whole DevOps lifecycle a breeze. With the newly added feature to include jobs definition from a local definition, a central repository or remote URL, we can finally get rid of all the repetition in our build definitions.</p><p><em>Thanks for the review </em><a href="https://twitter.com/markus1189"><em>Markus</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17225532812a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>