Skip to content

Commit 89e6002

Browse files
authored
Merge pull request Xabaril#133 from lfraile/master
Release Gate extension for Azure DevOps
2 parents 320f674 + 3cd62ee commit 89e6002

11 files changed

+259
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,6 @@ ASALocalRun/
332332

333333
# MFractors (Xamarin productivity tool) working folder
334334
.mfractor/
335+
336+
# Azure DevOps tasks ignores
337+
AzureDevOpsTasks/**/*.vsix
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"id": "8ED8698B-C924-4C07-A340-A040778B4FDD",
3+
"name": "AspNetCoreHealthCheckReleaseGate",
4+
"friendlyName": "Asp.Net Core Health Check Release Gate",
5+
"description": "Azure DevOps release gate based on Asp.Net Core Health Checks.",
6+
"author": "lfraile",
7+
"helpMarkDown": "[More Information](https://github.com/lfraile/AspNetCore.Diagnostics.HealthChecks/blob/master/AzureDevOpsTasks/README.md)",
8+
"category": "Utility",
9+
"preview": "true",
10+
"visibility": [
11+
"Release"
12+
],
13+
"runsOn": [
14+
"Server",
15+
"ServerGate"
16+
],
17+
"version": {
18+
"Major": 1,
19+
"Minor": 0,
20+
"Patch": 0
21+
},
22+
"instanceNameFormat": "Asp.Net Core Health Check Release Gate",
23+
"groups": [
24+
{
25+
"name": "aspNetCoreHealthCheckEndpoint",
26+
"displayName": "Asp.Net Core Health Check endpoint information",
27+
"isExpanded": true
28+
},
29+
{
30+
"name": "aspNetCoreHealthChecks",
31+
"displayName": "Asp.Net Core Health Checks information",
32+
"isExpanded": true
33+
}
34+
],
35+
"inputs": [{
36+
"name": "aspNetCoreHealthCheckUri",
37+
"type": "string",
38+
"label": "Url configured for Asp.Net Core Health Check ",
39+
"defaultValue": "",
40+
"required": true,
41+
"groupName":"aspNetCoreHealthCheckEndpoint",
42+
"helpMarkDown": "Url configured in Asp.Net Core Health Check to get general checks"
43+
},{
44+
"name": "aspNetCoreHealthCheckText",
45+
"type": "string",
46+
"label": "Value of healthy response for the check to verify",
47+
"required": true,
48+
"defaultValue": "Healthy",
49+
"groupName":"aspNetCoreHealthChecks",
50+
"helpMarkDown": "Text to check when for **Healthy** Health Check when verifying particular checks. By default is **Healthy**. Needs [AspNetCore.HealthChecks.UI](https://www.nuget.org/packages/AspNetCore.HealthChecks.UI/) package."
51+
}, {
52+
"name": "aspNetCoreHealthCheckCheck",
53+
"type": "string",
54+
"label": "Name of check to verify",
55+
"required": false,
56+
"defaultValue": "",
57+
"groupName":"aspNetCoreHealthChecks",
58+
"helpMarkDown": "Name of the configured check in Asp.Net Core Health Check to verify. Needs [AspNetCore.HealthChecks.UI](https://www.nuget.org/packages/AspNetCore.HealthChecks.UI/) package."
59+
}
60+
],
61+
62+
"execution": {
63+
"HttpRequest": {
64+
"Execute": {
65+
"EndpointId": "",
66+
"EndpointUrl": "$(aspNetCoreHealthCheckUri)",
67+
"Method": "GET",
68+
"Body": "",
69+
"Headers": "{\"Content-Type\":\"application/json\"}",
70+
"WaitForCompletion": "false",
71+
"Expression": "or(eq('$(aspNetCoreHealthCheckCheck)', ''), eq(jsonpath('$.entries.$(aspNetCoreHealthCheckCheck).status')[0],'$(aspNetCoreHealthCheckText)'))"
72+
}
73+
}
74+
}
75+
}

AzureDevOpsTasks/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Azure DevOps ASP.NET Core health checks extensions
2+
3+
## Azure DevOps Release Gate for ASP.NET Core Health checks
4+
5+
This Release Gate allows you to add a new Gate based on [**Asp.Net Core Health Checks**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2).
6+
7+
More info on [**Release Gates for Azure DevOps**](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/approvals/gates?view=azure-devops)
8+
9+
### Prerequisites
10+
To use this extension first you must configure **Asp.Net Core Health Checks** in your desired application, to install it follow this [walk-through](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2)
11+
12+
You also need the [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) as the Release Gate needs to call the endpoint returning the json information on Health Checks.
13+
14+
Once installed and deployed, you can start use this extenstion to use Health Checks as Release Gates
15+
16+
### Configuration
17+
18+
#### Basic Health Check
19+
20+
When using int the basic mode, the Release Gate just checks the HTTP 200 OK result from the global Health Check.
21+
![Gate basic snapshot](images/AspNetCoreHealthCheckBasic.png)
22+
23+
To configure the extension in its basic form,you need to provide following parameters:
24+
- *Display name*: Name for the Release Gate.
25+
- *Url for Asp.Net Core Health Check*: Full url for your Asp.Net Core Health Check (i.e.: https://mywebsite.com/health).
26+
- *Value of healthy response for the check to verify*: By default, when using [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) it is *Healthy*, but it can be changed in the [**Health Checks Response Writer**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2#customize-output) so review it when configuring it.
27+
28+
#### Filter by particular Health Check
29+
With this, we can filter out for a particular Health Check from the configured ones, but this requires a little bit more configuration both in the tasks and in your application code.
30+
31+
When configuring it, we also need to modify the HTTP responses for it, as the Release Gates always checks for the HTTP 200 OK code, and if some Health Checks fails, by default it returns an HTTP 503 Error, which will make the Release Gate fail no matter if the particular Health Check is Healthy or not. So we need to add this code when configuring Health Check UI:
32+
``` C#
33+
app.UseHealthChecks("/healthz", new HealthCheckOptions()
34+
{
35+
Predicate = _ => true,
36+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
37+
ResultStatusCodes =
38+
{
39+
[HealthStatus.Healthy] = StatusCodes.Status200OK,
40+
[HealthStatus.Degraded] = StatusCodes.Status200OK,
41+
[HealthStatus.Unhealthy] = StatusCodes.Status200OK
42+
}
43+
});
44+
```
45+
46+
> **IMPORTANT**: If you plan to use this along with basic general check for different purposes you will need another endpoint with the default configuration on *ResultStatusCodes* so it returns HTTP 503 Error when one of them fails.
47+
48+
The tasks configuration will be like this:
49+
![Gate filtered snapshot](images/AspNetCoreHealthCheckParticularCheck.png)
50+
- *Display name*: Name for the Release Gate.
51+
- *Url for Asp.Net Core Health Check*: Full url for your Asp.Net Core Health Check (i.e.: https://mywebsite.com/health).
52+
- *Name of check to verify*: Name of the check configured in **Health Checks** to verify. (i.e.: sqlserver).
53+
- *Value of healthy response for the check to verify*: By default, when using [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) it is *Healthy*, but it can be changed in the [**Health Checks Response Writer**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2#customize-output) so review it when configuring it.
54+
Loading
Loading
3.68 KB
Loading
Binary file not shown.

AzureDevOpsTasks/overview.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Azure DevOps ASP.NET Core health checks extensions
2+
3+
## Azure DevOps Release Gate for ASP.NET Core Health checks
4+
5+
This Release Gate allows you to add a new Gate based on [**Asp.Net Core Health Checks**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2).
6+
7+
More info on [**Release Gates for Azure DevOps**](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/approvals/gates?view=azure-devops)
8+
9+
### Prerequisites
10+
To use this extension first you must configure **Asp.Net Core Health Checks** in your desired application, to install it follow this [walk-through](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2)
11+
12+
You also need the [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) as the Release Gate needs to call the endpoint returning the json information on Health Checks.
13+
14+
Once installed and deployed, you can start use this extenstion to use Health Checks as Release Gates
15+
16+
### Configuration
17+
18+
#### Basic Health Check
19+
20+
When using int the basic mode, the Release Gate just checks the HTTP 200 OK result from the global Health Check.
21+
![Gate basic snapshot](images/AspNetCoreHealthCheckBasic.png)
22+
23+
To configure the extension in its basic form,you need to provide following parameters:
24+
- *Display name*: Name for the Release Gate.
25+
- *Url for Asp.Net Core Health Check*: Full url for your Asp.Net Core Health Check (i.e.: https://mywebsite.com/health).
26+
- *Value of healthy response for the check to verify*: By default, when using [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) it is *Healthy*, but it can be changed in the [**Health Checks Response Writer**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2#customize-output) so review it when configuring it.
27+
28+
#### Filter by particular Health Check
29+
With this, we can filter out for a particular Health Check from the configured ones, but this requires a little bit more configuration both in the tasks and in your application code.
30+
31+
When configuring it, we also need to modify the HTTP responses for it, as the Release Gates always checks for the HTTP 200 OK code, and if some Health Checks fails, by default it returns an HTTP 503 Error, which will make the Release Gate fail no matter if the particular Health Check is Healthy or not. So we need to add this code when configuring Health Check UI:
32+
``` C#
33+
app.UseHealthChecks("/healthz", new HealthCheckOptions()
34+
{
35+
Predicate = _ => true,
36+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
37+
ResultStatusCodes =
38+
{
39+
[HealthStatus.Healthy] = StatusCodes.Status200OK,
40+
[HealthStatus.Degraded] = StatusCodes.Status200OK,
41+
[HealthStatus.Unhealthy] = StatusCodes.Status200OK
42+
}
43+
});
44+
```
45+
46+
> **IMPORTANT**: If you plan to use this along with basic general check for different purposes you will need another endpoint with the default configuration on *ResultStatusCodes* so it returns HTTP 503 Error when one of them fails.
47+
48+
The tasks configuration will be like this:
49+
![Gate filtered snapshot](images/AspNetCoreHealthCheckParticularCheck.png)
50+
- *Display name*: Name for the Release Gate.
51+
- *Url for Asp.Net Core Health Check*: Full url for your Asp.Net Core Health Check (i.e.: https://mywebsite.com/health).
52+
- *Name of check to verify*: Name of the check configured in **Health Checks** to verify. (i.e.: sqlserver).
53+
- *Value of healthy response for the check to verify*: By default, when using [**Health Check UI**](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) it is *Healthy*, but it can be changed in the [**Health Checks Response Writer**](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2#customize-output) so review it when configuring it.
54+

AzureDevOpsTasks/vss-extension.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"manifestVersion": 1.0,
3+
"id": "vss-services-aspnetcorehealthcheck-extensions",
4+
"name": "Asp.Net Core Health Check extensions",
5+
"publisher": "luisfraile",
6+
"version": "1.0.0",
7+
"public": false,
8+
"description": "Azure DevOps Asp.Net Core Health Check extensions.",
9+
"categories": ["Azure Pipelines"],
10+
"Tags": ["AspNetCoreHealthCheck",
11+
"Liveness",
12+
"Release",
13+
"ReleaseGates",
14+
"DevOps"],
15+
"targets": [{
16+
"id": "Microsoft.VisualStudio.Services.Cloud"
17+
}],
18+
"demands": [],
19+
"icons": {
20+
"default": "images/aspnethealth-task.png"
21+
},
22+
"branding": {
23+
"color": "#3B3E43",
24+
"theme": "dark"
25+
},
26+
"screenshots": [{
27+
"path": "images/AspNetCoreHealthCheckBasic.png"
28+
},
29+
{
30+
"path": "images/AspNetCoreHealthCheckParticularCheck.png"
31+
}],
32+
"files": [
33+
{
34+
"path": "AspNetCoreHealthCheckReleaseGate"
35+
},
36+
{
37+
"path": "images/aspnethealth-task.png",
38+
"addressable": true
39+
},
40+
{
41+
"path": "images/AspNetCoreHealthCheckBasic.png",
42+
"addressable": true
43+
},
44+
{
45+
"path": "images/AspNetCoreHealthCheckParticularCheck.png",
46+
"addressable": true
47+
}
48+
],
49+
"content": {
50+
"details": {
51+
"path": "readme.md"
52+
}
53+
},
54+
"links": {
55+
"license": {
56+
"uri": "https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/LICENSE"
57+
}
58+
},
59+
"contributions": [{
60+
"id": "aspnetcorehealthcheck-gate-task",
61+
"type": "ms.vss-distributed-task.task",
62+
"targets": ["ms.vss-distributed-task.tasks"],
63+
"properties": {
64+
"name": "AspNetCoreHealthCheckReleaseGate"
65+
}
66+
}]
67+
}

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ HealthChecks UI supports automatic discovery of k8s services exposing pods that
239239

240240
You can get more information [here](./doc/k8s-ui-discovery.md)
241241

242+
## HealthChecks as Release Gates for Azure DevOps Pipelines
243+
244+
HealthChecks can be used as [Release Gates for Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/approvals/gates?view=azure-devops) using this [Visual Studio Market place Extension](https://marketplace.visualstudio.com/items?itemName=luisfraile.vss-services-aspnetcorehealthcheck-extensions).
245+
246+
Check this [README](./AzureDevOpsTasks/README.md) on how to configure it.
247+
242248
## Tutorials, demos and walkthroughs on ASP.NET Core HealthChecks
243249

244250
- [ASP.NET Core HealthChecks and Kubernetes Liveness / Readiness by Carlos Landeras](./doc/kubernetes-liveness.md)

0 commit comments

Comments
 (0)