-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
030ee79
commit 9dbe571
Showing
1 changed file
with
65 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,82 @@ | ||
# Dotnet Build Metrics | ||
# Dotnet Build and Test Metrics: Your F5 Experience, Quantified! | ||
|
||
This is a custom MSBuild task that will measure the time to build each project and publishes the information to a datastore. The intent is to measure and improve developer experience on local workstations. | ||
Welcome to the mono repo that's about to make your dotnet development experience smoother than a well-oiled CI/CD pipeline! We're all about measuring and improving your local dev experience, because who doesn't love a fast F5? | ||
|
||
**_Username and hostname are collected as a part of build information_** | ||
What is the F5 Experience? have a read [here](https://beerandserversdontmix.com/2024/08/15/an-introduction-to-the-f5-experience/) | ||
|
||
``` | ||
{ | ||
"id": "026fe42b-7888-4a76-81ee-2ab431ae4987", | ||
"userName": "aanand", | ||
"cpuCount": 12, | ||
"hostname": "25BVM13", | ||
"platform": 2, | ||
"os": "Microsoft Windows NT 10.0.19042.0", | ||
"timeTaken": "453", | ||
"branch": "master", | ||
"type": ".Net", | ||
"projectName": "Agoda.Cronos.Accommodation", | ||
"repository": "[email protected]:front-end/dotnet-build-metrics.git", | ||
"date": "2021-06-28T02:53:22.1420552Z" | ||
} | ||
``` | ||
## What's in the Box? | ||
|
||
This repo is like a Swiss Army knife for .NET developers. We've got tools for: | ||
|
||
1. Build Metrics: Measure your build times and kiss those coffee breaks goodbye! | ||
2. Startup Metrics: Because waiting for your app to start is so last year. | ||
3. Test Metrics: Know exactly how long your tests are taking (and why your coworker's tests are slower). | ||
|
||
## Build and Startup Metrics: The Dynamic Duo | ||
|
||
### Build Metrics: Time to Compile! | ||
|
||
We've created a custom MSBuild task that measures the build time for each project and sends it off to a datastore. It's like a fitbit for your builds! | ||
|
||
To use it, just install the [`Agoda.Builds.Metrics` NuGet package](https://www.nuget.org/packages/Agoda.Builds.Metrics) to all projects in your solution. It's easier than ordering pizza! | ||
|
||
The task will do a HTTP POST to `http://compilation-metrics/dotnet` (or wherever you tell it to go). See exampel payload [here](examples/dotnetbuild.json). | ||
|
||
| Parameter | Environment Variable | Default Value | | ||
|-------------------------|---------------------------|-----------------------------------| | ||
| Elastic Search Endpoint | BUILD_METRICS_ES_ENDPOINT | http://compilation-metrics/dotnet | | ||
|
||
Pro tip: Set up a CNAME on your internal DNS servers for `compilation-metrics`. Your future self will thank you! | ||
|
||
To use the task simply install the [`Agoda.Builds.Metrics` NuGet package](https://www.nuget.org/packages/Agoda.Builds.Metrics) to all of the projects in your solution, this will automatically enable metrics publication for that project. | ||
### Agoda.DevFeedback.AspNetStartup: Because Startup Time Matters | ||
|
||
Web API URL and the name of the endpoint are taken from environment variables if they are present as per the following table: | ||
This package measures your ASP.NET application's startup time in two exciting flavors: | ||
|
||
|Parameter |Environment Variable |Default Value | | ||
|-----------------------|-------------------------|-------------------------------------| | ||
|Elastic Search Endpoint|BUILD_METRICS_ES_ENDPOINT|http://compilation-metrics/dotnet | | ||
1. From `WebHostBuilder ConfigureServices` until `HostApplicationLifetime OnStarted` (type '.AspNetStartup') | ||
2. From `WebHostBuilder ConfigureServices` until the first HTTP Response (type '.AspNetResponse') | ||
|
||
We recommend create a CNAME on your internal DNS servers for compilation-metrics to point at an internal API that captures the data and stores it. | ||
To enable this magic, set these environment variables: | ||
|
||
1. `ASPNETCORE_ENVIRONMENT` to `Development` (we promise not to slow down your production servers) | ||
2. `ASPNETCORE_HOSTINGSTARTUPASSEMBLIES` to include `Agoda.DevFeedback.AspNetStartup` | ||
|
||
You can set these in your `launchSettings.json`. It's like leaving a note for your future self! | ||
|
||
## Test Metric Collection: Because Tests Should Be Fast Too! | ||
|
||
We've got packages for both `xUnit` and `NUnit`. They're like personal trainers for your tests! | ||
|
||
These packages will POST their data to `http://compilation-metrics/dotnet/nunit` (or wherever `BUILD_METRICS_ES_ENDPOINT` points to). See exampel payload [here](examples/dotnettests.json). | ||
|
||
To install, just run: | ||
|
||
For NUnit: | ||
```bash | ||
dotnet package add Agoda.Tests.Metrics.NUnit | ||
``` | ||
|
||
For xUnit: | ||
```bash | ||
dotnet package add Agoda.Tests.Metrics.xUnit | ||
``` | ||
|
||
Example build log output in Visual Studio using MSBuild. | ||
It's so easy, you might accidentally make your tests faster! | ||
|
||
![](doc/img/VSBuildOutput.PNG) | ||
## The F5 Experience | ||
|
||
Example build log output in Dotnet core CLI. | ||
Remember, we're all about that F5 Experience here. Our goal is to make your development process smoother than a freshly waxed keyboard. Here's what that means for you: | ||
|
||
![](doc/img/DotnetCLIBuildTimeOutput.PNG) | ||
1. **Setup Should Be a Breeze**: You should be able to clone the repo and get up and running faster than you can say "dotnet run". | ||
2. **Fast Feedback Loop**: We want your builds, startups, and tests to run faster than a caffeinated squirrel. If you find yourself waiting, something's wrong. | ||
|
||
## Contributing | ||
|
||
### Agoda.DevFeedback.AspNetStartup NuGet package | ||
We welcome contributions! Whether you're fixing bugs, improving documentation, or adding new features, we appreciate your help in making these tools even better. Check out our [Contributing Guide](CONTRIBUTING.md) for more details on how to get started. | ||
|
||
The goal of this package is to measure the application startup time as an additional metrics that affects developer feedback besides build time. | ||
Monoliths are especially prone to slow startup times on developer laptops and this provides visibility and tracking of improvements/regressions thereof. | ||
Remember, in the world of Dotnet Build and Test Metrics, there are no stupid questions, only unoptimized build times! | ||
|
||
This package measures the ASP.NET application's startup time in two ways. | ||
1) The time from WebHostBuilder ConfigureServices until HostApplicationLifetime OnStarted sent with type '.AspNetStartup'. | ||
2) The time from WebHostBuilder ConfigureServices until the first HTTP Reponse (measured from middleware) sent with type '.AspNetResponse'. | ||
## And Finally... | ||
|
||
Two environment variables are required to be set to enable the measurements. | ||
1) `ASPNETCORE_ENVIRONMENT` needs to be set as `Development` for the functionality to be added. This is so it's only enabled locally and not on production. | ||
2) `ASPNETCORE_HOSTINGSTARTUPASSEMBLIES` needs to be/include `Agoda.DevFeedback.AspNetStartup`. This is for package activation due to the use of [HostingStartup](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.hostingstartupattribute?view=aspnetcore-6.0). | ||
Remember, in software development, there are only two types of projects: those that are measuring their metrics, and those that are still wondering why everything is so slow. With these tools, you'll always know exactly where your time is going. (Spoiler alert: with our help, it won't be going to waste!) | ||
|
||
For convenience these environment variables can be set under the lauch profile of the web application's `launchSettings.json` file and committed to the repository. | ||
Happy coding, and may your builds be ever faster! 🚀 |