Patricio Navarro
07/17/2025, 1:46 PMflow_run_problem_notification = {
"type": "send-notification",
"block_document_id": slack_webhook_block._block_document_id,
"subject": ':rotating_light: Prefect Run Problem on PROD',
"body": 'Flow run {{ flow.name }}/{{ flow_run.name }} observed in ' +
'state `{{ flow_run.state.name }}` at ' +
'{{ flow_run.state.timestamp }}.\n' +
'Flow ID: {{ flow_run.flow_id }}\n' +
'Flow run ID: {{ flow_run.id }}\n' +
'Flow run URL: {{ flow_run|ui_url }}\n' +
'Flow run Params: {{ flow_run.parameters }}\n' +
'State message: {{ flow_run.state.message }}'
}
While this works fine in the Cloud, it fails to resolve the Flow run URL, on the self hosted. How can I fix this?Marvin
07/17/2025, 1:46 PMMarvin
07/17/2025, 1:47 PMPREFECT_UI_URL
environment variable in your self-hosted environment. This tells Prefect where your UI is hosted. For example:
bash
export PREFECT_UI_URL="<https://your-prefect-instance.company.com>"
2. Alternative: Manual URL Construction:
If setting the environment variable isn't feasible, you can manually construct the URL in your notification template:
python
flow_run_problem_notification = {
"type": "send-notification",
"block_document_id": slack_webhook_block._block_document_id,
"subject": ':rotating_light: Prefect Run Problem on PROD',
"body": 'Flow run {{ flow.name }}/{{ flow_run.name }} observed in ' +
'state `{{ flow_run.state.name }}` at ' +
'{{ flow_run.state.timestamp }}.\n' +
'Flow ID: {{ flow_run.flow_id }}\n' +
'Flow run ID: {{ flow_run.id }}\n' +
'Flow run URL: <https://your-prefect-instance.company.com/flow-runs/>{{ flow_run.id }}\n' +
'Flow run Params: {{ flow_run.parameters }}\n' +
'State message: {{ flow_run.state.message }}'
}
The first approach (setting PREFECT_UI_URL
) is recommended because:
1. It's more maintainable - you don't have to hardcode URLs in your code
2. It ensures consistency across all notifications and UI links
3. It works with the existing template variable {{ flow_run|ui_url }}
Would you like me to provide more details about setting up the environment variable in your specific deployment environment?Patricio Navarro
07/17/2025, 2:08 PMMarvin
07/17/2025, 2:08 PMMarvin
07/17/2025, 2:09 PM<https://prefect.your-company.com>
- This is what users will see in their browser when accessing the Prefect UI
2. PREFECT_UI_API_URL
- This is the URL that the Prefect UI uses to communicate with the Prefect API
- Used by the UI frontend to make API calls to the backend
- Particularly important when using reverse proxies or when the API is hosted at a different location than the UI
- Example: <https://prefect-api.your-company.com/api>
For your specific case with the notification URLs, PREFECT_UI_URL
is the variable you want to set, as it determines how the {{ flow_run|ui_url }}
template variable gets rendered.
A typical setup might look like this:
bash
# The URL where users access the UI
export PREFECT_UI_URL="<https://prefect.your-company.com>"
# The URL where the UI connects to the API (if different)
export PREFECT_UI_API_URL="<https://prefect-api.your-company.com/api>"
You can find the official documentation for these settings in the Prefect Settings Reference. However, I notice that the documentation could be more detailed about these specific variables. I would recommend also checking the Security Settings page for additional context about configuring URLs in a self-hosted environment.
Would you like me to provide more specific examples of how to set these up in different deployment environments (Docker, Kubernetes, etc.)?Patricio Navarro
07/17/2025, 2:26 PMMarvin
07/17/2025, 2:26 PMMarvin
07/17/2025, 2:27 PMPREFECT_UI_URL
environment variable in your Helm deployment:
1. Using values.yaml (Recommended):
Modify your values.yaml
file to include the environment variable:
yaml
server:
env:
- name: PREFECT_UI_URL
value: "<https://your-prefect-instance.company.com>"
ui:
env:
- name: PREFECT_UI_URL
value: "<https://your-prefect-instance.company.com>"
2. Using Helm CLI:
If you prefer not to modify the values file, you can set it during the helm install/upgrade:
bash
helm upgrade --install prefect prefect/prefect \
--set server.env[0].name=PREFECT_UI_URL \
--set server.env[0].value=<https://your-prefect-instance.company.com> \
--set ui.env[0].name=PREFECT_UI_URL \
--set ui.env[0].value=<https://your-prefect-instance.company.com>
Important notes:
1. Make sure to set this for both the server
and ui
components
2. The URL should be the externally accessible URL of your Prefect UI
3. If you're using an ingress controller, this should match your ingress host configuration
4. Don't forget the protocol (https:// or http://)
Here's a more complete example of a values.yaml
configuration that includes both the UI URL and ingress settings:
yaml
server:
env:
- name: PREFECT_UI_URL
value: "<https://your-prefect-instance.company.com>"
ui:
env:
- name: PREFECT_UI_URL
value: "<https://your-prefect-instance.company.com>"
ingress:
enabled: true
hosts:
- host: <http://your-prefect-instance.company.com|your-prefect-instance.company.com>
paths:
- path: /
pathType: Prefix
tls:
- secretName: your-tls-secret
hosts:
- <http://your-prefect-instance.company.com|your-prefect-instance.company.com>
After making these changes, you'll need to upgrade your Helm deployment:
bash
helm upgrade prefect prefect/prefect -f values.yaml
Would you like me to provide more specific details about any part of this configuration, such as ingress setup or TLS configuration?