Skip to content

Commit 7c0147a

Browse files
committed
Update prepdocs with ping and update docs
1 parent 4b3cd8c commit 7c0147a

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

app/backend/prepdocs.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from typing import Optional, Union
66

7+
import aiohttp
78
from azure.core.credentials import AzureKeyCredential
89
from azure.core.credentials_async import AsyncTokenCredential
910
from azure.identity.aio import AzureDeveloperCliCredential, get_bearer_token_provider
@@ -45,6 +46,19 @@ def clean_key_if_exists(key: Union[str, None]) -> Union[str, None]:
4546
return None
4647

4748

49+
async def check_search_service_connectivity(search_service: str) -> bool:
50+
"""Check if the search service is accessible by hitting the /ping endpoint."""
51+
ping_url = f"https://{search_service}.search.windows.net/ping"
52+
53+
try:
54+
async with aiohttp.ClientSession() as session:
55+
async with session.get(ping_url, timeout=aiohttp.ClientTimeout(total=10)) as response:
56+
return response.status == 200
57+
except Exception as e:
58+
logger.debug(f"Search service ping failed: {e}")
59+
return False
60+
61+
4862
async def setup_search_info(
4963
search_service: str,
5064
index_name: str,
@@ -372,6 +386,23 @@ async def main(strategy: Strategy, setup_index: bool = True):
372386
search_key=clean_key_if_exists(args.searchkey),
373387
)
374388
)
389+
390+
# Check search service connectivity
391+
search_service = os.environ["AZURE_SEARCH_SERVICE"]
392+
is_connected = loop.run_until_complete(check_search_service_connectivity(search_service))
393+
394+
if not is_connected:
395+
if os.getenv("AZURE_USE_PRIVATE_ENDPOINT"):
396+
logger.error(
397+
"Unable to connect to Azure AI Search service, which indicates either a network issue or a misconfiguration. You have AZURE_USE_PRIVATE_ENDPOINT enabled. Perhaps you're not yet connected to the VPN? Download the VPN configuration from the Azure portal here: %s",
398+
os.getenv("AZURE_VPN_CONFIG_DOWNLOAD_LINK"),
399+
)
400+
else:
401+
logger.error(
402+
"Unable to connect to Azure AI Search service, which indicates either a network issue or a misconfiguration."
403+
)
404+
exit(1)
405+
375406
blob_manager = setup_blob_manager(
376407
azure_credential=azd_credential,
377408
storage_account=os.environ["AZURE_STORAGE_ACCOUNT"],

docs/deploy_private.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Deploying with public access disabled adds additional cost to your deployment. P
4646

4747
## Recommended deployment strategy for private access
4848

49-
1. Deploy the app with private endpoints enabled, public network access disabled, and a VPN gateway configured. This will allow you to connect to the chat app from inside the virtual network.
49+
1. Configure the azd environment variables to use private endpoints and a VPN gateway, with public network access disabled. This will allow you to connect to the chat app from inside the virtual network, but not from the public Internet.
5050

5151
```shell
5252
azd env set AZURE_USE_PRIVATE_ENDPOINT true
@@ -55,19 +55,19 @@ Deploying with public access disabled adds additional cost to your deployment. P
5555
azd up
5656
```
5757

58-
2. First provision all the resources:
58+
2. Provision all the Azure resources:
5959

6060
```bash
6161
azd provision
6262
```
6363

64-
3. Once provisioning is complete, run this command to get the VPN configuration download link:
64+
3. Once provisioning is complete, you will see an error when it tries to run the data ingestion script, because you are not yet connected to the VPN. That message should provide a URL for the VPN configuration file download. If you don't see that URL, run this command:
6565
6666
```bash
6767
azd env get-value AZURE_VPN_CONFIG_DOWNLOAD_LINK
6868
```
6969
70-
Select "Download VPN client" to download a ZIP file containing the VPN configuration.
70+
Open that link in your browser. Select "Download VPN client" to download a ZIP file containing the VPN configuration.
7171
7272
4. Open `AzureVPN/azurevpnconfig.xml`, and replace the `<clientconfig>` empty tag with the following:
7373
@@ -79,17 +79,19 @@ Deploying with public access disabled adds additional cost to your deployment. P
7979
</clientconfig>
8080
```
8181
82-
5. Open the "Azure VPN" client and select "Import" button. Select the `azurevpnconfig.xml` file you just downloaded and modified.
82+
5. Install the [Azure VPN Client](https://learn.microsoft.com/azure/vpn-gateway/vpn-gateway-howto-vpn-client-install).
8383
84-
6. Select "Connect" and the new VPN connection. You will be prompted to select your Microsoft account and login.
84+
6. Open the "Azure VPN" client and select "Import" button. Select the `azurevpnconfig.xml` file you just downloaded and modified.
8585
86-
7. Once you're successfully connected to VPN, you can run the data ingestion script:
86+
7. Select "Connect" and the new VPN connection. You will be prompted to select your Microsoft account and login.
87+
88+
8. Once you're successfully connected to VPN, you can run the data ingestion script:
8789

8890
```bash
8991
azd hooks run postprovision
9092
```
9193

92-
8. Finally, you can deploy the app:
94+
9. Finally, you can deploy the app:
9395

9496
```bash
9597
azd deploy

todo.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
* Better error when youre trying to run prepdocs and not connected to VPN.
2-
* Hit up /ping and check that it returns 200 OK. Anything else = no bueno.
3-
* If they have AZURE_USE_PRIVATE_ENDPOINT and it gets non-200, reminds them to set up VPN.
1+
42
* Manually test App Service

0 commit comments

Comments
 (0)