Hey all - I am registering my flows with the follo...
# prefect-server
j
Hey all - I am registering my flows with the following (to a server deployment on k8s);
Copy code
def register_deploy():
    # pylint: disable=missing-function-docstring
    with prefect.context(
        config={
            "cloud": {"graphql": os.environ["GRPAHQL_ENDPOINT"]},
            "server": {"ui": {"endpoint": os.environ["UI_ENDPOINT"]}},
        }
    ):

        for flow_name, flow in all_flows.items():
            <http://logging.info|logging.info>(f"Registering flow: {flow_name}")
            flow.register(project_name=PROD_PROJECT, labels=[SHARED_LABEL])
This works (in terms of registering) but the stdout is the following;
Copy code
Result check: OK
Flow URL: <http://localhost:8080/default/flow/a6013647-a31e-4d3c-9e7e-82e69c02f71e>
 └── ID: d78a0fc5-3990-461d-91d7-593a4278b6b2
 └── Project: prod
 └── Labels: ['prefect-agent']
I thought setting
config.server.ui.endpoint
would lead to that endpoint being printed but it seems to not (
localhost:8080
as opposed to
UI_ENDPOINT
) - any ideas?
m
Hello Josh! I remember this issue and seems like setting server ui endpoint should work. If you'll have a chance, can you test setting env var
PREFECT__SERVER__UI__ENDPOINT
?
j
Isn't that what I am doing via the context?
m
Sorry for late response. Can you share the output from
prefect diagnostics
?
j
No worries - of course!
Copy code
{
  "config_overrides": {},
  "env_vars": [],
  "system_information": {
    "platform": "macOS-10.15.7-x86_64-i386-64bit",
    "prefect_backend": "server",
    "prefect_version": "0.14.11",
    "python_version": "3.8.7"
  }
}
It does work if I set the env var - but I need to switch between endpoints in the same script thus the use of contexts
It feels like the context manager is not being applied down in the stack of function calls
m
Yeah, I'm trying to figure out if there is a way to use endpoint from the context. I'll be back shortly.
j
The code (https://github.com/PrefectHQ/prefect/blob/8c662ce5524aca9cb635e44784081a1701cfb5c3/src/prefect/client/client.py#L881) that deals with it accesses
prefect.config.server.ui.endpoint
to get the base url - so it should work cos that is set as expected just after the context manager
but perhaps in that function it has somehow reverted to the default value
I don't have a setup for changing the prefect code - otherwise I would just start adding some logging to see how it changes...
m
Josh, I’m back with some updates. Context will not update config values (so if config.toml is not updated, server ui endpoint will be set to default http://localhost:8080). But we have a utility, which is used mostly for testing, but it can temporary alter the configuration values within your script. You can try to do following:
Copy code
from prefect.utilities.configuration import set_temporary_config

def register_deploy():
    with set_temporary_config({"server": {"ui": {"endpoint": "<>"}}}):