Skip to content

Commit 42c89e7

Browse files
committed
Add health check for website and worker
1 parent 67886c3 commit 42c89e7

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

deploy/bicep/function-worker.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ resource worker 'Microsoft.Web/sites@2022-09-01' = {
130130
minTlsVersion: '1.2'
131131
alwaysOn: !isConsumptionPlan
132132
use32BitWorkerProcess: false
133+
healthCheckPath: '/healthz'
133134
appSettings: concat([
134135
{
135136
name: 'AzureFunctionsJobHost__logging__LogLevel__Default'

deploy/bicep/spot-worker.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ resource vmss 'Microsoft.Compute/virtualMachineScaleSets@2021-11-01' = {
262262
settings: {
263263
protocol: 'http'
264264
port: 80
265-
requestPath: '/'
265+
requestPath: '/healthz'
266266
}
267267
}
268268
}

deploy/bicep/website.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ resource website 'Microsoft.Web/sites@2022-09-01' = {
4949
minTlsVersion: '1.2'
5050
alwaysOn: false // I've run into problems with the AAD client certificate not refreshing...
5151
use32BitWorkerProcess: false
52+
healthCheckPath: '/healthz'
5253
appSettings: concat([
5354
{
5455
name: 'AzureAd__Instance'

src/Website/Controllers/HomeController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public ViewResult Index()
2626
return View(_options.Value.ShowAdminMetadata ? _cache : null);
2727
}
2828

29+
[HttpGet("/healthz")]
30+
public ContentResult Health()
31+
{
32+
return Content("The website is alive.");
33+
}
34+
2935
public async Task<RedirectToActionResult> SignOutAndRedirect()
3036
{
3137
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

src/Worker/Functions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Net;
45
using System.Threading.Tasks;
56
using Azure.Storage.Queues.Models;
67
using Microsoft.Azure.Functions.Worker;
8+
using Microsoft.Azure.Functions.Worker.Http;
79

810
namespace NuGet.Insights.Worker
911
{
@@ -33,6 +35,16 @@ public Functions(
3335
_messageProcessor = messageProcessor;
3436
}
3537

38+
[Function("HealthFunction")]
39+
public HttpResponseData HealthFunction(
40+
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "healthz")] HttpRequestData request)
41+
{
42+
var response = request.CreateResponse(HttpStatusCode.OK);
43+
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
44+
response.WriteString("The worker is alive.");
45+
return response;
46+
}
47+
3648
[Function("MetricsFunction")]
3749
public async Task MetricsFunction(
3850
[TimerTrigger("*/10 * * * * *")] TimerInfo timerInfo)

src/Worker/host.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"queues": {
1919
"maxDequeueCount": 10,
2020
"messageEncoding": "none"
21+
},
22+
"http": {
23+
"routePrefix": ""
2124
}
2225
}
2326
}

0 commit comments

Comments
 (0)