Skip to content

Commit 563451a

Browse files
committed
Update deployment and fix azurecli issue
1 parent 56d8c77 commit 563451a

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

AzureFunctions/km-charts-function/function_app.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
import azure.functions as func
23
import logging
34
import json
@@ -25,6 +26,33 @@ def get_metrics(req: func.HttpRequest) -> func.HttpResponse:
2526

2627
conn = pymssql.connect(server, username, password, database)
2728
cursor = conn.cursor()
29+
30+
# Adjust the dates to the current date
31+
today = datetime.today()
32+
cursor.execute("SELECT MAX(CAST(StartTime AS DATETIME)) FROM [dbo].[processed_data]")
33+
max_start_time = cursor.fetchone()[0]
34+
35+
if max_start_time:
36+
days_difference = (today - max_start_time).days - 1
37+
if days_difference != 0:
38+
# Update processed_data table
39+
cursor.execute(
40+
"UPDATE [dbo].[processed_data] SET StartTime = FORMAT(DATEADD(DAY, %s, StartTime), 'yyyy-MM-dd HH:mm:ss'), EndTime = FORMAT(DATEADD(DAY, %s, EndTime), 'yyyy-MM-dd HH:mm:ss')",
41+
(days_difference, days_difference)
42+
)
43+
# Update km_processed_data table
44+
cursor.execute(
45+
"UPDATE [dbo].[km_processed_data] SET StartTime = FORMAT(DATEADD(DAY, %s, StartTime), 'yyyy-MM-dd HH:mm:ss'), EndTime = FORMAT(DATEADD(DAY, %s, EndTime), 'yyyy-MM-dd HH:mm:ss')",
46+
(days_difference, days_difference)
47+
)
48+
# Update processed_data_key_phrases table
49+
cursor.execute(
50+
"UPDATE [dbo].[processed_data_key_phrases] SET StartTime = FORMAT(DATEADD(DAY, %s, StartTime), 'yyyy-MM-dd HH:mm:ss')",
51+
(days_difference,)
52+
)
53+
# Commit the changes
54+
conn.commit()
55+
2856
if data_type == 'filters':
2957

3058
sql_stmt = '''select 'Topic' as filter_name, mined_topic as displayValue, mined_topic as key1 from

Deployment/bicep/deploy_upload_files_script.bicep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ param solutionLocation string
33
param keyVaultName string
44
param baseUrl string
55
param managedIdentityObjectId string
6-
@secure()
7-
param storageAccountKey string
86
param storageAccountName string
97
param containerName string
108
// param identity string
@@ -40,7 +38,7 @@ resource copy_demo_Data 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
4038
properties: {
4139
azCliVersion: '2.50.0'
4240
primaryScriptUri: '${baseUrl}Deployment/scripts/copy_kb_files.sh' // deploy-azure-synapse-pipelines.sh
43-
arguments: '${storageAccountName} ${containerName} ${storageAccountKey} ${baseUrl}' // Specify any arguments for the script
41+
arguments: '${storageAccountName} ${containerName} ${baseUrl}' // Specify any arguments for the script
4442
timeout: 'PT1H' // Specify the desired timeout duration
4543
retentionInterval: 'PT1H' // Specify the desired retention interval
4644
cleanupPreference:'OnSuccess'

Deployment/bicep/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ param otherLocation string
1313
// param fabricWorkspaceId string
1414

1515
var resourceGroupLocation = resourceGroup().location
16+
var resourceGroupName = resourceGroup().name
1617

1718
var solutionLocation = resourceGroupLocation
1819
var baseUrl = 'https://raw.githubusercontent.com/microsoft/Customer-Service-Conversational-Insights-with-Azure-OpenAI-Services/km-v3-staging/'
@@ -84,7 +85,6 @@ module uploadFiles 'deploy_upload_files_script.bicep' = {
8485
baseUrl: baseUrl
8586
storageAccountName: storageAccount.outputs.storageName
8687
containerName: storageAccount.outputs.storageContainer
87-
storageAccountKey:keyVault.getSecret('ADLS-ACCOUNT-KEY')
8888
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.id
8989
}
9090
dependsOn:[storageAccount,keyVault]

Deployment/bicep/main.json

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.32.4.45862",
8-
"templateHash": "7717305353028371958"
8+
"templateHash": "2383153489316953097"
99
}
1010
},
1111
"parameters": {
@@ -26,6 +26,7 @@
2626
},
2727
"variables": {
2828
"resourceGroupLocation": "[resourceGroup().location]",
29+
"resourceGroupName": "[resourceGroup().name]",
2930
"solutionLocation": "[variables('resourceGroupLocation')]",
3031
"baseUrl": "https://raw.githubusercontent.com/microsoft/Customer-Service-Conversational-Insights-with-Azure-OpenAI-Services/km-v3-staging/"
3132
},
@@ -1434,14 +1435,6 @@
14341435
"containerName": {
14351436
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageContainer.value]"
14361437
},
1437-
"storageAccountKey": {
1438-
"reference": {
1439-
"keyVault": {
1440-
"id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.KeyVault/vaults', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value)]"
1441-
},
1442-
"secretName": "ADLS-ACCOUNT-KEY"
1443-
}
1444-
},
14451438
"managedIdentityObjectId": {
14461439
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.id]"
14471440
}
@@ -1453,7 +1446,7 @@
14531446
"_generator": {
14541447
"name": "bicep",
14551448
"version": "0.32.4.45862",
1456-
"templateHash": "2240564084997274937"
1449+
"templateHash": "16162981464101235300"
14571450
}
14581451
},
14591452
"parameters": {
@@ -1472,9 +1465,6 @@
14721465
"managedIdentityObjectId": {
14731466
"type": "string"
14741467
},
1475-
"storageAccountKey": {
1476-
"type": "securestring"
1477-
},
14781468
"storageAccountName": {
14791469
"type": "string"
14801470
},
@@ -1498,7 +1488,7 @@
14981488
"properties": {
14991489
"azCliVersion": "2.50.0",
15001490
"primaryScriptUri": "[format('{0}Deployment/scripts/copy_kb_files.sh', parameters('baseUrl'))]",
1501-
"arguments": "[format('{0} {1} {2} {3}', parameters('storageAccountName'), parameters('containerName'), parameters('storageAccountKey'), parameters('baseUrl'))]",
1491+
"arguments": "[format('{0} {1} {2}', parameters('storageAccountName'), parameters('containerName'), parameters('baseUrl'))]",
15021492
"timeout": "PT1H",
15031493
"retentionInterval": "PT1H",
15041494
"cleanupPreference": "OnSuccess"

Deployment/scripts/copy_kb_files.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Variables
44
storageAccount="$1"
55
fileSystem="$2"
6-
accountKey="$3"
7-
baseUrl="$4"
6+
baseUrl="$3"
87
# azureOpenAIApiKey="$4"
98
# azureOpenAIEndpoint="$5"
109
# azureSearchAdminKey="$6"
@@ -85,7 +84,12 @@ echo "Script Started"
8584
# az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder1" --source /mnt/azscripts/azscriptinput/"$extractedFolder1" --auth-mode login --pattern '*'
8685
# az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder2" --source /mnt/azscripts/azscriptinput/"$extractedFolder2" --auth-mode login --pattern '*'
8786

88-
az storage fs directory upload -f "$fileSystem" --account-name "$storageAccount" -s "$extractedFolder1" --account-key "$accountKey" --recursive
87+
# Authenticate with Azure using managed identity
88+
az login --identity
89+
# Using az storage blob upload-batch to upload files with managed identity authentication, as the az storage fs directory upload command is not working with managed identity authentication.
90+
az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder1" --source /mnt/azscripts/azscriptinput/"$extractedFolder1" --auth-mode login --pattern '*'
91+
92+
#az storage fs directory upload -f "$fileSystem" --account-name "$storageAccount" -s "$extractedFolder1" --account-key "$accountKey" --recursive
8993

9094
# az storage blob upload-batch --account-name "$storageAccount" --destination "data/audiofiles" --source /mnt/azscripts/azscriptinput/"$extractedFolder2" --account-key "$accountKey" --pattern '*'
9195
# az storage blob upload-batch --account-name "$storageAccount" --destination "data/audiofiles" --source /mnt/azscripts/azscriptinput/"$extractedFolder3" --account-key "$accountKey" --pattern '*'
@@ -105,4 +109,4 @@ az storage fs directory upload -f "$fileSystem" --account-name "$storageAccount"
105109
# # pip install graphrag==0.3.6
106110

107111
# # python -m graphrag.index --root /mnt/azscripts/azscriptinput/ragtest
108-
# # python -m graphrag index --root ./ragtest
112+
# # python -m graphrag index --root ./ragtest

0 commit comments

Comments
 (0)