Search This Blog

Tuesday, 12 November 2019

Wednesday, 30 October 2019

Cross-Platform Unit Testing and Code Coverage with Coverlet

How to check code coverage (using Unit Test cases)

Code coverage and report generation using coverlet (global tool).

Coverlet is a cross-platform code coverage framework for .NET, with support for the line, branch and method coverage. It works with .NET Framework on Windows and .NET Core on all supported platforms.


Steps as below
  • Step 1:Create the SetupGlobalTool.bat file in your project folder.
    Sample path: "C:\YourProjectFolder\BuildCodeCoverageReport\SetupGlobalTool.bat"
  • Step 2: Create the RunCodeCoverage.bat file in your project folder.
    Sample path: "C:\YourProjectFolder\BuildCodeCoverageReport\RunCodeCoverage.bat"
  • Step 3 Execute both file from command prompt respectively.
  • Note: File content provided in below seactions.

SetupGlobalTool.bat


@ECHO OFF

dotnet tool install --global coverlet.console  --ignore-failed-sources

dotnet tool install -g dotnet-reportgenerator-globaltool --ignore-failed-sources

pause

RunCodeCoverage.bat


@ECHO OFF

coverlet "..\TestProjectName\bin\Release\netcoreapp2.2\TestProjectName.dll" --target "dotnet" --targetargs "test ..\TestProjectName\TestProjectName.csproj -c Release --no-build --logger:trx" --threshold 0 --format "opencover" -f json -f lcov  --output "CodeCoverage"

reportgenerator "-reports:CodeCoverage.opencover.xml" "-targetdir:CodeCoverage\Reports"

pause

Note: Create the RunCodeCoverage.bat and SetupGlobalTool.bat file in BuildCodeCoverageReport folder.

Commands

  • Step 1: Install global tools.
    SetupGlobalTool.bat
  • To verify tools has been installed execute below command
    dotnet tool list -g
  • RunCodeCoverage.bat

Note: If command is not recognized, please check the environment variable PATH.

Sample Report

Wednesday, 28 August 2019

Observability

What are Observability?

Observability is the activities that involve measuring, collecting, and analyzing various diagnostics signals from a system. These signals may include metrics, traces, logs, events, profiles and more

  • Log aggregation
  • Application metrics
  • Audit logging
  • Distributed tracing
  • Exception tracking
  • Health check API
  • Log deployments and changes

Log aggregation

Definition Use a centralized logging service that aggregates logs from each service instance. The users can search and analyze the logs. They can configure alerts that are triggered when certain messages appear in the logs.

Issue: Handling a large volume of logs requires substantial infrastructure.
Note: Any solution should have minimal runtime overhead.

Application metrics

DefinitionInstrument a service to gather statistics about individual operations. Aggregate metrics in centralized metrics service, which provides reporting and alerting. There are two models for aggregating metrics:

  • push - the service pushes metrics to the metrics service
  • pull - the metrics services pulls metrics from the service

Examples
  • Instrumentation libraries:
    • Prometheus client libraries
  • Metrics aggregation services:
    • Prometheus

Benefits:It provides deep insight into application behavior
Drawbacks: Metrics code is intertwined with business logic making it more complicated
Issues: Aggregating metrics can require significant infrastructure

Audit logging

Definition: Record user activity in a database.

Benefits: Provides a record of user actions
Drawbacks: The auditing code is intertwined with the business logic, which makes the business logic more complicated

Distributed Tracing

Definition:

  • Assigns each external request a unique external request id
  • Passes the external request id to all services that are involved in handling the request
  • Includes the external request id in all log messages
  • Records information (e.g. start time, end time) about the requests and operations performed when handling a external request in a centralized service

Benefits:
  • It provides useful insight into the behavior of the system including the sources of latency
  • It enables developers to see how an individual request is handled by searching across aggregated logs for its external request id

Issues: Aggregating and storing traces can require significant infrastructure
Note:
  • External monitoring only tells you the overall response time and number of invocations - no insight into the individual operations
  • Any solution should have minimal runtime overhead
  • Log entries for a request are scattered across numerous logs

Tools:

Exception tracking

Definition Report all exceptions to a centralized exception tracking service that aggregates and tracks exceptions and notifies developers.

Benefits: It is easier to view exceptions and track their resolution
Drawbacks: The exception tracking service is additional infrastructure
Note:
  • Exceptions must be de-duplicated, recorded, investigated by developers and the underlying issue resolved
  • Any solution should have minimal runtime overhead

Health Check API

Definition A service has an health check API endpoint (e.g. HTTP /health) that returns the health of the service. The API endpoint handler performs various checks, such as

  • the status of the connections to the infrastructure services used by the service instance
  • the status of the host, e.g. disk space
  • application specific logic

A health check client - a monitoring service, service registry or load balancer - periodically invokes the endpoint to check the health of the service instance.

Benefits: The health check endpoint enables the health of a service instance to be periodically tested
Drawbacks: The health check might not sufficiently comprehensive or the service instance might fail between health checks and so requests might still be routed to a failed service instance

Log deployments and changes

Definition Log every deployment and every change to the (production) environment.

Benefits: Enables deployments and changes to be easily correlated with issues leading to a faster resolution.

Technology stack for Observability

  • https://opentracing.io/ - OpenTracing is not a download or a program. Distributed tracing requires that software developers add instrumentation to the code of an application, or to the frameworks used in the application.

Tuesday, 27 August 2019

Microservice

What are microservices?

Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are

  • Highly maintainable and testable
  • Loosely coupled
  • Independently deployable
  • Organized around business capabilities
  • Owned by a small team

Reference

Thursday, 22 August 2019

Started with ASP.NET Core Logging

ASP.NET Core using Microsoft.Extensions.Logging

.Net Core Logging : .NET Core supports a logging API that works with a variety of built-in and third-party logging providers.


Video


Quick start with below video


Quick start with below video

Thursday, 8 August 2019

Getting Started with Kubernetes

Kubernetes Webinars

Video - Load your gun in short time.

Kubernetes Volumes 3: How things connect

Kubernetes 101: Master

Kubernetes 101: Nodes

Kubernetes Basics

Kubernetes: Understanding Resources via YAML, Deployments, Replica Sets, and Pods

How to Setup Jaeger on local using docker

Introduction to Jaeger

Jaeger : open source, end-to-end distributed tracing Monitor and troubleshoot transactions in complex distributed systems .

Steps as below for setup Jaeger:
  1. Docker Pull Command as below
    docker pull jaegertracing/all-in-one
  2. Jaeger run in docker as below
    docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:latest
  3. open "http://localhost:16686/" url in browser.

Screen shot


Screen Shot 1: You will see below screen when execute commands


Screen Shot 2: You will get Jeager UI

Monday, 22 July 2019

.NET Core on Windows using the command line

Hello, Console App!

using System;

namespace HelloWordConsoleApp {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}

How to run

CMD Command>dotnet run HelloWordConsoleApp.csproj
or
CMD Command>dotnet run

Output C:\HelloWordConsoleApp>dotnet run HelloWordConsoleApp.csproj
Hello World!

Elasticsearch CRUD Using POSTMAN

Get Elastisearch version

GET https://[Elastic search connection string]

Get list of indexes in Elasticsearch

GET https://[Elastic search connection string]/_cat/indices?v

Get list of mappings in Elasticsearch

GET https://[Elastic search connection string]/_mapping

Get specified index data in Elasticsearch

GET https://[Elastic search connection string]/Index-Name

Get specified index search in Elasticsearch

GET https://[Elastic search connection string]/Index-Name/_search

Delete specific index in Elasticsearch

DELETE https://[Elastic search connection string]/Index-Name

Reference

Wednesday, 26 June 2019

Getting started with NewRelic

Introduction to New Relic APM

New Relic's software analytics product for application performance monitoring (APM) delivers real-time and trending data about your web application's performance and the level of satisfaction that your end users experience. With end to end transaction tracing and a variety of color-coded charts and reports, APM visualizes your data, down to the deepest code levels.


Get started with the .NET Core agent
Before installing the New Relic .NET Core agent:
  • .NET agent configuration - Required environment variables.

Steps as below
  1. Signup on https://newrelic.com/
  2. Get the "service licenseKey"
  3. Create Sample Application for .Net / .Net Core
  4. From the Package Manager command prompt, type Install-Package NewRelic.Agent and press Enter. When you build your project, the .NET agent folder will be copied to your build output directory
  5. Set environment variables.
  6. update newrelic.config file content for service licenseKey="key from new relic portal"
  7. update newrelic.config file content for SampleWebApplication

Screen shot

Source Code: NewRelic Sample code

Screen Shot 1: You will get New relic dashboard link in logs
Screen Shot 2:
Screen Shot 3:

Solution for Common Mistake

  • Monitor whole system.
  • Monitoring important things about system.
  • Monitor early enough.

Elasticsearch - Nodes, clusters, and shards

Elastic Stack Video - Load your gun in short time.   Beginner's Crash Course to Ela...

Recent Post