def test_update_autoscaling(self, client, created_entities, experiment_run, model_for_deployment): experiment_run.log_model(model_for_deployment['model'], custom_modules=[]) experiment_run.log_environment(Python(['scikit-learn'])) path = verta._internal_utils._utils.generate_default_name() endpoint = client.set_endpoint(path) created_entities.append(endpoint) autoscaling = Autoscaling(min_replicas=1, max_replicas=2, min_scale=0.5, max_scale=2.0) autoscaling.add_metric(CpuUtilizationTarget(0.5)) autoscaling.add_metric(MemoryUtilizationTarget(0.7)) autoscaling.add_metric(RequestsPerWorkerTarget(100)) endpoint.update(experiment_run, DirectUpdateStrategy(), autoscaling=autoscaling) update_status = endpoint.get_update_status() autoscaling_metrics = update_status["update_request"]["autoscaling"]["metrics"] assert len(autoscaling_metrics) == 3 for metric in autoscaling_metrics: assert metric["metric_id"] in [1001, 1002, 1003] if metric["metric_id"] == 1001: assert metric["parameters"][0]["value"] == "0.5" elif metric["metric_id"] == 1002: assert metric["parameters"][0]["value"] == "100" else: assert metric["parameters"][0]["value"] == "0.7"
def test_download_manifest(self, client, in_tempdir): download_to_path = "manifest.yaml" path = verta._internal_utils._utils.generate_default_name() name = verta._internal_utils._utils.generate_default_name() strategy = CanaryUpdateStrategy(interval=10, step=0.1) strategy.add_rule(MaximumAverageLatencyThresholdRule(0.1)) resources = Resources(cpu=.1, memory="128Mi") autoscaling = Autoscaling(min_replicas=1, max_replicas=10, min_scale=0.1, max_scale=2) autoscaling.add_metric(CpuUtilizationTarget(0.75)) env_vars = {'env1': "var1", 'env2': "var2"} filepath = client.download_endpoint_manifest( download_to_path=download_to_path, path=path, name=name, strategy=strategy, autoscaling=autoscaling, resources=resources, env_vars=env_vars, ) # can be loaded as YAML with open(filepath, 'rb') as f: manifest = yaml.safe_load(f) assert manifest['kind'] == "Endpoint" # check environment variables containers = manifest['spec']['function']['spec']['templates'][ 'deployment']['spec']['template']['spec']['containers'] retrieved_env_vars = { env_var['name']: env_var['value'] for env_var in containers[0]['env'] } assert retrieved_env_vars == env_vars