Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload-433 add health check function #131

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion BulkFileUploadFunctionApp/BulkFileUploadFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

} // .foreach

} // .Task Run
} // .Task Run

/// <summary>
/// Processeses the given blob created event from the URL provided.
Expand Down Expand Up @@ -250,7 +250,7 @@
throw new TusInfoFileException(e.Message);
}

_logger.LogInformation($"Info file metadata keys: {string.Join(", ", tusInfoFile.MetaData?.Keys.ToList())}");

Check warning on line 253 in BulkFileUploadFunctionApp/BulkFileUploadFunction.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'values' in 'string string.Join(string? separator, IEnumerable<string?> values)'.

Check warning on line 253 in BulkFileUploadFunctionApp/BulkFileUploadFunction.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'values' in 'string string.Join(string? separator, IEnumerable<string?> values)'.

Check warning on line 253 in BulkFileUploadFunctionApp/BulkFileUploadFunction.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'values' in 'string string.Join(string? separator, IEnumerable<string?> values)'.

Check warning on line 253 in BulkFileUploadFunctionApp/BulkFileUploadFunction.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'values' in 'string string.Join(string? separator, IEnumerable<string?> values)'.

return tusInfoFile;
}
Expand Down Expand Up @@ -497,5 +497,10 @@

return filenameSuffix;
}


}


}

1 change: 1 addition & 0 deletions BulkFileUploadFunctionApp/BulkFileUploadFunctionApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.10.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.EventHubs" Version="5.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
53 changes: 53 additions & 0 deletions BulkFileUploadFunctionApp/HealthCheckFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Azure.Storage.Blobs;
using Azure;
using Azure.Storage.Blobs.Models;

namespace BulkFileUploadFunctionApp
{
public static class HealthCheckFunction
{

[Function("HealthCheckFunction")]
public static async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequestData req,
FunctionContext context)
Copy link
Contributor

@rohitpanwar rohitpanwar Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthorizationLevel will be Anonymous instead of Function

{
var logger = context.GetLogger("HealthCheckFunction");

string dEX_AZURE_STORAGE_ACCOUNT_NAME = "DEX_AZURE_STORAGE_ACCOUNT_NAME";
string dexAzureStorageAccountKey = "DEX_AZURE_STORAGE_ACCOUNT_KEY";
string cName = "ndlp-influenzavaccination";
var response = req.CreateResponse();
try
{

String? _dexAzureStorageAccountName = Environment.GetEnvironmentVariable(dEX_AZURE_STORAGE_ACCOUNT_NAME);
String? _dexAzureStorageAccountKey = Environment.GetEnvironmentVariable(dexAzureStorageAccountKey);
String? containerName = Environment.GetEnvironmentVariable(cName);

var connectionString = $"DefaultEndpointsProtocol=https;AccountName={_dexAzureStorageAccountName};AccountKey={_dexAzureStorageAccountKey};EndpointSuffix=core.windows.net";

BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(containerName);
response.StatusCode = (HttpStatusCode)200;
await response.WriteStringAsync("Healthy!");

} catch (RequestFailedException ex)
{

logger.LogError(ex, "Error occurred while checking Blob storage container health.");
response.StatusCode = (HttpStatusCode)500;
await response.WriteStringAsync("Not Healthy!");
}

return response;
}

}

}