Vilette Braun
02/20/2024, 4:32 PMclass AssetConfig(Config):
mlflow_endpoint: str
@asset
def my_model_asset(config: AssetConfig) -> None:
# Use config.mlflow_endpoint in some way, e.g. to track an ML experiment
And I'd have a very simple configuration
# config.prod.yaml
ops:
model:
config:
mlflow_endpoint: "http://..."
How would I supply this configuration to a production deployment of Dagster, while at the same time have a different configuration (e.g. config.dev.yaml
) for a local defelopment environment (dagster dev), and maybe yet another configuration for a CI/CD pipeline?
To me, none of the 3 options in https://docs.dagster.io/concepts/configuration/config-schema#specifying-runtime-configuration seem to apply to this situation, while I assume that the use case I've described is a common scenario?
I might be completely thinking in the wrong direction, thank you for any best practices you could share for how to properly do this.
All the bestZach
02/20/2024, 6:13 PMdeployment = os.getenv("DEPLOYMENT")
if deployment == "dev":
with open("config.dev.yaml", "r") as conf_in
config = conf_in.read()
elif deployment == "prod":
with open("config.prod.yaml", "r") as conf_in
config = conf_in.read()
job = define_asset_job(AssetSelection.assets(my_model_asset), config=config)
If you're using Dagster Cloud, they inject env vars that indicate the deployment the code is executing on which you could also use for deciding how to load deployment-specific configurationsVilette Braun
02/20/2024, 7:48 PMjob
into the picture, is there a specific necessity for this in this scenario, or would my original example make sense combined with your suggestion as well? I.e. something like this:
class AssetConfig(Config):
mlflow_endpoint: str
deployment = os.getenv("DEPLOYMENT")
if deployment == "dev":
with open("config.dev.yaml", "r") as conf_in:
config = conf_in.read()
elif deployment == "prod":
with open("config.prod.yaml", "r") as conf_in:
config = conf_in.read()
@asset
def my_model_asset(config: AssetConfig = config) -> None:
# Use config.mlflow_endpoint
All the bestZach
02/20/2024, 8:11 PM@asset
definition doesn't seem to provide, like binding static config to the asset. If you don't want to make it into a job then I'm not really sure how to bind static configuration to the asset. You might be able to do it like you suggest, but Dagster might complain that it's missing config as I don't know if it's able to resolve defaults for config parameters. If you don't plan on changing the config in the launchpad you could just do
class AssetConfig(Config):
mlflow_endpoint: str
deployment = os.getenv("DEPLOYMENT")
if deployment == "dev":
with open("config.dev.yaml", "r") as conf_in:
config = conf_in.read()
elif deployment == "prod":
with open("config.prod.yaml", "r") as conf_in:
config = conf_in.read()
asset_config = AssetConfig(**config)
@asset
def my_model_asset() -> None:
mlflow_endpoint = asset_config.mlflow_endpoint
Alexis Manin
02/21/2024, 7:15 AMclass MyWebServiceAccess(ConfigurableResource):
url: str = Field(description="access url to ...")
@asset
def my_asset(my_web_service: MyWebServiceAccess):
request(my_web_service.url)
definitions = Definitions(
assets = [my_asset],
resources = {
"my_web_service": MyWebServiceAccess(url=EnvVar(MY_WEB_SERVICE_URL))
}
)
Vilette Braun
02/21/2024, 8:44 AMZach
02/21/2024, 4:37 PM