<?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 Mohit Mahajan on Medium]]></title>
        <description><![CDATA[Stories by Mohit Mahajan on Medium]]></description>
        <link>https://medium.com/@mahajanmohit?source=rss-d10278eb078------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lMYhUc1-2Qy0uzbX0Qg7-w.png</url>
            <title>Stories by Mohit Mahajan on Medium</title>
            <link>https://medium.com/@mahajanmohit?source=rss-d10278eb078------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:23:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahajanmohit/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[Integrating SonarQube with Azure DevOps]]></title>
            <link>https://mahajanmohit.medium.com/integrating-sonarqube-with-azure-devops-750c1a3db7e8?source=rss-d10278eb078------2</link>
            <guid isPermaLink="false">https://medium.com/p/750c1a3db7e8</guid>
            <category><![CDATA[sonar]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[code-coverage]]></category>
            <category><![CDATA[sonarqube]]></category>
            <dc:creator><![CDATA[Mohit Mahajan]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 21:35:10 GMT</pubDate>
            <atom:updated>2024-12-03T17:45:31.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*jwYUxwlICo47i0Et74tl_g.png" /></figure><p>Enhance your Azure DevOps pipeline with a focus on code quality and security. This practical guide provides a detailed walkthrough of integrating SonarQube with Azure DevOps, including actionable code snippets. Discover how to leverage SonarQube’s automated code analysis capabilities to identify and resolve issues early, ensuring only high-quality code makes it to production.</p><p><strong>Prerequisites</strong>:</p><ul><li><a href="https://helm.sh/docs/intro/install/">Helm</a></li><li><a href="https://kubernetes.io/docs/tasks/tools/">Kubectl</a></li><li>A Kubernetes cluster</li></ul><h3>Deploying community edition using Helm</h3><p>Authenticate to your cluster from CLI and deploy community edition using helm and run the following commands to install helm chart:</p><pre>helm repo add sonarqube https://SonarSource.github.io/helm-chart-sonarqube<br>helm repo update<br>kubectl create namespace sonarqube<br>helm upgrade --install -n sonarqube sonarqube sonarqube/sonarqube </pre><p>Configure your ingress once deployed. This will be later used to create Azure DevOps service connection and accessing SonarQube dashboard.</p><h3>Integrate with Azure DevOps Pipelines</h3><p>Add SonarQube Extension to your Azure DevOps organization from <a href="https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube">marketplace</a></p><h4>1. Add a new SonarQube Service Connection</h4><ol><li>In Azure DevOps, go to <strong>Project settings &gt; Service connections</strong></li><li>Add a new service connection of type <strong>SonarQube</strong></li><li>Enter your SonarQube server url:https://your.kubernetes.ingress.com</li><li>Enter an existing token, or a newly generated token from sonar dashboard <strong>SonarQube dashboard &gt; Administration &gt; Users &gt; Tokens</strong></li><li>Enter a memorable connection name.</li><li>Create the service connection.</li></ol><h4>2. Configure Azure DevOps pipelines</h4><p>In Azure DevOps, add Sonar Analysis stage to your pipeline.</p><p><strong>SonarQubePrepare@7</strong> task sets up the pipeline to analyze. This prepares the environment by configuring authentication, specifying the SonarQube project details and initializing necessary build variables.</p><pre>- task: SonarQubePrepare@7<br>  inputs:<br>    SonarQube: &quot;service_connection_name&quot;<br>    scannerMode: &quot;cli&quot;<br>    configMode: &quot;manual&quot;<br>    cliProjectKey: &quot;unique projectkey [pipeline name]&quot;<br>    cliSources: &quot;$(System.DefaultWorkingDirectory)/&quot;</pre><p><strong>SonarQubeAnalyze@7 </strong>task performs the actual static code analysis of your project using SonarQube Scanner, it processes the source code and collects the metrics.</p><pre>- task: SonarQubeAnalyze@7<br>  inputs:<br>    jdkversion: &quot;JAVA_HOME_17_X64&quot;</pre><p><strong>SonarQubePublish@7 </strong>task is the final step in SonarQube analysis process. It retrieves the analysis results from the SonarQube server and displays them in Azure DevOps pipeline summary, the detailed report can be viewed on SonarQube dashboard.</p><pre>- task: SonarQubePublish@7<br>  inputs:<br>    pollingTimeoutSec: &quot;300&quot;</pre><h4>3. Code Coverage</h4><p>It’s a critical aspect of maintaining code quality during software development. It measures the percentage of your code that is covered by <strong>automated tests</strong>, helping teams identify untested parts of codebase.</p><p>Use the following snippet if you have to include your coverage reports in sonar analysis.</p><pre>- task: SonarQubePrepare@7<br>  inputs:<br>    SonarQube: &quot;service_connection_name&quot;<br>    scannerMode: &quot;cli&quot;<br>    configMode: &quot;manual&quot;<br>    cliProjectKey: &quot;unique projectkey [pipeline name]&quot;<br>    cliSources: &quot;$(System.DefaultWorkingDirectory)/&quot;<br>    extraProperties: |<br>      sonar.projectVersion=1.0<br>      sonar.sources=$(System.DefaultWorkingDirectory)/<br>      sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/coverage.xml<br>      sonar.exclusions=**/test/**</pre><blockquote>Make sure you add a task/stage which installs necessary libraries, run tests on your application and generate <strong>coverage report</strong> before the above task.</blockquote><p>For more details refer <a href="https://learn.microsoft.com/en-in/azure/devops/pipelines/tasks/reference/sonar-qube-prepare-v7?view=azure-pipelines">documentation</a></p><p>Here’s everything from above compiled into one stage</p><pre># Run tests and create coverage report <br># ...<br><br>- stage: SonarAnalysis<br>  jobs:<br>    - job: test<br>      continueOnError: false<br>      steps:<br>        - task: SonarQubePrepare@7<br>          inputs:<br>            SonarQube: &quot;service_connection_name&quot;<br>            scannerMode: &quot;cli&quot;<br>            configMode: &quot;manual&quot;<br>            cliProjectKey: &quot;unique projectkey [pipeline name]&quot;<br>            cliSources: &quot;$(System.DefaultWorkingDirectory)/&quot;<br>            extraProperties: |<br>                sonar.projectVersion=1.0<br>                sonar.sources=$(System.DefaultWorkingDirectory)/<br>                sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/coverage.xml<br>                sonar.exclusions=**/test/**<br><br>        - task: SonarQubeAnalyze@7<br>          inputs:<br>            jdkversion: &quot;JAVA_HOME_17_X64&quot;<br><br>        - task: SonarQubePublish@7<br>          inputs:<br>            pollingTimeoutSec: &quot;300&quot;<br><br># Build stage<br># ...</pre><p><strong>Note</strong>: If you are using SonarQube <strong>Community Edition</strong> at the time of writing this article, <a href="https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube">SonarQube extension</a> from <strong>Azure DevOps marketplace</strong> includes a variable in pipeline task (sonar.branch.name) which is not supported by community edition so as a result your pipelines would fail. So as a workaround in this case is to add a PowerShell after SonarQubePrepare@7 task, this will remove this variable.</p><pre>- task: PowerShell@2<br>  inputs:<br>    targetType: &quot;inline&quot;<br>    script: |<br>      $params = &quot;$env:SONARQUBE_SCANNER_PARAMS&quot; -replace &#39;&quot;sonar.branch.name&quot;:&quot;[\w,/,-]*&quot;\,?&#39;<br>          Write-Host &quot;##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$params&quot;</pre><h4>Build Validation</h4><p>Build validation is a critical step in CI/CD where the code is analyzed and <strong>tested before</strong> it’s merged into <strong>production</strong> branch. By running validations in this manner, you can enforce quality gates and block changes that don&#39;t meet your organizations code quality standards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCuHcCuDh9GygFbct2kzIQ.png" /></figure><p>Build validation will trigger sonar pipeline when a pull request is raised. Pull request will be merged only if this pipeline succeeds.</p><p>I recommend creating a separate pipeline with SonarAnalysis in your main branch to trigger during build validation.</p><p><strong>Steps to add build validation to your branch:</strong></p><ol><li>Open build validation Repos &gt; Branches &gt; click more options for the branch want to add validation &gt; Branch policies &gt; Policies</li><li>Build Validation &gt; Add new build policy</li><li>Select Sonar-Validation pipeline</li><li>Trigger: Manual</li><li>Policy requirement: required</li><li>Save</li></ol><blockquote>Note: To use SonarQube with build validation, you need SonarQube <strong>Developer Edition</strong></blockquote><p>Thank you for reading! If you found this guide helpful or have any questions, feel free to connect with me on <a href="http://www.linkedin.com/in/mohit-mahajan-941929216">LinkedIn</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=750c1a3db7e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Centralized Logging with Elastic Stack]]></title>
            <link>https://mahajanmohit.medium.com/centralized-logging-with-elastic-stack-2d5890d37e3f?source=rss-d10278eb078------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d5890d37e3f</guid>
            <dc:creator><![CDATA[Mohit Mahajan]]></dc:creator>
            <pubDate>Sun, 11 Aug 2024 19:58:08 GMT</pubDate>
            <atom:updated>2024-09-03T11:46:11.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*B1F4-yOU8nOK9xE8M61yNA.png" /></figure><blockquote>logging is one of the important parts of every software. With the traditional architecture we had a few sources of logging so analyze and find issues in them was not so hard but today with Microservice Architecture we have to deal with many dependent and independent services which each of them has it’s own logging mechanism and a few replications in different servers which is near impossible to analyze their logs without any Big Data techniques.</blockquote><h3>Importance of Centralized Logging</h3><p><strong>1. Centralized storage:</strong> So by copying logs to a central repository, we can store all our logs in one place, making it easier to search, analyze, and troubleshoot issues. This can be especially useful in distributed environments where logs may be scattered across multiple clusters or servers.</p><p><strong>2. Improved visibility</strong>: By storing logs in a central repository, you can gain better visibility into the health and performance of your application or system. This can help you identify patterns, trends, and issues that may be difficult to detect otherwise.</p><p><strong>3. Compliance and auditing</strong>: This can help you comply with regulations and auditing requirements by providing a complete and secure record of all events and activities.</p><p><strong>4. Faster issue resolution</strong>: By having all logs in one place, you can quickly and easily identify the root cause of issues and resolve them faster. This can help to minimize downtime and improve the overall reliability of your application or system.</p><p><strong>5. Scalability</strong>: Centralized logging can be more scalable than local logging because it can handle large volumes of logs from multiple sources.</p><h3>What is Elastic Stack?</h3><blockquote>The ELK stack is an acronym used to describe a stack that comprises three popular projects: Elasticsearch, Logstash, and Kibana. Often referred to as Elasticsearch, the ELK stack gives you the ability to aggregate logs from all your systems and applications, analyze these logs, and create visualizations for application and infrastructure monitoring, faster troubleshooting, security analytics, and more.</blockquote><p>ELK is mostly used for the log management and for the analytics purpose in various scenarios such as:</p><ul><li>To troubleshoot the issues of application which are generated in production servers.</li><li>ELK can monitor the health of an application and the performances of the applications.</li><li>And, to analyze log data for the business intelligence which can be used for the gain the insights into customer behavior ,product usage, and other business metrics.</li></ul><h3>Elasticsearch</h3><blockquote>Elasticsearch is a distributed search and analytics engine built on Apache Lucene. Support for various languages, high performance, and schema-free documents makes Elasticsearch an ideal choice for various log analytics and search use cases.</blockquote><p>Elasticsearch provides near real-time search and analytics for all types of data. Whether you have structured or unstructured text, numerical data, or geospatial data, Elasticsearch can efficiently store and index it in a way that supports fast searches. You can go far beyond simple data retrieval and aggregate information to discover trends and patterns in your data. And as your data and query volume grows, the distributed nature of Elasticsearch enables your deployment to grow seamlessly along with it.</p><h3>Logstash</h3><blockquote>Logstash is a lightweight, open-source, server-side data processing pipeline that allows you to collect data from various sources, transform it on the fly, and send it to your desired destination. It is most often used as a data pipeline for Elasticsearch and features prebuilt open-source plugins that can help you easily index your data, it’s a popular choice for loading data into Elasticsearch.</blockquote><p><strong><em>Easily load unstructured data</em></strong></p><p>to ingest unstructured data from various data sources including system logs, website logs, and application server logs.</p><p><strong><em>Prebuilt filters</em></strong></p><p>so, you can readily transform common data types, index them in Elasticsearch, and start querying without having to build custom data transformation pipelines.</p><p><strong><em>Flexible plugin architecture</em></strong></p><p>over 200 plugins already available on GitHub, it is likely that someone has already built the plugin that you need to customize your data pipeline. But if one is not available that suits your requirements, you can easily create one yourself.</p><h3>Kibana</h3><blockquote>Kibana is a data visualization and exploration tool used for log and time-series analytics, application monitoring, and operational intelligence use cases. It offers powerful and easy-to-use features such as histograms, line graphs, pie charts, heat maps, and built-in geospatial support.</blockquote><ul><li><strong>Interactive charts </strong>offers intuitive charts and reports that you can use to interactively navigate through large amounts of log data. You can dynamically drag time windows, zoom in and out of specific data subsets, and get reports to extract actionable insights from your data.</li><li><strong>Mapping support<em> </em></strong>Kibana comes with powerful geospatial capabilities, so you can seamlessly layer in geographical information on top of your data and visualize results on maps.</li><li><strong>Prebuilt aggregations and filters<em> </em></strong>you can run various analytics like histograms, top N queries, and trends in just a few steps.</li></ul><p><strong>Easily accessible dashboards </strong>You can easily set up dashboards, reports and share them with others. All you need is a browser to view and explore the data.</p><h3>Beats</h3><blockquote>Lightweight data shippers, send data from hundreds or thousands of machines and systems to Logstash or Elasticsearch.</blockquote><ul><li><strong>FileBeat </strong>— Lightweight shippers for logs and other data</li><li><strong>PacketBeat</strong> — For monitoring network data</li><li><strong>WinlogBeat</strong> — For capturing windows event logs</li><li><strong>AuditBeat</strong> — Monitor user activity and processes</li><li><strong>HeartBeat</strong> — For uptime monitoring</li><li><strong>MetricBeat</strong> — Used for capturing system related metrics like CPU usage, Heap Usage etc.</li></ul><h3>Pipelines to monitor logs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*wdLtEvRpCtHjOEndvF6dmA.png" /><figcaption>Fig. Elastic stack pipelines</figcaption></figure><p>In the pathway shown by the <strong>red </strong>arrow, Filebeat clients directly push the raw log lines to an Elasticsearch server. So here unstructured log lines (which are raw string messages) will get indexed by Elasticsearch and you will have to face many difficulties in visualizing what you want in Kibana. As a solution to this, you can have an Elasticsearch Ingest Node to preprocess the log lines to a structured pattern, using regex Processors like grok.</p><p>In the pipeline in <strong>blue</strong>, Logstash can take log lines as inputs through its Input plugins, preprocess and send them to Elasticsearch. So you have to configure Logstash to read log lines through its File Input Plugin and preprocess them using Filter plugins. But to do this you have to deploy a Logstash instance per application node. Logstash runs on JVM and consumes a considerable amount of resources which may harm your application performance.</p><p>So the most recommended pipeline is the one in <strong>green </strong>arrows. Where Filebeat clients; lightweight log shippers, are deployed per application server to read log lines from the log files and forward them to Logstash. Elastic guarantees that Filebeat will “never miss a beat” (logline) and its backpressure-sensitive protocol will never overload the pipeline.</p><p>Filebeat sends number of fields regarding a logline to Logstash. We can use simple If’s on these fields to filter the loglines for various grok patterns.</p><p>Finally, you can build graphs and dashboards in Kibana with the structured log data you have pushed into Elasticsearch.</p><h4>Explore more with documentation</h4><p><a href="https://www.elastic.co/guide/en/elastic-stack/current/installing-elastic-stack.html">Installing the Elastic Stack</a></p><p>H<a href="https://www.elastic.co/demo-gallery/observability-overview">ands-on demo to learn how to bring your logs, metrics, and traces together for complete visibility into your application environment.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d5890d37e3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>