Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Script.Diagnostics.HealthChecks;
using Microsoft.Azure.WebJobs.Script.Extensions;
using Microsoft.Azure.WebJobs.Script.WebHost.Configuration;
using Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -151,13 +152,13 @@ static bool Predicate(HttpContext context)

app.UseHealthChecks($"{healthPrefix}/live", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("az.functions.liveness"),
Predicate = r => r.Tags.Contains(HealthCheckTags.Liveness),
ResponseWriter = HealthCheckResponseWriter.WriteResponseAsync,
});

app.UseHealthChecks($"{healthPrefix}/ready", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("az.functions.readiness"),
Predicate = r => r.Tags.Contains(HealthCheckTags.Readiness),
ResponseWriter = HealthCheckResponseWriter.WriteResponseAsync,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
using System.Net.Http.Json;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Diagnostics.HealthChecks;
using Microsoft.Azure.WebJobs.Script.Management.Models;
using Microsoft.Azure.WebJobs.Script.Models;
using Microsoft.Azure.WebJobs.Script.WebHost;
Expand Down Expand Up @@ -334,6 +336,43 @@ public async Task HealthCheck_AdminToken_Succeeds(string uri)
Assert.Equal("{\"status\":\"Healthy\"}", body);
}

[Theory]
[InlineData("/admin/health?expand=true", null)]
[InlineData("/admin/health/live?expand=true", HealthCheckTags.Liveness)]
[InlineData("/admin/health/ready?expand=true", HealthCheckTags.Readiness)]
public async Task HealthCheck_AdminToken_ExpandSucceeds(string uri, string tag)
{
// token specified as bearer token
HttpRequestMessage request = new(HttpMethod.Get, uri);
string token = _fixture.Host.GenerateAdminJwtToken();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
HttpResponseMessage response = await _fixture.Host.HttpClient.SendAsync(request);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

// Not doing a deep validation of the response, just ensuring we get the correct tags.
// The full response body is validated in other tests.
using Stream stream = await response.Content.ReadAsStreamAsync();
JsonDocument json = await JsonDocument.ParseAsync(stream);
JsonElement entries = json.RootElement.GetProperty("entries");

if (string.IsNullOrEmpty(tag))
{
Assert.NotEmpty(entries.EnumerateObject());
}
else
{
bool atLeastOne = false;
foreach (JsonProperty entry in entries.EnumerateObject())
{
atLeastOne = true;
HashSet<string> tags = entry.Value.GetProperty("tags").Deserialize<HashSet<string>>();
Assert.Contains(tag, tags);
}

Assert.True(atLeastOne, "Expected at least one entry to have the specified tag.");
}
}

[Theory]
[InlineData("/admin/health")]
[InlineData("/admin/health/live")]
Expand Down