Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active March 19, 2021 06:56
Show Gist options
  • Save gsscoder/ff78ee1ec22eeaa3afcb43274af04956 to your computer and use it in GitHub Desktop.
Save gsscoder/ff78ee1ec22eeaa3afcb43274af04956 to your computer and use it in GitHub Desktop.
Simple C# availability canary Function App
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
namespace HealthTest2
{
public class CanaryFunction
{
readonly ILogger _logger;
public CanaryFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger("Function.CanaryFunction.User");
}
[FunctionName("FunctionOK")]
public Task<IActionResult> RunOk(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "ok")] HttpRequest req)
{
_logger.LogInformation("Helth test request: OK");
return Task.FromResult<IActionResult>(new OkObjectResult("OK"));
}
[FunctionName("FunctionBAD")]
public Task<IActionResult> RunBad(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "bad")] HttpRequest req)
{
_logger.LogInformation("Helth test request: BAD");
return Task.FromResult<IActionResult>(new BadRequestObjectResult("BAD"));
}
[FunctionName("FunctionERR")]
public Task<IActionResult> RunErr(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "err")] HttpRequest req)
{
_logger.LogInformation("Helth test request: ERR");
throw new Exception("ERR");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment