From 4f0785576a55f01a9d895b08c87bb3fc90775771 Mon Sep 17 00:00:00 2001 From: Marek Majcher Date: Tue, 24 Jan 2023 16:25:03 +0100 Subject: [PATCH 1/3] PCLOUDS-1689: Make storage account name unique --- deployment/dynatrace-azure-forwarder.json | 4 +++- deployment/dynatrace-azure-logs.sh | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deployment/dynatrace-azure-forwarder.json b/deployment/dynatrace-azure-forwarder.json index 9a65dd4..c34216a 100644 --- a/deployment/dynatrace-azure-forwarder.json +++ b/deployment/dynatrace-azure-forwarder.json @@ -89,7 +89,9 @@ "containerSubnetName": "aci", "appServicePlan": "[concat(parameters('forwarderName'),'-plan')]", "functionName": "[concat(parameters('forwarderName'),'-function')]", - "storageAccountName": "[replace(concat(parameters('forwarderName'),'sa'), '-', '')]", + "forwarderNameShort": "[substring(parameters('forwarderName'), 0, 18)]", + "randomIdToMakeStorageAccountGloballyUnique": "[substring(uniqueString(parameters('forwarderName'), resourceGroup().id), 0, 4)]", + "storageAccountName": "[concat(variables('forwarderNameShort'), variables('randomIdToMakeStorageAccountGloballyUnique'),'sa')]", "virtualNetworkId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", "functionSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('functionSubnetName'))]", "containerSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('containerSubnetName'))]", diff --git a/deployment/dynatrace-azure-logs.sh b/deployment/dynatrace-azure-logs.sh index 7cc5baf..9d42571 100755 --- a/deployment/dynatrace-azure-logs.sh +++ b/deployment/dynatrace-azure-logs.sh @@ -19,7 +19,7 @@ readonly FUNCTION_ZIP_PACKAGE=dynatrace-azure-log-forwarder.zip readonly FUNCTION_REPOSITORY_RELEASE_URL=https://github.com/dynatrace-oss/dynatrace-azure-log-forwarder/releases/latest/download/ readonly DYNATRACE_TARGET_URL_REGEX="^(https?:\/\/[-a-zA-Z0-9@:%._+~=]{1,255}\/?)(\/e\/[a-z0-9-]{36}\/?)?$" readonly ACTIVE_GATE_TARGET_URL_REGEX="^https:\/\/[-a-zA-Z0-9@:%._+~=]{1,255}\/e\/[-a-z0-9]{1,36}[\/]{0,1}$" -readonly DEPLOYMENT_NAME_REGEX="^[-a-z0-9]{3,20}$" +readonly DEPLOYMENT_NAME_REGEX="^[a-z0-9]{3,20}$" readonly EVENT_HUB_CONNECTION_STRING_REGEX="^Endpoint=sb:\/\/.*EntityPath=[^[:space:]]+$" readonly FILTER_CONFIG_REGEX="([^;\s].+?)=([^;]*)" readonly TAGS_REGEX="^([^<>,%&\?\/]+?:[^,]+,?)+$" @@ -94,7 +94,7 @@ check_arg() { exit 1 else if ! [[ "$ARGUMENT" =~ $REGEX ]]; then - echo "Not correct $CLI_ARGUMENT_NAME" + echo "Not correct $CLI_ARGUMENT_NAME, pattern is: $REGEX" exit 1 fi fi From 2750dd7a10692e3793f13bc1ab647aeec387e155 Mon Sep 17 00:00:00 2001 From: Marek Majcher Date: Tue, 24 Jan 2023 17:32:36 +0100 Subject: [PATCH 2/3] PCLOUDS-1689: Make storage account name unique - fix build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3d6bce4..dcd1522 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,7 +74,7 @@ jobs: - az group create --name "$RESOURCE_GROUP_NAME" --location westeurope - az resource invoke-action --action enable --name "$LOGIC_APP_NAME" -g "$RESOURCE_GROUP_STATIC_RESOURCES" --resource-type "$LOGIC_APP_RESOURCE_TYPE" script: - - ./deployment/dynatrace-azure-logs.sh --deployment-name "e2e-${TRAVIS_BUILD_ID}" --resource-group "$RESOURCE_GROUP_NAME" --target-url "$TARGET_URL" --target-api-token "$TARGET_API_TOKEN" --use-existing-active-gate true --event-hub-connection-string "$EH_CONNECTION_STRING" --repository-release-url "https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net/${STORAGE_ACCOUNT_DIR_NAME}/" + - ./deployment/dynatrace-azure-logs.sh --deployment-name "e2e${TRAVIS_BUILD_ID}" --resource-group "$RESOURCE_GROUP_NAME" --target-url "$TARGET_URL" --target-api-token "$TARGET_API_TOKEN" --use-existing-active-gate true --event-hub-connection-string "$EH_CONNECTION_STRING" --repository-release-url "https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net/${STORAGE_ACCOUNT_DIR_NAME}/" - pytest tests/e2e -v after_script: - az group delete --name "$RESOURCE_GROUP_NAME" --yes From a1598ea150f4ad0e65c7253f2c5b880b7df72491 Mon Sep 17 00:00:00 2001 From: Marek Majcher Date: Wed, 25 Jan 2023 11:21:00 +0100 Subject: [PATCH 3/3] PCLOUDS-1689: Make storage account name unique - replace substring with take (safe when arg too short) --- deployment/dynatrace-azure-forwarder.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/dynatrace-azure-forwarder.json b/deployment/dynatrace-azure-forwarder.json index c34216a..eae4e0d 100644 --- a/deployment/dynatrace-azure-forwarder.json +++ b/deployment/dynatrace-azure-forwarder.json @@ -89,9 +89,9 @@ "containerSubnetName": "aci", "appServicePlan": "[concat(parameters('forwarderName'),'-plan')]", "functionName": "[concat(parameters('forwarderName'),'-function')]", - "forwarderNameShort": "[substring(parameters('forwarderName'), 0, 18)]", + "forwarderNameShort": "[take(parameters('forwarderName'), 18)]", "randomIdToMakeStorageAccountGloballyUnique": "[substring(uniqueString(parameters('forwarderName'), resourceGroup().id), 0, 4)]", - "storageAccountName": "[concat(variables('forwarderNameShort'), variables('randomIdToMakeStorageAccountGloballyUnique'),'sa')]", + "storageAccountName": "[concat(variables('forwarderNameShort'), 'sa', variables('randomIdToMakeStorageAccountGloballyUnique'))]", "virtualNetworkId": "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]", "functionSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('functionSubnetName'))]", "containerSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('containerSubnetName'))]",