Hello Visitor from 🌎

Welcome to the Ranbook 🎉

  • I’ll be sharing my experiences here. 🙂

ASP.NET Core WebAPI Payload Logging with Serilog

Problem Statement Imagine debugging a tricky API integration where you’re getting intermittent errors. You suspect the data being sent is the culprit, but you’re flying blind. Wouldn’t it be great if you could see exactly what’s going over the wire?. For some API-based applications, logging the payload for a given transaction is helpful from both audit and monitoring perspectives. While it’s generally not recommended to log the request or response body due to performance/compliance/security considerations, if there is a need for such a requirement and you understand all the risks, then hopefully this guide provides one of the many ways to achieve it. In this article, we will look at how to create JSON structured log events for HTTP API request/response transactions in an ASP.NET Core Web API using the Serilog logger and the HTTP Logging Middleware provided by Microsoft. Goal By the end of this article, you’ll be able to: ...

February 23, 2025 Â· 6 min Â· Imran

Python SonarQube Code Coverage & Quality

In this article, we will look at how to run pylint, bandit, pytest and coverage utilities to generate and upload code coverage, quality reports to SonarQube server. Required Software Docker: To run SonarQube and SonarQube CLI containers. Python3 pip3: To install required dependencies. Python3.x-venv: Optional but recommended. SonarQube Setup Run following commands to bring SonarQube Docker. Let’s create docker network first so our Sonar CLI container can interact with SonarQube Server. docker network create sonar-network Bring SonarQube Server up. docker run \ --network sonar-network \ --name sonarqube \ -p 9000:9000 \ sonarqube:10.6-community Login to SonarQube & Create Token to upload reports to server at http://localhost:9000/ Login(admin/admin) → Reset Password → Administration → Security → Users → admin → Tokens → Create Token ...

November 28, 2024 Â· 2 min Â· Imran

AWS ECS Deployments with Helm Templates

Typically, helm is used for creating deployment charts for kubernetes platform but I like the helm templating features to generate YAML specifications which can be used to deploy to any platform. AWS Elastic Container Service(ECS) is another platform where you can run container workloads in AWS Cloud. While I won’t go deep into AWS ECS platform or setting up cluster in this article, we will quickly look at how we can deploy a service to an existing ECS cluster with Helm Templates and AWS CLI. ...

August 10, 2024 Â· 4 min Â· Imran

Java8 Alpine Dockerfile Curl

As of Alpine Linux 3.3 there exists a new --no-cache option for apk. It allows users to install packages with an index that is updated and used on-the-fly and not cached locally: FROM openjdk:8-jre-alpine RUN apk --no-cache add curl This avoids the need to use --update and remove /var/cache/apk/* when done installing packages. Reference - https://github.com/gliderlabs/docker-alpine/blob/master/docs/usage.md

August 3, 2024 Â· 1 min Â· Imran

Spring Boot Dynamic Beans Example

You can create dynamic & configuration driven beans in Spring Boot in following way. Note: Below example full code is available at https://github.com/imran9m/spring-boot-dynamic-beans For the example, Let’s create dynamic RestClient beans with customized connection timeout and user-agent configuration to use anywhere we want. Let’s go with following configuration to manage customized properties for two dynamic RestClient beans. application.yml restClients: clients: - clientName: test1 connectionTimeout: 6000 responseTimeout: 6000 userAgent: test1 - clientName: test2 connectionTimeout: 5000 responseTimeout: 5000 userAgent: test2 Now, let’s load this configuration into custom configuration properties record. DynamicRestBuilderProperties.java ...

January 2, 2025 Â· 4 min Â· Imran

Fluentd Conditional Matches Based on Environment Variables

You can enable/disable FluentD Matches with environment variables in following way. Below is fluent.conf. <source> @type dummy dummy {"hello":"world"} @label @DUMMY tag dummy </source> <label @DUMMY> <match dummy> @type copy copy_mode deep <store> @type relabel @label @OPENSEARCH </store> <store> @type relabel @label @ELASTICSEARCH </store> </match> </label> <label @OPENSEARCH> @include "#{ENV['FLUENTD_OPENSEARCH']}" </label> <label @ELASTICSEARCH> @include "#{ENV['FLUENTD_ELASTICSEARCH']}" </label> Following is the content for fluent-elasticsearch.conf. For testing purpose, we will send events to stdout. ...

November 18, 2024 Â· 1 min Â· Imran

Get PublicIP of ECS Fargate Task with AWS Java SDK

You will need to make multiple AWS API calls to get Public IPv4 address. Here are the steps. Once you perform taskRun operation. Keep taskFullArn from Output. With above taskArn and cluster name, make describeTasks operation call. Example - AmazonECS client = AmazonECSClientBuilder.standard().build(); DescribeTasksRequest request = new DescribeTasksRequest().withTasks("c5cba4eb-5dad-405e-96db-71ef8eefe6a8"); DescribeTasksResult response = client.describeTasks(request); Above API will give you a response with network attachment details. "attachments": [ { "id": "xxxxx-d02c-4a9d-ae79-xxxxxxx", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-xxxxx" }, { "name": "networkInterfaceId", "value": "eni-e5aa89a3" }, { "name": "macAddress", "value": "xxxxx" }, { "name": "privateIPv4Address", "value": "172.31.94.215" } ] } ] Take networkInterfaceId from above API response and make following call. Call AWS EC2 describeNetworkInterfaces. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/ec2/AmazonEC2Client.html#describeNetworkInterfaces-com.amazonaws.services.ec2.model.DescribeNetworkInterfacesRequest- Example - ...

August 3, 2024 Â· 1 min Â· Imran

Fluentd Multiple Filters Matches for Same Source

You can try using plugins copy and relabel to achieve this. Example configuration looks like this. //One Source <source> @type tail tag service path /tmp/l.log format json read_from_head true </source> //Now Copy Source Events to 2 Labels <match service> @type copy <store> @type relabel @label @data </store> <store> @type relabel @label @pi2 </store> </match> //@data Label, you can perform desired filter and output file <label @data> <filter service> ... </filter> <match service> @type file path /tmp/out/data </match> </label> //@pi2 Label, you can perform desired filter and output file <label @pi2> <filter service> ... </filter> <match service> @type file path /tmp/out/pi </match> </label> This Routing examples article has few more ways to do it by re-writing tag etc., but for me I like working with labels and above looks simple. ...

August 3, 2024 Â· 1 min Â· Imran