Skip to content

Commit

Permalink
Add ENV_FUNCTION_VERSION parameter (#3)
Browse files Browse the repository at this point in the history
* Add ENV_FUNCTION_VERSION parameter

* Updated version in ReadMe

* azure-functions & python-dotenv update
  • Loading branch information
bardabun authored Mar 3, 2024
1 parent 5e60f34 commit 40d804f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions LogzioShipper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
RETRY_WAIT_FIXED = 2 # seconds for retry delay
ENV_MAX_TRIES = int(os.getenv('MAX_TRIES', 3))
ENV_LOG_TYPE = os.getenv('LOG_TYPE', "eventHub")
ENV_FUNCTION_VERSION = os.getenv('FUNCTION_VERSION', '1.0.0')

# Thread and Queue Configuration
ENV_THREAD_COUNT = int(os.getenv('THREAD_COUNT', 4))
Expand Down Expand Up @@ -135,8 +136,15 @@ def process_eventhub_message(event):
logs = []
for line in message_body.splitlines():
log_entry = json.loads(line)

# Append version number to log
log_entry['function_version'] = ENV_FUNCTION_VERSION

# Check if this log entry contains nested logs under 'records'
if 'records' in log_entry and isinstance(log_entry['records'], list):
for record in log_entry['records']:
# Ensure nested logs also include the version number
record['function_version'] = ENV_FUNCTION_VERSION
logs.extend(log_entry['records']) # Add nested logs individually
else:
logs.append(log_entry)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ As an alternative to the Azure Template, you can use Terraform to set up your lo
---
## Changelog

- 0.0.2:
* Added `ENV_FUNCTION_VERSION` parameter for dynamic versioning in ARM template and Terraform.

- 0.0.1:
* Initial release with Python Azure Function.
* Implement log shipping to Logz.io.
Expand Down
11 changes: 11 additions & 0 deletions deployments/azuredeploylogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"contentVersion": "v0.0.1",
"parameters":
{
"FunctionAppVersion": {
"type": "string",
"defaultValue": "1.0.0",
"metadata": {
"description": "The version of the function app being deployed."
}
},
"FailedLogBackupContainer":
{
"defaultValue": "failedlogbackup",
Expand Down Expand Up @@ -226,6 +233,10 @@
"linuxFxVersion": "PYTHON|3.11",
"appSettings":
[
{
"name": "FUNCTION_VERSION",
"value": "[parameters('FunctionAppVersion')]"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "python"
Expand Down
1 change: 1 addition & 0 deletions deployments/azuredeploylogs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ resource "azurerm_linux_function_app" "function_app" {
}

app_settings = {
"FUNCTION_VERSION" = var.function_app_version
"FUNCTIONS_WORKER_RUNTIME" = "python"
"FUNCTIONS_EXTENSION_VERSION" = "~4"
"AzureWebJobsEventHubConnectionString" = local.eventhub_connection_string
Expand Down
5 changes: 5 additions & 0 deletions deployments/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "function_app_version" {
description = "The version of the function app being deployed."
default = "1.0.0"
}

variable "failed_log_backup_container" {
description = "The name of the blob container within the storage account."
default = "failedlogbackup"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Manually managing azure-functions-worker may cause unexpected issues

# Azure Functions framework
azure-functions==1.17.0
azure-functions==1.18.0

applicationinsights

# Azure Blob Storage SDK for backup container functionality
azure-storage-blob==12.19.0

# Utilities and helpers
python-dotenv==1.0.0
python-dotenv==1.0.1
backoff==2.2.1

0 comments on commit 40d804f

Please sign in to comment.