Skip to content

Support new variable: deployment price #103

@martaroz

Description

@martaroz

When a variable of type price is present in the generic.dsl message,see the example:

      "key": "application_deployment_price",
      "path": "",
      "type": "float",
      "meaning": "price",
      "value": {
        "lower_bound": 0,
        "higher_bound": 0
      } 

The Optimizer Controller should use the message from Utility Evaluator (example message:

    "type": "performanceIndicator",
    "performanceIndicators": [
        {
            "name": "cost_pi_component1",
            "variables": ["cpu1", "ram1"],
            "coefficientsName": "COEFFICIENTS_component1"
        },
        {
            "name": "cost_pi_component2",
            "variables": ["cpu2"],
            "coefficientsName": "COEFFICIENTS_component2"
        }
    ],
    "initialDataFile": "param: COEFFICIENTS_component1 := 1 0.1 2 0.3; param: COEFFICIENTS_component2 := 1 0.1;"
} ) 

and create a new performance indicator in AMPL:

var application_deployment_price = replicas_component1 * cost_pi_component1+ replicas_component2 * cost_pi_component2;

where replicas_component1 is a variable of type REPLICAS for component1, and replicas_component2 is a variable of type REPLICAS for component 2.
If there is no variable for number of replicas, Optimizer Controller should skip this cost performance indicator in the formula. Also,

Then, Optimiser Controller should use application_deployment_price in constraints or utility function in the way it is specified by the user (like a standard variable).

Example generic.dsl message:

{
  "title": "Ubiwhere Test",
  "uuid": "0f2b4837-b67d-427b-8eae-c734c21b7531",
  "status": "draft",
  "content": "apiVersion: core.oam.dev/v1beta1\nkind: Application\nmetadata:\n  name: nebulous-infrastructure\nspec:\n  publish-version: 1\n  components:\n    - name: nebulous-master\n      type: webservice\n      properties:\n        image: harbor.ubiwhere.com/nebulous/cv_image:nebulous\n        imagePullPolicy: \"Always\"\n        imagePullSecrets: [\"regcred\"]\n        cpu: \"4.0\"\n        memory: \"8Gi\"\n        cmd:\n          - \"python3\"\n          - \"/usr/src/app/algorithm/trackv7.py\"\n          - \"/usr/src/app/prometheus/prometheus_metrics.py\"\n        volumes:\n          - mountPath: /usr/src/app/runs\n            name: output-volume\n          - mountPath: /usr/src/app/algorithm/weights\n            name: weights-volume\n          - mountPath: /usr/src/app/videos\n            name: videos-volume\n          - mountPath: /usr/src/app/prometheus\n            name: prometheus-volume\n        env:\n          - name: \"CLASSES\"\n            value: \"0, 1, 2, 3, 5, 7\"         \n          - name: \"SAVE\"\n            value: \"True\"\n        gpu:\n          resourceType: \"nvidia.com/gpu\"\n          resourceLimit: 50\n        ports:\n          - port: 6379\n            protocol: TCP\n        traits:\n        - type: scaler\n          properties:\n            replicas: 3\n        dependsOn:\n          - redis\n\n    - name: redis\n      type: webservice\n      properties:\n        image: \"redis:6.2.6-alpine\"\n        cpu: \"4.0\"\n        memory: \"8Gi\"",
  "variables": [
    {
      "key": "spec_components_0_properties_traits_0_properties_replicas",
      "path": "/spec/components/0/properties/traits/0/properties/replicas",
      "type": "float",
      "meaning": "replicas",
      "value": {
        "lower_bound": 1,
        "higher_bound": 3
      }
    },
    {
      "key": "spec_components_0_properties_cpu",
      "path": "/spec/components/0/properties/cpu",
      "type": "float",
      "meaning": "cpu",
      "value": {
        "lower_bound": 1,
        "higher_bound": 3
      }
    },
    {
      "key": "spec_components_0_properties_memory",
      "path": "/spec/components/0/properties/memory",
      "type": "float",
      "meaning": "memory",
      "value": {
        "lower_bound": 4,
        "higher_bound": 16
      }
    },
    {
      "key": "application_deployment_price",
      "path": "",
      "type": "float",
      "meaning": "price",
      "value": {
        "lower_bound": 0,
        "higher_bound": 0
      }
    }
  ],
  "environmentVariables": [
  ],
  "resources": [
    {
      "title": "aws-tid-test-0015",
      "uuid": "e5f1f8f8-f4b9-43f5-90ef-b417f2d34250",
      "platform": "AWS",
      "enabled": false,
      "regions": "eu-north-1",
      "valid_instance_types": "t3.medium,t3.xlarge,t3a.2xlarge,t3.2xlarge"
    },
    {
      "title": "eut-aws-202502051141",
      "uuid": "32aed76d-53bc-4a2b-814b-88de3e7f5432",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": []
    },
    {
      "title": "eut-aws-202502040853",
      "uuid": "77e1bb2d-2913-4656-8456-fd57712d4d7c",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": []
    },
    {
      "title": "aws_eut_202501301557",
      "uuid": "0a75a968-9345-4267-b094-30f3646ec254",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": []
    },
    {
      "title": "test_filter_2",
      "uuid": "afe6d71a-877e-4759-8526-e292974fdeaf",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": "c6g.medium,m6gd.medium"
    },
    {
      "title": "test_filter",
      "uuid": "818a796b-8500-470a-9a5a-6677fb64d777",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": "c6g.medium,m6g.medium,m6gd.medium"
    },
    {
      "title": "adfadfa",
      "uuid": "703c3376-d27c-4320-9c61-89727ad018c4",
      "platform": "OPENSTACK",
      "enabled": false,
      "regions": "asdfa",
      "valid_instance_types": []
    },
    {
      "title": "eut-aws-202501211504",
      "uuid": "78581bf0-08a9-45e8-be0e-ab53f25b3ae0",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": []
    },
    {
      "title": "eut-aws-202501211341",
      "uuid": "ca65f8d3-816a-473a-9b6e-23d57cf248cf",
      "platform": "AWS",
      "enabled": false,
      "regions": "us-east-1",
      "valid_instance_types": []
    },
    {
      "title": "aws-tid-test-0014",
      "uuid": "d3d27238-f0d4-4282-b839-8e26638627ad",
      "platform": "AWS",
      "enabled": false,
      "regions": "eu-north-1",
      "valid_instance_types": []
    }
  ],
  "templates": [],
  "parameters": [],
  "metrics": [
    {
      "type": "raw",
      "name": "gpu_usage_percent",
      "level": "global",
      "components": [],
      "sensor": "prometheus gpu_usage_percent",
      "config": [],
      "isWindowOutputRaw": true,
      "outputRaw": {
        "type": "all",
        "interval": 0,
        "unit": "ms",
        "metaType": "object",
        "scopedObjectName": "doc.application.outputRaw"
      },
      "_id": "cm7d5ha7c0011amskgjqf75pp",
      "metaType": "arrayItem",
      "scopedArrayName": "doc.application.metrics",
      "_docId": "cm1663ky4007g01sda4v64jgd:en:published",
      "_edit": true
    },
    {
      "type": "raw",
      "name": "cpu_usage_percent",
      "level": "global",
      "components": [],
      "sensor": "prometheus cpu_usage_percent",
      "config": [],
      "isWindowOutputRaw": true,
      "outputRaw": {
        "type": "all",
        "interval": 0,
        "unit": "ms",
        "metaType": "object",
        "scopedObjectName": "doc.application.outputRaw"
      },
      "_id": "cm7d5ha7c0012amskazp1f5ui",
      "metaType": "arrayItem",
      "scopedArrayName": "doc.application.metrics",
      "_docId": "cm1663ky4007g01sda4v64jgd:en:published",
      "_edit": true
    },
    {
      "type": "raw",
      "name": "memory_usage_percent",
      "level": "global",
      "components": [],
      "sensor": "prometheus memory_usage_percent",
      "config": [],
      "isWindowOutputRaw": true,
      "outputRaw": {
        "type": "all",
        "interval": 0,
        "unit": "ms",
        "metaType": "object",
        "scopedObjectName": "doc.application.outputRaw"
      },
      "_id": "cm7d5ha7c0013amsk35lu86kz",
      "metaType": "arrayItem",
      "scopedArrayName": "doc.application.metrics",
      "_docId": "cm1663ky4007g01sda4v64jgd:en:published",
      "_edit": true
    }
  ],
  "sloViolations": {
    "nodeKey": "d7d23dc9-16ec-4ab3-a2d6-ff6883cf9a74",
    "isComposite": true,
    "condition": "AND",
    "not": false,
    "children": [
      {
        "nodeKey": "8a4ad522-8fe9-4388-adb9-ff20b060339c",
        "isComposite": false,
        "metricName": "cpu_usage_percent",
        "operator": ">=",
        "value": 1000
      }
    ]
  },
  "utilityFunctions": [
    {
      "name": "a",
      "type": "minimize",
      "expression": {
        "formula": "a+c",
        "variables": [
          {
            "name": "a",
            "value": "cpu_usage_percent"
          },
          {
            "name": "c",
            "value": "application_deployment_price"
          }
        ]
      },
      "selected": true
    },
    {
      "name": "b",
      "type": "maximize",
      "expression": {
        "formula": "a+c",
        "variables": [
          {
            "name": "a",
            "value": "memory_usage_percent"
          },
          {
            "name": "c",
            "value": "spec_components_0_properties_cpu"
          }
        ]
      },
      "selected": false
    },
    {
      "name": "a",
      "type": "constraint",
      "expression": {
        "formula": "f",
        "variables": [
          {
            "name": "f",
            "value": "spec_components_0_properties_memory"
          }
        ]
      },
      "operator": "<="
    }
  ],
  "_create": true,
  "_delete": true
}

Example AMPL:

# AMPL file for application 'Mercabana Intralogistics' with id 419c5ac2-e8cb-4115-8aa1-27d41ba0a08e

# Variables
var spec_components_0_traits_0_properties_replicas >= 1.0, <= 8.0;
var spec_components_0_traits_0_properties_cpu >= 1.0, <= 8.0;
var spec_components_0_traits_0_properties_ram >= 1000.0, <= 8000.0;

# Metrics.  Note that we only emit metrics that are in use.  Values will be provided by the solver.
## Raw metrics
param raw_B;	# raw_B
## Composite metrics
param comp_C; 

## Constants
param currentReplicas;

# Performance indicators = composite metrics that have at least one variable in their formula. Firstly defined:
var pi_D = spec_components_0_traits_0_properties_replicas + comp_C + raw_B;
var pi_F = pi_D + comp_C;

#Cost performance indicators
param COEFFICIENTS_0{1..2};  #WORKS
#param COEFFICIENTS_0 := 1 0.1 2 0.3;
param COEFFICIENTS_1{1..1};
var cost_pi_0 = COEFFICIENTS_0[1] * spec_components_0_traits_0_properties_cpu + COEFFICIENTS_0[2] * spec_components_0_traits_0_properties_ram; 
var cost_pi_1 = COEFFICIENTS_1[1] * spec_components_0_traits_0_properties_cpu;
# variables: spec_components_0_traits_0_properties_cpu, spec_components_0_traits_0_properties_ram
# coefficientsName: COEFFICIENTS_0

var application_deployment_price = spec_components_0_traits_0_properties_replicas * cost_pi_0 + REPLICAS_2 * cost_pi_1;


# Utility functions
maximize firstfunction :
	(comp_C*currentReplicas)/spec_components_0_traits_0_properties_replicas;
	
minimize costfunction: 
	application_deployment_price;

# Default utility function: specified in message to solver

# Constraints that include variables / performance indicators

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions