Green-Software-Foundation / if

Impact Framework
https://if.greensoftware.foundation/
MIT License
136 stars 37 forks source link

Add parameter mapping feature #820

Open zanete opened 3 weeks ago

zanete commented 3 weeks ago

Why: Sub of #761 - so that we can automatically add the return values of one plugin to the inputs array under the name required by another plugin

What: Build a feature in IF that maps a parameter that is present in the input data to a new name that is expected by a particular plugin. For example, let's say a hypothetical plugin, myPlugin expects to see cpu/util in the inputs array. That p[recise parametr is not available in the array, but the precise same information is available with the cpu-utilization name. In this case, we want to use the mapping feature to pass the value of cpu-utilization to myPlugin as cpu/util.

The configuration for this should be done in the manifest, in the initialization bock for each plugin, for example:

initialize:
  plugins:
    my-plugin:
      method: MyPlugin
      path: @grnsft/dummy-plugins
      mapping:
        cpu/util: cpu-utilization

In this case, my-plugin, which expects to see cpu/util will understand that it should use the cpu-utilization values rather than throwing an error because cpu/util is not available.

Scope of work:

Acceptance criteria

name: sum
description: successful path
tags:
initialize:
  plugins:
    sum:
      method: Sum
      path: "builtin"
      global-config:
        input-parameters: ["cpu/energy", "network/energy"]
        output-parameter: "energy"
      mapping:
        cpu/energy: energy-from-cpu
        network/energy: energy-from-network
tree:
  children:
    child:
      pipeline:
        - sum
      config:
        sum:
      inputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          energy-from-cpu: 0.001
          energy-from-network: 0.001

THEN IF should map the available energy-from-cpu and energy-from-network values to the expected cpu/energy and network/energy values and correctly execute the sum plugin, yielding the following manifest:

name: sum
description: successful path
tags:
initialize:
  plugins:
    sum:
      method: Sum
      path: "builtin"
      global-config:
        input-parameters: ["cpu/energy", "network/energy"]
        output-parameter: "energy"
      mapping:
        cpu/energy: energy-from-cpu
        network/energy: energy-from-network
tree:
  children:
    child:
      pipeline:
        - sum
      config:
        sum:
      inputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          energy-from-cpu: 0.001
          energy-from-network: 0.001
      outputs:
        - timestamp: 2023-08-06T00:00
          duration: 3600
          energy-from-cpu: 0.001
          energy-from-network: 0.001
          energy: 0.002

This behaviour should generalize to any plugin.

zanete commented 2 weeks ago

@manushak @narekhovhannisyan please review ac to confirm you're ok with it