From 548c02917c7228b8c047a72405c8ff06dc8fc0a3 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:31:21 +0400 Subject: [PATCH 01/35] feat(util): add `parameter-metadata` into manifest validation schema --- src/common/util/validations.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/util/validations.ts b/src/common/util/validations.ts index 76b785d6d..98d017c29 100644 --- a/src/common/util/validations.ts +++ b/src/common/util/validations.ts @@ -56,6 +56,30 @@ export const manifestSchema = z.object({ path: z.string(), method: z.string(), 'global-config': z.record(z.string(), z.any()).optional(), + 'parameter-metadata': z + .object({ + inputs: z + .record( + z.string(), + z.object({ + unit: z.string(), + description: z.string(), + }) + ) + .optional() + .nullable(), + outputs: z + .record( + z.string(), + z.object({ + unit: z.string(), + description: z.string(), + }) + ) + .optional() + .nullable(), + }) + .optional(), }) ), }), From 6a2584952bc331cc2dc54b88617e5cb15a94c59e Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:33:08 +0400 Subject: [PATCH 02/35] feat(lib): add `parameter-metadata` as a second parameter of the plugins --- src/if-run/lib/initialize.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/if-run/lib/initialize.ts b/src/if-run/lib/initialize.ts index 5833787ba..5adcc2b18 100644 --- a/src/if-run/lib/initialize.ts +++ b/src/if-run/lib/initialize.ts @@ -79,7 +79,12 @@ const handModule = (method: string, pluginPath: string) => { const initPlugin = async ( initPluginParams: PluginOptions ): Promise => { - const {method, path, 'global-config': globalConfig} = initPluginParams; + const { + method, + path, + 'global-config': globalConfig, + 'parameter-metadata': parameterMetadata, + } = initPluginParams; console.debug(INITIALIZING_PLUGIN(method)); @@ -93,7 +98,7 @@ const initPlugin = async ( const plugin = await handModule(method, path); - return plugin(globalConfig); + return plugin(globalConfig, parameterMetadata); }; /** From 16517ade3ee98d6d51b3ec31685fca6a1011854b Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:36:06 +0400 Subject: [PATCH 03/35] feat(src): update `Coefficient`, `Copy`, `Divide` and `Exponent` plugins code and docs --- src/if-run/builtins/coefficient/README.md | 25 +++++++++++++++- src/if-run/builtins/coefficient/index.ts | 18 +++++++++++- src/if-run/builtins/copy-param/README.md | 36 ++++++++++++++++------- src/if-run/builtins/copy-param/index.ts | 13 ++++++-- src/if-run/builtins/divide/README.md | 15 +++++++++- src/if-run/builtins/divide/index.ts | 14 +++++++-- src/if-run/builtins/exponent/README.md | 15 +++++++++- src/if-run/builtins/exponent/index.ts | 8 ++++- 8 files changed, 125 insertions(+), 19 deletions(-) diff --git a/src/if-run/builtins/coefficient/README.md b/src/if-run/builtins/coefficient/README.md index fb42e32a1..f0e16cb4b 100644 --- a/src/if-run/builtins/coefficient/README.md +++ b/src/if-run/builtins/coefficient/README.md @@ -16,6 +16,20 @@ Three parameters are required in global config: `input-parameter`, `coefficient` - `coefficient`: the value to multiply `input-parameter` by. - `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` +of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameter` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe parameters of the `output-parameter` of the global config. Each parameter has: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -68,6 +82,15 @@ initialize: input-parameter: 'carbon' coefficient: 3 output-parameter: 'carbon-product' + parameter-metadata: + inputs: + carbon: + description: "an amount of carbon emitted into the atmosphere" + unit: "gCO2e" + outputs: + carbon-product: + description: "a product of cabon property and the coefficient" + unit: "gCO2e" tree: children: child: @@ -105,4 +128,4 @@ The required parameters are: You can fix this error by checking you are providing valid values for each parameter in the config. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/coefficient/index.ts b/src/if-run/builtins/coefficient/index.ts index 4b80be633..b6c743170 100644 --- a/src/if-run/builtins/coefficient/index.ts +++ b/src/if-run/builtins/coefficient/index.ts @@ -3,6 +3,7 @@ import {ERRORS} from '@grnsft/if-core/utils'; import { CoefficientConfig, ExecutePlugin, + PluginParametersMetadata, PluginParams, } from '@grnsft/if-core/types'; @@ -13,9 +14,24 @@ import {STRINGS} from '../../config'; const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; -export const Coefficient = (globalConfig: CoefficientConfig): ExecutePlugin => { +export const Coefficient = ( + globalConfig: CoefficientConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + carbon: { + description: 'an amount of carbon emitted into the atmosphere', + unit: 'gCO2e', + }, + }, + outputs: parametersMetadata?.outputs || { + 'carbon-product': { + description: 'a product of cabon property and the coefficient', + unit: 'gCO2e', + }, + }, }; /** diff --git a/src/if-run/builtins/copy-param/README.md b/src/if-run/builtins/copy-param/README.md index 78ab5f656..8e6ef563a 100644 --- a/src/if-run/builtins/copy-param/README.md +++ b/src/if-run/builtins/copy-param/README.md @@ -39,6 +39,19 @@ Three parameters are required in config: `from` and `to` and `keep-existing`. `to`: a string defining the name to use to add the result of summing the input parameters to the output array. `keep-existing`: toggles whether to keep or delete the copied parameter (defined in `to`) +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `from` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `to` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs As with all plugins, `timestamp` and `duration` are required. The key passed to `from` must exist in the `input` data. @@ -47,24 +60,28 @@ As with all plugins, `timestamp` and `duration` are required. The key passed to The plugin adds a new parameter with the name defined in `to` to the `input` data. - ## Implementation To run the plugin, you must first create an instance of `Copy`. Then, you can call `execute()`. ```typescript -import { Copy } from "."; +import {Copy} from '.'; -const plugin = Copy({ 'keep-existing': true, from: 'from-param', to: 'to-param' }); +const plugin = Copy({ + 'keep-existing': true, + from: 'from-param', + to: 'to-param', +}); -const result = plugin.execute([{ - timestamp: "2023-12-12T00:00:13.000Z", +const result = plugin.execute([ + { + timestamp: '2023-12-12T00:00:13.000Z', duration: 30, 'from-param': 'hello', -}]) - -console.log(result) + }, +]); +console.log(result); ``` ## Example manifest @@ -90,9 +107,8 @@ tree: pipeline: - copy-param inputs: - - timestamp: "2023-12-12T00:00:00.000Z" + - timestamp: '2023-12-12T00:00:00.000Z' original: 'hello' - ``` You can run this example by saving it as `./manifests/examples/copy.yml` and executing the following command from the project root: diff --git a/src/if-run/builtins/copy-param/index.ts b/src/if-run/builtins/copy-param/index.ts index cf21cfb8e..7f10bf696 100644 --- a/src/if-run/builtins/copy-param/index.ts +++ b/src/if-run/builtins/copy-param/index.ts @@ -1,6 +1,10 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParametersMetadata, + PluginParams, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -12,9 +16,14 @@ const {GlobalConfigError} = ERRORS; // from-param: the parameter you are copying from (e.g. cpu/name) // to-field: the parameter you are copying to (e.g. cpu/processor-name) -export const Copy = (globalConfig: Record): ExecutePlugin => { +export const Copy = ( + globalConfig: Record, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/divide/README.md b/src/if-run/builtins/divide/README.md index 99f8a23ee..98e5c0314 100644 --- a/src/if-run/builtins/divide/README.md +++ b/src/if-run/builtins/divide/README.md @@ -12,6 +12,19 @@ You provide the names of the values you want to divide, and a name to use to add - `denominator` - a parameter by a specific configured number or the number by which `numerator` is divided - `output` - the number to a configured output parameter +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `numerator` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `denominator` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `numerator` - as input parameter, must be available in the input array @@ -42,7 +55,7 @@ const globalConfig = { denominator: 2, output: 'cpu/number-cores', }; -const divide = Divide(globalConfig); +const divide = Divide(globalConfig, parametersMetadata); const input = [ { diff --git a/src/if-run/builtins/divide/index.ts b/src/if-run/builtins/divide/index.ts index 328c4ccff..3d09c130c 100644 --- a/src/if-run/builtins/divide/index.ts +++ b/src/if-run/builtins/divide/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {GlobalConfigError, MissingInputDataError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA, ZERO_DIVISION} = STRINGS; -export const Divide = (globalConfig: ConfigParams): ExecutePlugin => { +export const Divide = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/exponent/README.md b/src/if-run/builtins/exponent/README.md index fa36319b8..ed1c74b35 100644 --- a/src/if-run/builtins/exponent/README.md +++ b/src/if-run/builtins/exponent/README.md @@ -16,6 +16,19 @@ Three parameters are required in global config: `input-parameter`, `exponent` an `exponent`: a number defining the exponent. `output-parameter`: a string defining the name to use to add the result of the exponent to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes:: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs `input-parameter` and `exponent` must be available in the input array. @@ -111,4 +124,4 @@ Every element in the `inputs` array must contain: This error arises when an invalid value is passed to `Exponent`. Typically, this can occur when a non-numeric value (such as a string made of alphabetic characters) is passed where a number or numeric string is expected. Please check that the types are correct for all the relevant fields in your `inputs` array. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/exponent/index.ts b/src/if-run/builtins/exponent/index.ts index 800b2295e..a821c3a14 100644 --- a/src/if-run/builtins/exponent/index.ts +++ b/src/if-run/builtins/exponent/index.ts @@ -3,13 +3,19 @@ import { ExecutePlugin, PluginParams, ExponentConfig, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Exponent = (globalConfig: ExponentConfig): ExecutePlugin => { +export const Exponent = ( + globalConfig: ExponentConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 9b3890ec96cdae98b35f7a9c656ec2de6b5b02d0 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:38:28 +0400 Subject: [PATCH 04/35] feat(src): update `Interpolation`, `Multiply`, `Regex` and `Sum` plugins and their docs --- src/if-run/builtins/interpolation/README.md | 13 ++++++++++ src/if-run/builtins/interpolation/index.ts | 16 +++++++++--- src/if-run/builtins/multiply/README.md | 15 +++++++++++- src/if-run/builtins/multiply/index.ts | 8 +++++- src/if-run/builtins/regex/README.md | 13 ++++++++++ src/if-run/builtins/regex/index.ts | 14 +++++++++-- src/if-run/builtins/sum/README.md | 27 ++++++++++++++++++++- src/if-run/builtins/sum/index.ts | 14 +++++++++-- 8 files changed, 109 insertions(+), 11 deletions(-) diff --git a/src/if-run/builtins/interpolation/README.md b/src/if-run/builtins/interpolation/README.md index 74c8498a3..dedcfe5e9 100644 --- a/src/if-run/builtins/interpolation/README.md +++ b/src/if-run/builtins/interpolation/README.md @@ -25,6 +25,19 @@ To employ the `Interpolation` plugin, adhere to these steps: `x` and `y` arrays must be equal lengths. +## Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ## Input Parameters The plugin expects the following input parameters: diff --git a/src/if-run/builtins/interpolation/index.ts b/src/if-run/builtins/interpolation/index.ts index 03239a004..60fe90e5b 100644 --- a/src/if-run/builtins/interpolation/index.ts +++ b/src/if-run/builtins/interpolation/index.ts @@ -6,6 +6,7 @@ import { PluginParams, ConfigParams, Method, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -20,7 +21,16 @@ const { WITHIN_THE_RANGE, } = STRINGS; -export const Interpolation = (globalConfig: ConfigParams): ExecutePlugin => { +export const Interpolation = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { + const metadata = { + kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, + }; + /** * Executes the energy consumption calculation for an array of input parameters. */ @@ -189,9 +199,7 @@ export const Interpolation = (globalConfig: ConfigParams): ExecutePlugin => { }; return { - metadata: { - kind: 'execute', - }, + metadata, execute, }; }; diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 0ce42c7c0..08ebe9526 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -41,7 +54,7 @@ const config = { outputParameter: 'energy-product', }; -const mult = Multiply(config); +const mult = Multiply(config, parametersMetadata); const result = await mult.execute([ { duration: 3600, diff --git a/src/if-run/builtins/multiply/index.ts b/src/if-run/builtins/multiply/index.ts index 706e190ec..b51c1a426 100644 --- a/src/if-run/builtins/multiply/index.ts +++ b/src/if-run/builtins/multiply/index.ts @@ -3,13 +3,19 @@ import { ExecutePlugin, PluginParams, MultiplyConfig, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Multiply = (globalConfig: MultiplyConfig): ExecutePlugin => { +export const Multiply = ( + globalConfig: MultiplyConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/regex/README.md b/src/if-run/builtins/regex/README.md index cba3b6fe4..99685a15b 100644 --- a/src/if-run/builtins/regex/README.md +++ b/src/if-run/builtins/regex/README.md @@ -16,6 +16,19 @@ Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-26 - `match` - a regex by which needs to match the `parameter` - `output` - output parameter name in the input +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameter of the `parameter` value of the global config. The parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameters of the `output` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `parameter` - as input parameter, must be available in the input array diff --git a/src/if-run/builtins/regex/index.ts b/src/if-run/builtins/regex/index.ts index 45c65d6f6..59c10154c 100644 --- a/src/if-run/builtins/regex/index.ts +++ b/src/if-run/builtins/regex/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {MissingInputDataError, GlobalConfigError, RegexMismatchError} = ERRORS; const {MISSING_GLOBAL_CONFIG, MISSING_INPUT_DATA, REGEX_MISMATCH} = STRINGS; -export const Regex = (globalConfig: ConfigParams): ExecutePlugin => { +export const Regex = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/sum/README.md b/src/if-run/builtins/sum/README.md index 997a6e1cf..4d861f2c9 100644 --- a/src/if-run/builtins/sum/README.md +++ b/src/if-run/builtins/sum/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the result of summing the input parameters to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. @@ -39,7 +52,7 @@ const config = { outputParameter: 'energy', }; -const sum = Sum(config); +const sum = Sum(config, parametersMetadata); const result = sum.execute([ { timestamp: '2021-01-01T00:00:00Z', @@ -66,6 +79,18 @@ initialize: global-config: input-parameters: ['cpu/energy', 'network/energy'] output-parameter: 'energy' + parameter-metadata: + inputs: + cpu/energy: + description: energy consumed by the cpu + unit: kWh + network/energy: + description: energy consumed by data ingress and egress + unit: kWh + outputs: + energy: + description: sum of energy components + unit: kWh tree: children: child: diff --git a/src/if-run/builtins/sum/index.ts b/src/if-run/builtins/sum/index.ts index 62ba479e6..da642dd13 100644 --- a/src/if-run/builtins/sum/index.ts +++ b/src/if-run/builtins/sum/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, SumConfig} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + SumConfig, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -9,9 +14,14 @@ import {STRINGS} from '../../config'; const {GlobalConfigError} = ERRORS; const {MISSING_GLOBAL_CONFIG} = STRINGS; -export const Sum = (globalConfig: SumConfig): ExecutePlugin => { +export const Sum = ( + globalConfig: SumConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 61b089d8793226b3af0ecd4f0cf35e04ab339e5f Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:51:24 +0400 Subject: [PATCH 05/35] feat(src): update `Sci`, `SciEmbodied` and `Subtract` plugins and their docs --- src/if-run/builtins/csv-lookup/README.md | 4 +-- src/if-run/builtins/sci-embodied/README.md | 13 +++++++ src/if-run/builtins/sci-embodied/index.ts | 42 ++++++++++++++++++++-- src/if-run/builtins/sci/README.md | 13 +++++++ src/if-run/builtins/sci/index.ts | 29 +++++++++++++-- src/if-run/builtins/subtract/README.md | 13 +++++++ src/if-run/builtins/subtract/index.ts | 8 ++++- 7 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/if-run/builtins/csv-lookup/README.md b/src/if-run/builtins/csv-lookup/README.md index 61af5b292..317f3c897 100644 --- a/src/if-run/builtins/csv-lookup/README.md +++ b/src/if-run/builtins/csv-lookup/README.md @@ -84,7 +84,7 @@ const globalConfig = { }, output: ['cpu-tdp', 'tdp'], }; -const divide = CSVLookup(globalConfig); +const csvLookup = CSVLookup(globalConfig); const input = [ { @@ -173,4 +173,4 @@ The required parameters are: You can fix this error by checking you are providing valid values for each parameter in the config. -For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors +For more information on our error classes, please visit [our docs](https://if.greensoftware.foundation/reference/errors) diff --git a/src/if-run/builtins/sci-embodied/README.md b/src/if-run/builtins/sci-embodied/README.md index b4d71304b..21266fba7 100644 --- a/src/if-run/builtins/sci-embodied/README.md +++ b/src/if-run/builtins/sci-embodied/README.md @@ -10,6 +10,19 @@ Read more on [embodied carbon](https://github.com/Green-Software-Foundation/sci/ Not Needed +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe the parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the `carbon-embodied` parameter. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `device/emissions-embodied`: the sum of Life Cycle Assessment (LCA) emissions for the component diff --git a/src/if-run/builtins/sci-embodied/index.ts b/src/if-run/builtins/sci-embodied/index.ts index 2fffc09ed..e2a60edd6 100644 --- a/src/if-run/builtins/sci-embodied/index.ts +++ b/src/if-run/builtins/sci-embodied/index.ts @@ -1,5 +1,9 @@ import {z} from 'zod'; -import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParametersMetadata, + PluginParams, +} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../../common/util/validations'; @@ -7,9 +11,43 @@ import {STRINGS} from '../../config'; const {SCI_EMBODIED_ERROR} = STRINGS; -export const SciEmbodied = (): ExecutePlugin => { +export const SciEmbodied = ( + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + 'device/emissions-embodied': { + description: 'total embodied emissions of some component', + unit: 'gCO2e', + }, + 'device/expected-lifespan': { + description: 'Total Expected Lifespan of the Component in Seconds', + unit: 'seconds', + }, + 'resources-reserved': { + description: 'resources reserved for an application', + unit: 'count', + }, + 'resources-total': { + description: 'total resources available', + unit: 'count', + }, + 'vcpus-allocated': { + description: 'number of vcpus allocated to particular resource', + unit: 'count', + }, + 'vcpus-total': { + description: 'total number of vcpus available on a particular resource', + unit: 'count', + }, + }, + outputs: parametersMetadata?.outputs || { + 'carbon-embodied': { + description: 'embodied emissions of the component', + unit: 'gCO2e', + }, + }, }; const METRICS = [ diff --git a/src/if-run/builtins/sci/README.md b/src/if-run/builtins/sci/README.md index d40ca93ed..4d9544ad2 100644 --- a/src/if-run/builtins/sci/README.md +++ b/src/if-run/builtins/sci/README.md @@ -8,6 +8,19 @@ - `functional-unit`: the name of the functional unit in which to express the carbon impact (required) +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the `sci` parameter which has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs - `carbon`: total carbon in gCO2eq (required) diff --git a/src/if-run/builtins/sci/index.ts b/src/if-run/builtins/sci/index.ts index f11f6c2b8..90cf55fb7 100644 --- a/src/if-run/builtins/sci/index.ts +++ b/src/if-run/builtins/sci/index.ts @@ -1,6 +1,11 @@ import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate, allDefined} from '../../../common/util/validations'; @@ -14,9 +19,29 @@ const { ZERO_DIVISION, } = STRINGS; -export const Sci = (globalConfig: ConfigParams): ExecutePlugin => { +export const Sci = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + carbon: { + description: 'an amount of carbon emitted into the atmosphere', + unit: 'gCO2e', + }, + 'functional-unit': { + description: + 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', + unit: 'none', + }, + }, + outputs: parametersMetadata?.outputs || { + sci: { + description: 'carbon expressed in terms of the given functional unit', + unit: 'gCO2e', + }, + }, }; /** diff --git a/src/if-run/builtins/subtract/README.md b/src/if-run/builtins/subtract/README.md index 726f982b2..9916404bc 100644 --- a/src/if-run/builtins/subtract/README.md +++ b/src/if-run/builtins/subtract/README.md @@ -15,6 +15,19 @@ Two parameters are required in global config: `input-parameters` and `output-par `input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array `output-parameter`: a string defining the name to use to add the result of the diff to the output array. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs + +- `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has the following attributes: + + - `description`: description of the parameter + - `unit`: unit of the parameter + +- `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + ### Inputs All of `input-parameters` must be available in the input array. diff --git a/src/if-run/builtins/subtract/index.ts b/src/if-run/builtins/subtract/index.ts index bd5af0603..2598ecb8a 100644 --- a/src/if-run/builtins/subtract/index.ts +++ b/src/if-run/builtins/subtract/index.ts @@ -1,15 +1,21 @@ import {z} from 'zod'; import { ExecutePlugin, + PluginParametersMetadata, PluginParams, SubtractConfig, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; -export const Subtract = (globalConfig: SubtractConfig): ExecutePlugin => { +export const Subtract = ( + globalConfig: SubtractConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** From 2574f4ff93fb65d8adbc2eeb978825f8edbde0d8 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 12 Jul 2024 18:54:29 +0400 Subject: [PATCH 06/35] test(builtins): add `parametersMetadata` into the tests --- .../if-run/builtins/coefficient.test.ts | 12 +++-- .../if-run/builtins/copy-param.test.ts | 12 +++-- src/__tests__/if-run/builtins/divide.test.ts | 16 +++--- .../if-run/builtins/exponent.test.ts | 8 ++- .../if-run/builtins/interpolation.test.ts | 20 +++++--- .../if-run/builtins/multiply.test.ts | 8 ++- src/__tests__/if-run/builtins/regex.test.ts | 12 +++-- .../if-run/builtins/sci-embodied.test.ts | 6 ++- src/__tests__/if-run/builtins/sci.test.ts | 51 +++++++++++++------ .../if-run/builtins/subtract.test.ts | 8 ++- src/__tests__/if-run/builtins/sum.test.ts | 10 ++-- 11 files changed, 111 insertions(+), 52 deletions(-) diff --git a/src/__tests__/if-run/builtins/coefficient.test.ts b/src/__tests__/if-run/builtins/coefficient.test.ts index 1660edffe..8d99c3e87 100644 --- a/src/__tests__/if-run/builtins/coefficient.test.ts +++ b/src/__tests__/if-run/builtins/coefficient.test.ts @@ -14,7 +14,11 @@ describe('builtins/coefficient: ', () => { coefficient: 3, 'output-parameter': 'carbon-product', }; - const coefficient = Coefficient(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const coefficient = Coefficient(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -51,7 +55,7 @@ describe('builtins/coefficient: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const coefficient = Coefficient(config!); + const coefficient = Coefficient(config!, parametersMetadata); expect.assertions(1); @@ -76,7 +80,7 @@ describe('builtins/coefficient: ', () => { coefficient: 3, 'output-parameter': 'carbon-product', }; - const coefficient = Coefficient(invalidConfig); + const coefficient = Coefficient(invalidConfig, parametersMetadata); const expectedMessage = '"input-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.'; @@ -103,7 +107,7 @@ describe('builtins/coefficient: ', () => { coefficient: 10, 'output-parameter': '', }; - const coefficient = Coefficient(invalidConfig); + const coefficient = Coefficient(invalidConfig, parametersMetadata); const expectedMessage = '"output-parameter" parameter is string must contain at least 1 character(s). Error code: too_small.'; diff --git a/src/__tests__/if-run/builtins/copy-param.test.ts b/src/__tests__/if-run/builtins/copy-param.test.ts index 8ac621538..952546505 100644 --- a/src/__tests__/if-run/builtins/copy-param.test.ts +++ b/src/__tests__/if-run/builtins/copy-param.test.ts @@ -14,7 +14,11 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const copy = Copy(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -49,7 +53,7 @@ describe('builtins/copy: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const copy = Copy(config!); + const copy = Copy(config!, parametersMetadata); expect.assertions(1); @@ -74,7 +78,7 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const copy = Copy(globalConfig, parametersMetadata); expect.assertions(1); try { @@ -99,7 +103,7 @@ describe('builtins/copy: ', () => { from: 'original', to: 'copy', }; - const copy = Copy(globalConfig); + const copy = Copy(globalConfig, parametersMetadata); const expectedResult = [ { diff --git a/src/__tests__/if-run/builtins/divide.test.ts b/src/__tests__/if-run/builtins/divide.test.ts index b9d1d9456..e0a472998 100644 --- a/src/__tests__/if-run/builtins/divide.test.ts +++ b/src/__tests__/if-run/builtins/divide.test.ts @@ -14,7 +14,11 @@ describe('builtins/divide: ', () => { denominator: 2, output: 'cpu/number-cores', }; - const divide = Divide(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const divide = Divide(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -54,7 +58,7 @@ describe('builtins/divide: ', () => { denominator: 'duration', output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); const input = [ { @@ -86,7 +90,7 @@ describe('builtins/divide: ', () => { denominator: 3600, output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); @@ -107,7 +111,7 @@ describe('builtins/divide: ', () => { it('throws an error on missing global config.', async () => { const config = undefined; - const divide = Divide(config!); + const divide = Divide(config!, parametersMetadata); expect.assertions(1); @@ -131,7 +135,7 @@ describe('builtins/divide: ', () => { denominator: 0, output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); @@ -159,7 +163,7 @@ describe('builtins/divide: ', () => { denominator: '10', output: 'vcpus-allocated-per-second', }; - const divide = Divide(globalConfig); + const divide = Divide(globalConfig, parametersMetadata); expect.assertions(1); diff --git a/src/__tests__/if-run/builtins/exponent.test.ts b/src/__tests__/if-run/builtins/exponent.test.ts index 3b88df0cb..2e0419686 100644 --- a/src/__tests__/if-run/builtins/exponent.test.ts +++ b/src/__tests__/if-run/builtins/exponent.test.ts @@ -11,7 +11,11 @@ describe('builtins/exponent: ', () => { exponent: 3, 'output-parameter': 'energy', }; - const exponent = Exponent(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const exponent = Exponent(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -91,7 +95,7 @@ describe('builtins/exponent: ', () => { exponent: 4, 'output-parameter': 'carbon', }; - const exponent = Exponent(newConfig); + const exponent = Exponent(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/interpolation.test.ts b/src/__tests__/if-run/builtins/interpolation.test.ts index 8dbd1295c..6634556dd 100644 --- a/src/__tests__/if-run/builtins/interpolation.test.ts +++ b/src/__tests__/if-run/builtins/interpolation.test.ts @@ -22,6 +22,10 @@ describe('builtins/interpolation: ', () => { 'input-parameter': 'cpu/utilization', 'output-parameter': 'interpolation-result', }; + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; const inputs = [ { timestamp: '2023-07-06T00:00', @@ -29,7 +33,7 @@ describe('builtins/interpolation: ', () => { 'cpu/utilization': 45, }, ]; - const plugin = Interpolation(globalConfig); + const plugin = Interpolation(globalConfig, parametersMetadata); describe('init Interpolation: ', () => { it('initalizes object with properties.', async () => { @@ -59,7 +63,7 @@ describe('builtins/interpolation: ', () => { 'input-parameter': 'cpu/utilization', 'output-parameter': 'interpolation-result', }; - const plugin = Interpolation(globalConfig); + const plugin = Interpolation(globalConfig, parametersMetadata); const outputs = [ { @@ -75,7 +79,7 @@ describe('builtins/interpolation: ', () => { it('returns result when the `method` is `spline`.', () => { const config = Object.assign({}, globalConfig, {method: Method.SPLINE}); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -93,7 +97,7 @@ describe('builtins/interpolation: ', () => { const config = Object.assign({}, globalConfig, { method: Method.POLYNOMIAL, }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -111,7 +115,7 @@ describe('builtins/interpolation: ', () => { const config = Object.assign({}, globalConfig, { x: [0, 10, 100, 50], }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const outputs = [ { @@ -147,7 +151,7 @@ describe('builtins/interpolation: ', () => { it('throws an when the global config is not provided.', () => { const config = undefined; - const plugin = Interpolation(config!); + const plugin = Interpolation(config!, parametersMetadata); expect.assertions(2); try { @@ -163,7 +167,7 @@ describe('builtins/interpolation: ', () => { x: [0, 10, 100], }); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); expect.assertions(2); try { @@ -198,7 +202,7 @@ describe('builtins/interpolation: ', () => { 'output-parameter': 'interpolation-result', }; const config = Object.assign({}, globalConfig, {method: Method.SPLINE}); - const plugin = Interpolation(config); + const plugin = Interpolation(config, parametersMetadata); const inputs = [ { timestamp: '2023-07-06T00:00', diff --git a/src/__tests__/if-run/builtins/multiply.test.ts b/src/__tests__/if-run/builtins/multiply.test.ts index 07dedf5ea..b3856dfd4 100644 --- a/src/__tests__/if-run/builtins/multiply.test.ts +++ b/src/__tests__/if-run/builtins/multiply.test.ts @@ -10,7 +10,11 @@ describe('builtins/multiply: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy', }; - const multiply = Multiply(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const multiply = Multiply(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -72,7 +76,7 @@ describe('builtins/multiply: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-product', }; - const multiply = Multiply(newConfig); + const multiply = Multiply(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/regex.test.ts b/src/__tests__/if-run/builtins/regex.test.ts index 6ac6bd4e9..6d039363d 100644 --- a/src/__tests__/if-run/builtins/regex.test.ts +++ b/src/__tests__/if-run/builtins/regex.test.ts @@ -14,7 +14,11 @@ describe('builtins/regex: ', () => { match: '^[^,]+', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const regex = Regex(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -59,7 +63,7 @@ describe('builtins/regex: ', () => { match: '[^,]+/', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); const expectedResult = [ { @@ -90,7 +94,7 @@ describe('builtins/regex: ', () => { match: '^(^:)+', output: 'cpu/name', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); expect.assertions(1); @@ -113,7 +117,7 @@ describe('builtins/regex: ', () => { it('throws an error on missing global config.', async () => { const config = undefined; - const regex = Regex(config!); + const regex = Regex(config!, parametersMetadata); expect.assertions(1); diff --git a/src/__tests__/if-run/builtins/sci-embodied.test.ts b/src/__tests__/if-run/builtins/sci-embodied.test.ts index 0c1b504ac..0e2c234f7 100644 --- a/src/__tests__/if-run/builtins/sci-embodied.test.ts +++ b/src/__tests__/if-run/builtins/sci-embodied.test.ts @@ -9,7 +9,11 @@ const {SCI_EMBODIED_ERROR} = STRINGS; describe('builtins/sci-embodied:', () => { describe('SciEmbodied: ', () => { - const sciEmbodied = SciEmbodied(); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sciEmbodied = SciEmbodied(parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { diff --git a/src/__tests__/if-run/builtins/sci.test.ts b/src/__tests__/if-run/builtins/sci.test.ts index 2d75ea170..0360149a9 100644 --- a/src/__tests__/if-run/builtins/sci.test.ts +++ b/src/__tests__/if-run/builtins/sci.test.ts @@ -6,7 +6,11 @@ const {MissingInputDataError} = ERRORS; describe('builtins/sci:', () => { describe('Sci: ', () => { - const sci = Sci({'functional-unit': 'users'}); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sci = Sci({'functional-unit': 'users'}, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -17,9 +21,12 @@ describe('builtins/sci:', () => { describe('execute():', () => { it('returns a result with valid inputs.', async () => { - const sci = Sci({ - 'functional-unit': 'users', - }); + const sci = Sci( + { + 'functional-unit': 'users', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -48,9 +55,12 @@ describe('builtins/sci:', () => { }); it('returns the same result regardless of input duration.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -96,9 +106,12 @@ describe('builtins/sci:', () => { }); it('throws exception on invalid functional unit data.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -118,9 +131,12 @@ describe('builtins/sci:', () => { }); it('throws exception if functional unit value is not positive integer.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', @@ -142,9 +158,12 @@ describe('builtins/sci:', () => { }); it('fallbacks to carbon value, if functional unit is 0.', async () => { - const sci = Sci({ - 'functional-unit': 'requests', - }); + const sci = Sci( + { + 'functional-unit': 'requests', + }, + parametersMetadata + ); const inputs = [ { timestamp: '2021-01-01T00:00:00Z', diff --git a/src/__tests__/if-run/builtins/subtract.test.ts b/src/__tests__/if-run/builtins/subtract.test.ts index 33ba137ab..134cebfa7 100644 --- a/src/__tests__/if-run/builtins/subtract.test.ts +++ b/src/__tests__/if-run/builtins/subtract.test.ts @@ -10,7 +10,11 @@ describe('builtins/subtract: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy/diff', }; - const subtract = Subtract(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const subtract = Subtract(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -72,7 +76,7 @@ describe('builtins/subtract: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-diff', }; - const subtract = Subtract(newConfig); + const subtract = Subtract(newConfig, parametersMetadata); const data = [ { diff --git a/src/__tests__/if-run/builtins/sum.test.ts b/src/__tests__/if-run/builtins/sum.test.ts index d7530827c..9ccc64378 100644 --- a/src/__tests__/if-run/builtins/sum.test.ts +++ b/src/__tests__/if-run/builtins/sum.test.ts @@ -13,7 +13,11 @@ describe('builtins/sum: ', () => { 'input-parameters': ['cpu/energy', 'network/energy', 'memory/energy'], 'output-parameter': 'energy', }; - const sum = Sum(globalConfig); + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + const sum = Sum(globalConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -52,7 +56,7 @@ describe('builtins/sum: ', () => { it('throws an error when global config is not provided.', () => { const config = undefined; - const sum = Sum(config!); + const sum = Sum(config!, parametersMetadata); expect.assertions(1); @@ -98,7 +102,7 @@ describe('builtins/sum: ', () => { 'input-parameters': ['carbon', 'other-carbon'], 'output-parameter': 'carbon-sum', }; - const sum = Sum(newConfig); + const sum = Sum(newConfig, parametersMetadata); const data = [ { From 029978dca6ddc049d9d7dc2602109a2b37cb6a03 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:36:07 +0400 Subject: [PATCH 07/35] feat(util): add explain and explainer properties in the manifest validation --- src/common/util/validations.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/util/validations.ts b/src/common/util/validations.ts index 98d017c29..5298d7d74 100644 --- a/src/common/util/validations.ts +++ b/src/common/util/validations.ts @@ -38,6 +38,8 @@ export const manifestSchema = z.object({ }) .optional() .nullable(), + explainer: z.boolean().optional(), + explain: z.record(z.string(), z.any()).optional(), aggregation: z .object({ metrics: z.record( From 9c7a7f008178da57f1b96e8df24f1108654d3e78 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:41:30 +0400 Subject: [PATCH 08/35] feat(types): add `ExplainParams` type --- src/if-run/types/explain.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/if-run/types/explain.ts diff --git a/src/if-run/types/explain.ts b/src/if-run/types/explain.ts new file mode 100644 index 000000000..b1b684882 --- /dev/null +++ b/src/if-run/types/explain.ts @@ -0,0 +1,7 @@ +import {ParameterMetadata} from '@grnsft/if-core/types'; + +export type ExplainParams = { + pluginName: string; + pluginData: {method: string; path: string}; + metadata: {inputs?: ParameterMetadata; outputs?: ParameterMetadata}; +}; From 4ecc3d7feaee148d32b71ce12175aea2e2634132 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:43:07 +0400 Subject: [PATCH 09/35] feat(lib): add `explain` logic --- src/if-run/lib/explain.ts | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/if-run/lib/explain.ts diff --git a/src/if-run/lib/explain.ts b/src/if-run/lib/explain.ts new file mode 100644 index 000000000..add1a02b6 --- /dev/null +++ b/src/if-run/lib/explain.ts @@ -0,0 +1,44 @@ +import {ExplainParams} from '../types/explain'; + +/** + * Retrieves stored explain data. + */ +export const explain = () => storeExplainData.plugins; + +/** + * Manages the storage of explain data. + */ +const storeExplainData = (() => { + let plugin = {}; + + const pluginManager = { + get plugins() { + return plugin; + }, + set plugins(value: object) { + plugin = value; + }, + }; + + return pluginManager; +})(); + +/** + * Adds new explain data to the stored explain data. + */ +export const addExplainData = (params: ExplainParams) => { + const {pluginName, pluginData, metadata} = params; + const plugin = { + [pluginName]: { + method: pluginData.method, + path: pluginData.path, + inputs: metadata?.inputs || 'undefined', + outputs: metadata?.outputs || 'undefined', + }, + }; + + storeExplainData.plugins = { + ...storeExplainData.plugins, + ...plugin, + }; +}; From 2e35df3a1400d465614001b4646108ad647c6564 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:44:56 +0400 Subject: [PATCH 10/35] test(lib): add tests for --- src/__tests__/if-run/lib/explain.test.ts | 86 ++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/__tests__/if-run/lib/explain.test.ts diff --git a/src/__tests__/if-run/lib/explain.test.ts b/src/__tests__/if-run/lib/explain.test.ts new file mode 100644 index 000000000..509c3ba32 --- /dev/null +++ b/src/__tests__/if-run/lib/explain.test.ts @@ -0,0 +1,86 @@ +import {explain, addExplainData} from '../../../if-run/lib/explain'; + +describe('lib/explain: ', () => { + it('successfully adds explain data if `inputs` and `outputs` of `metadata` are `undefined`.', () => { + const mockData = { + pluginName: 'divide', + metadata: {kind: 'execute', inputs: undefined, outputs: undefined}, + pluginData: { + path: 'builtin', + method: 'Divide', + }, + }; + const expectedResult = { + divide: { + method: 'Divide', + path: 'builtin', + inputs: 'undefined', + outputs: 'undefined', + }, + }; + + addExplainData(mockData); + const result = explain(); + expect.assertions(1); + expect(result).toEqual(expectedResult); + }); + + it('successfully adds explain data if `inputs` and `outputs` of `metadata` are valid data.', () => { + const mockData = { + pluginName: 'sum', + metadata: { + kind: 'execute', + inputs: { + 'cpu/energy': { + unit: 'kWh', + description: 'energy consumed by the cpu', + }, + 'network/energy': { + unit: 'kWh', + description: 'energy consumed by data ingress and egress', + }, + }, + outputs: { + 'energy-sum': { + unit: 'kWh', + description: 'sum of energy components', + }, + }, + }, + pluginData: { + path: 'builtin', + method: 'Sum', + }, + }; + const expectedResult = { + divide: { + method: 'Divide', + path: 'builtin', + inputs: 'undefined', + outputs: 'undefined', + }, + sum: { + method: 'Sum', + path: 'builtin', + inputs: { + 'cpu/energy': { + unit: 'kWh', + description: 'energy consumed by the cpu', + }, + 'network/energy': { + unit: 'kWh', + description: 'energy consumed by data ingress and egress', + }, + }, + outputs: { + 'energy-sum': {unit: 'kWh', description: 'sum of energy components'}, + }, + }, + }; + + addExplainData(mockData); + const result = explain(); + expect.assertions(1); + expect(result).toEqual(expectedResult); + }); +}); From 3a9023a07b40fa269f568a17793c95a38c45a3d4 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:48:48 +0400 Subject: [PATCH 11/35] feat(lib): add logic in the compute.ts to add explain data in the storage --- src/if-run/lib/compute.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/if-run/lib/compute.ts b/src/if-run/lib/compute.ts index dde49d3f7..02cc8e0e4 100644 --- a/src/if-run/lib/compute.ts +++ b/src/if-run/lib/compute.ts @@ -7,6 +7,7 @@ import {STRINGS} from '../config/strings'; import {isExecute, isGroupBy} from '../types/interface'; import {ComputeParams, Node, Params} from '../types/compute'; +import {addExplainData} from './explain'; const {MERGING_DEFAULTS_WITH_INPUT_DATA, COMPUTING_PIPELINE_FOR_NODE} = STRINGS; @@ -78,6 +79,15 @@ const computeNode = async (node: Node, params: Params): Promise => { if (isExecute(plugin)) { inputStorage = await plugin.execute(inputStorage, nodeConfig); + + if (params.context.explainer) { + addExplainData({ + pluginName, + metadata: plugin.metadata, + pluginData: params.context.initialize.plugins[pluginName], + }); + } + debugLogger.setExecutingPluginName(); node.outputs = inputStorage; From 41f9816767b81b5970dba7c6746594d85bdd91d5 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 16 Jul 2024 10:50:34 +0400 Subject: [PATCH 12/35] feat(src): add logic to compose explain data when it's true --- src/if-run/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/if-run/index.ts b/src/if-run/index.ts index 5ffb62ded..ab4e7df01 100644 --- a/src/if-run/index.ts +++ b/src/if-run/index.ts @@ -14,6 +14,7 @@ import {debugLogger} from '../common/util/debug-logger'; import {STRINGS} from './config'; import {STRINGS as COMMON_STRINGS} from '../common/config'; +import {explain} from './lib/explain'; const {EXITING_IF, STARTING_IF} = STRINGS; const {DISCLAIMER_MESSAGE} = COMMON_STRINGS; @@ -39,6 +40,9 @@ const impactEngine = async () => { const pluginStorage = await initialize(context.initialize.plugins); const computedTree = await compute(tree, {context, pluginStorage}); const aggregatedTree = aggregate(computedTree, context.aggregation); + + envManifest.explainer && (context.explain = explain()); + await exhaust(aggregatedTree, context, outputOptions); } catch (error) { if (error instanceof Error) { From b20c3bd093c1b103eb014a842e386e1989b6f28f Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 18 Jul 2024 18:04:50 +0400 Subject: [PATCH 13/35] fix(package): update if-core version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f01b0fb13..57230e0e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.10", + "@grnsft/if-core": "^0.0.12", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1185,9 +1185,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.10.tgz", - "integrity": "sha512-WHCdr7H/dFO9gT5fbjrthjOU+4RoLZ5P1F84pbGwJiKLmcU7dvYRuNQKDVIQQ7YJfZl76KSaS7sYgqA+QG8Wpw==", + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.12.tgz", + "integrity": "sha512-wBn/mC/I7UPvzTVlhgr+ODEa6upYc9lUONqNiPXcn/6s8wXHUx0tHsxjwz6rpp3wUEnRxTMbcy0jV7+tjoK00Q==", "dependencies": { "typescript": "^5.1.6" }, diff --git a/package.json b/package.json index 7c80610c5..3a0f5af32 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.10", + "@grnsft/if-core": "^0.0.12", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 5a7847687601c86358f646b3e5706ad1655a2c70 Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 18 Jul 2024 18:05:52 +0400 Subject: [PATCH 14/35] test(builtins): update rege test --- src/__tests__/if-run/builtins/regex.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/if-run/builtins/regex.test.ts b/src/__tests__/if-run/builtins/regex.test.ts index 795bbd36d..ea45c49d1 100644 --- a/src/__tests__/if-run/builtins/regex.test.ts +++ b/src/__tests__/if-run/builtins/regex.test.ts @@ -59,7 +59,7 @@ describe('builtins/regex: ', () => { match: '/(?<=_)[^_]+?(?=_|$)/g', output: 'cloud/instance-type', }; - const regex = Regex(globalConfig); + const regex = Regex(globalConfig, parametersMetadata); const expectedResult = [ { From ae7ad734f6b2f6ad145e7c24295ef540c48af081 Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 18 Jul 2024 18:16:38 +0400 Subject: [PATCH 15/35] fix(src): rename `MissingPluginDependenciesError` custom error --- src/if-env/util/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/if-env/util/helpers.ts b/src/if-env/util/helpers.ts index 17827f58a..e8ff24914 100644 --- a/src/if-env/util/helpers.ts +++ b/src/if-env/util/helpers.ts @@ -16,7 +16,7 @@ import {STRINGS} from '../config'; import {EnvironmentOptions} from '../types/if-env'; -const {MissingPluginDependenciesError} = ERRORS; +const {MissingManifestDependenciesError} = ERRORS; const { FAILURE_MESSAGE_DEPENDENCIES, FAILURE_MESSAGE, @@ -38,7 +38,7 @@ export const getOptionsFromArgs = async (commandArgs: { const dependencies = rawManifest?.execution?.environment.dependencies || []; if (!dependencies.length) { - throw new MissingPluginDependenciesError(FAILURE_MESSAGE_DEPENDENCIES); + throw new MissingManifestDependenciesError(FAILURE_MESSAGE_DEPENDENCIES); } const pathsWithVersion = extractPathsWithVersion(plugins, dependencies); From 2b5a591a43d520f5a58fff1caa8333c0ec7712d3 Mon Sep 17 00:00:00 2001 From: Manushak Keramyan Date: Mon, 22 Jul 2024 13:13:01 +0400 Subject: [PATCH 16/35] Update src/if-run/builtins/multiply/README.md Co-authored-by: Narek Hovhannisyan Signed-off-by: Manushak Keramyan --- src/if-run/builtins/multiply/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 08ebe9526..0514ce0fd 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -54,7 +54,7 @@ const config = { outputParameter: 'energy-product', }; -const mult = Multiply(config, parametersMetadata); +const multiply = Multiply(config, parametersMetadata); const result = await mult.execute([ { duration: 3600, From 9ed8e1aad5916d5cf6a37c3a9eefd7e146c600e8 Mon Sep 17 00:00:00 2001 From: Manushak Keramyan Date: Mon, 22 Jul 2024 13:13:18 +0400 Subject: [PATCH 17/35] Update src/if-run/builtins/multiply/README.md Co-authored-by: Narek Hovhannisyan Signed-off-by: Manushak Keramyan --- src/if-run/builtins/multiply/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 0514ce0fd..6acbb847a 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -55,7 +55,7 @@ const config = { }; const multiply = Multiply(config, parametersMetadata); -const result = await mult.execute([ +const result = await multiply.execute([ { duration: 3600, timestamp: '2021-01-01T00:00:00Z', From 2bf8e47775c918634072e26efe7af0b23c4fac7e Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:13:07 +0400 Subject: [PATCH 18/35] feat(package): update if-core version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 57230e0e6..78e1a23a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.12", + "@grnsft/if-core": "^0.0.13", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1185,9 +1185,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.12", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.12.tgz", - "integrity": "sha512-wBn/mC/I7UPvzTVlhgr+ODEa6upYc9lUONqNiPXcn/6s8wXHUx0tHsxjwz6rpp3wUEnRxTMbcy0jV7+tjoK00Q==", + "version": "0.0.13", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.13.tgz", + "integrity": "sha512-FSNzs0jL7sFaT8ZaaTS4yRl0IRBorVOgMQ7mVcQKZc9+uONosrudvWLPoDTZfxEQ5ZyFsJe6yEt2O1E53XagqQ==", "dependencies": { "typescript": "^5.1.6" }, diff --git a/package.json b/package.json index 3a0f5af32..ec8f48aed 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.12", + "@grnsft/if-core": "^0.0.13", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From fdced82dcd02c3c90272b6544d18edc0ebeb1aee Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:14:45 +0400 Subject: [PATCH 19/35] feat(util): add `aggregationMethod` into manifest schema --- src/common/util/validations.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/util/validations.ts b/src/common/util/validations.ts index 98d017c29..39de2de1c 100644 --- a/src/common/util/validations.ts +++ b/src/common/util/validations.ts @@ -64,6 +64,7 @@ export const manifestSchema = z.object({ z.object({ unit: z.string(), description: z.string(), + aggregationMethod: z.string(), }) ) .optional() @@ -74,6 +75,7 @@ export const manifestSchema = z.object({ z.object({ unit: z.string(), description: z.string(), + aggregationMethod: z.string(), }) ) .optional() From dfcd5ea3c16a3ccc4b9813d1c5fad398e049e618 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:16:54 +0400 Subject: [PATCH 20/35] feat(builtins): add `aggregationMethod` into plugins --- src/if-run/builtins/coefficient/index.ts | 2 ++ src/if-run/builtins/csv-lookup/index.ts | 13 +++++++++++-- .../builtins/mock-observations/index.ts | 8 +++++++- src/if-run/builtins/sci-embodied/index.ts | 6 ++++++ src/if-run/builtins/sci/index.ts | 3 +++ src/if-run/builtins/shell/index.ts | 14 ++++++++++++-- src/if-run/builtins/time-sync.ts | 19 ++++++++++++++++++- 7 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/if-run/builtins/coefficient/index.ts b/src/if-run/builtins/coefficient/index.ts index b6c743170..f04a2ab74 100644 --- a/src/if-run/builtins/coefficient/index.ts +++ b/src/if-run/builtins/coefficient/index.ts @@ -24,12 +24,14 @@ export const Coefficient = ( carbon: { description: 'an amount of carbon emitted into the atmosphere', unit: 'gCO2e', + aggregationMethod: 'sum', }, }, outputs: parametersMetadata?.outputs || { 'carbon-product': { description: 'a product of cabon property and the coefficient', unit: 'gCO2e', + aggregationMethod: 'sum', }, }, }; diff --git a/src/if-run/builtins/csv-lookup/index.ts b/src/if-run/builtins/csv-lookup/index.ts index 91e1739b3..e227eaadf 100644 --- a/src/if-run/builtins/csv-lookup/index.ts +++ b/src/if-run/builtins/csv-lookup/index.ts @@ -5,7 +5,11 @@ import axios from 'axios'; import {z} from 'zod'; import {parse} from 'csv-parse/sync'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParametersMetadata, + PluginParams, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -28,9 +32,14 @@ const { CSVParseError, } = ERRORS; -export const CSVLookup = (globalConfig: any): ExecutePlugin => { +export const CSVLookup = ( + globalConfig: any, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/mock-observations/index.ts b/src/if-run/builtins/mock-observations/index.ts index ab090d7c8..facc78353 100644 --- a/src/if-run/builtins/mock-observations/index.ts +++ b/src/if-run/builtins/mock-observations/index.ts @@ -5,6 +5,7 @@ import { PluginParams, ConfigParams, ObservationParams, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; @@ -14,9 +15,14 @@ import {RandIntGenerator} from './helpers/rand-int-generator'; import {Generator} from './interfaces/index'; -export const MockObservations = (globalConfig: ConfigParams): ExecutePlugin => { +export const MockObservations = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/sci-embodied/index.ts b/src/if-run/builtins/sci-embodied/index.ts index e2a60edd6..6bd7fd1b8 100644 --- a/src/if-run/builtins/sci-embodied/index.ts +++ b/src/if-run/builtins/sci-embodied/index.ts @@ -20,14 +20,17 @@ export const SciEmbodied = ( 'device/emissions-embodied': { description: 'total embodied emissions of some component', unit: 'gCO2e', + aggregationMethod: 'sum', }, 'device/expected-lifespan': { description: 'Total Expected Lifespan of the Component in Seconds', unit: 'seconds', + aggregationMethod: 'sum', }, 'resources-reserved': { description: 'resources reserved for an application', unit: 'count', + aggregationMethod: 'none', }, 'resources-total': { description: 'total resources available', @@ -36,16 +39,19 @@ export const SciEmbodied = ( 'vcpus-allocated': { description: 'number of vcpus allocated to particular resource', unit: 'count', + aggregationMethod: 'none', }, 'vcpus-total': { description: 'total number of vcpus available on a particular resource', unit: 'count', + aggregationMethod: 'none', }, }, outputs: parametersMetadata?.outputs || { 'carbon-embodied': { description: 'embodied emissions of the component', unit: 'gCO2e', + aggregationMethod: 'sum', }, }, }; diff --git a/src/if-run/builtins/sci/index.ts b/src/if-run/builtins/sci/index.ts index 90cf55fb7..ac566fdb9 100644 --- a/src/if-run/builtins/sci/index.ts +++ b/src/if-run/builtins/sci/index.ts @@ -29,17 +29,20 @@ export const Sci = ( carbon: { description: 'an amount of carbon emitted into the atmosphere', unit: 'gCO2e', + aggregationMethod: 'sum', }, 'functional-unit': { description: 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', unit: 'none', + aggregationMethod: 'sum', }, }, outputs: parametersMetadata?.outputs || { sci: { description: 'carbon expressed in terms of the given functional unit', unit: 'gCO2e', + aggregationMethod: 'sum', }, }, }; diff --git a/src/if-run/builtins/shell/index.ts b/src/if-run/builtins/shell/index.ts index 5fbea5f28..9abe8363c 100644 --- a/src/if-run/builtins/shell/index.ts +++ b/src/if-run/builtins/shell/index.ts @@ -3,15 +3,25 @@ import {spawnSync, SpawnSyncReturns} from 'child_process'; import {loadAll, dump} from 'js-yaml'; import {z} from 'zod'; import {ERRORS} from '@grnsft/if-core/utils'; -import {ExecutePlugin, PluginParams, ConfigParams} from '@grnsft/if-core/types'; +import { + ExecutePlugin, + PluginParams, + ConfigParams, + PluginParametersMetadata, +} from '@grnsft/if-core/types'; import {validate} from '../../../common/util/validations'; const {ProcessExecutionError} = ERRORS; -export const Shell = (globalConfig: ConfigParams): ExecutePlugin => { +export const Shell = ( + globalConfig: ConfigParams, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs, + outputs: parametersMetadata?.outputs, }; /** diff --git a/src/if-run/builtins/time-sync.ts b/src/if-run/builtins/time-sync.ts index 9c14b63a4..ae5a91a87 100644 --- a/src/if-run/builtins/time-sync.ts +++ b/src/if-run/builtins/time-sync.ts @@ -9,6 +9,7 @@ import { PaddingReceipt, TimeNormalizerConfig, TimeParams, + PluginParametersMetadata, } from '@grnsft/if-core/types'; import {validate} from '../../common/util/validations'; @@ -35,9 +36,25 @@ const { INVALID_DATETIME, } = STRINGS; -export const TimeSync = (globalConfig: TimeNormalizerConfig): ExecutePlugin => { +export const TimeSync = ( + globalConfig: TimeNormalizerConfig, + parametersMetadata: PluginParametersMetadata +): ExecutePlugin => { const metadata = { kind: 'execute', + inputs: parametersMetadata?.inputs || { + timestamp: { + description: 'refers to the time of occurrence of the input', + unit: 'RFC3339', + aggregationMethod: 'none', + }, + duration: { + description: 'refers to the duration of the input', + unit: 'seconds', + aggregationMethod: 'sum', + }, + }, + outputs: parametersMetadata?.outputs, }; /** From 90f861faf03d4857ade586b098602c6123ba7238 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:18:35 +0400 Subject: [PATCH 21/35] test(builtins): update test according to changes --- .../if-run/builtins/csv-lookup.test.ts | 32 ++-- .../if-run/builtins/mock-observations.test.ts | 137 ++++++++++-------- src/__tests__/if-run/builtins/shell.test.ts | 16 +- .../if-run/builtins/time-sync.test.ts | 57 +++++--- src/__tests__/if-run/lib/aggregate.test.ts | 7 +- .../if-run/util/aggregation-helper.test.ts | 6 +- 6 files changed, 150 insertions(+), 105 deletions(-) diff --git a/src/__tests__/if-run/builtins/csv-lookup.test.ts b/src/__tests__/if-run/builtins/csv-lookup.test.ts index b89c7572e..49e4d45bb 100644 --- a/src/__tests__/if-run/builtins/csv-lookup.test.ts +++ b/src/__tests__/if-run/builtins/csv-lookup.test.ts @@ -19,6 +19,10 @@ const { const {MISSING_GLOBAL_CONFIG, MISSING_CSV_COLUMN, NO_QUERY_DATA} = STRINGS; describe('builtins/CSVLookup: ', () => { + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; const mock = new AxiosMockAdapter(axios); describe('CSVLookup: ', () => { @@ -35,7 +39,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); expect(csvLookup).toHaveProperty('metadata'); expect(csvLookup).toHaveProperty('execute'); }); @@ -54,7 +58,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const responseData = `cpu-cores-available,cpu-cores-utilized,cpu-manufacturer,cpu-model-name,cpu-tdp,gpu-count,gpu-model-name,Hardware Information on AWS Documentation & Comments,instance-class,instance-storage,memory-available,platform-memory,release-date,storage-drives 16,8,AWS,AWS Graviton,150.00,N/A,N/A,AWS Graviton (ARM),a1.2xlarge,EBS-Only,16,32,November 2018,0 @@ -93,7 +97,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -126,7 +130,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const input = [ { timestamp: '2024-03-01', @@ -155,7 +159,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const input = [ { timestamp: '2024-03-01', @@ -187,7 +191,7 @@ describe('builtins/CSVLookup: ', () => { }; mock.onGet(globalConfig.filepath).reply(404); - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const input = [ { timestamp: '2024-03-01', @@ -217,7 +221,7 @@ describe('builtins/CSVLookup: ', () => { }, output: '*', }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -265,7 +269,7 @@ describe('builtins/CSVLookup: ', () => { ['gpu-model-name', 'gpumodel'], ], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -300,7 +304,7 @@ describe('builtins/CSVLookup: ', () => { }, output: 'gpu-count', }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -335,7 +339,7 @@ describe('builtins/CSVLookup: ', () => { output: ['cpu-tdp', 'tdp'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const input = [ { timestamp: '2024-03-01', @@ -392,7 +396,7 @@ describe('builtins/CSVLookup: ', () => { }, output: 'mock', }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const input = [ { timestamp: '2024-03-01', @@ -425,7 +429,7 @@ describe('builtins/CSVLookup: ', () => { }, output: ['gpu-count'], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -459,7 +463,7 @@ describe('builtins/CSVLookup: ', () => { }, output: [['gpu-count']], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); const result = await csvLookup.execute([ { @@ -495,7 +499,7 @@ describe('builtins/CSVLookup: ', () => { }, output: [['gpu-count']], }; - const csvLookup = CSVLookup(globalConfig); + const csvLookup = CSVLookup(globalConfig, parametersMetadata); try { await csvLookup.execute([ diff --git a/src/__tests__/if-run/builtins/mock-observations.test.ts b/src/__tests__/if-run/builtins/mock-observations.test.ts index 6b0fb22bd..0569b4c93 100644 --- a/src/__tests__/if-run/builtins/mock-observations.test.ts +++ b/src/__tests__/if-run/builtins/mock-observations.test.ts @@ -8,24 +8,32 @@ const {InputValidationError, GlobalConfigError} = ERRORS; const {INVALID_MIN_MAX} = STRINGS; describe('builtins/mock-observations: ', () => { + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + describe('init: ', () => { it('successfully initalized.', () => { - const mockObservations = MockObservations({ - 'timestamp-from': '2023-07-06T00:00', - 'timestamp-to': '2023-07-06T00:01', - duration: 5, - components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], - generators: { - common: { - region: 'uk-west', - 'common-key': 'common-val', - }, - randint: { - 'cpu/utilization': {min: 10, max: 95}, - 'memory/utilization': {min: 10, max: 85}, + const mockObservations = MockObservations( + { + 'timestamp-from': '2023-07-06T00:00', + 'timestamp-to': '2023-07-06T00:01', + duration: 5, + components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], + generators: { + common: { + region: 'uk-west', + 'common-key': 'common-val', + }, + randint: { + 'cpu/utilization': {min: 10, max: 95}, + 'memory/utilization': {min: 10, max: 85}, + }, }, }, - }); + parametersMetadata + ); expect(mockObservations).toHaveProperty('metadata'); expect(mockObservations).toHaveProperty('execute'); @@ -49,7 +57,7 @@ describe('builtins/mock-observations: ', () => { }, }, }; - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); const result = await mockObservations.execute([]); expect.assertions(1); @@ -109,7 +117,7 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); try { await mockObservations.execute([]); } catch (error) { @@ -131,7 +139,7 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); try { - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); await mockObservations.execute([]); } catch (error) { expect(error).toBeInstanceOf(InputValidationError); @@ -165,7 +173,7 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); try { - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); await mockObservations.execute([]); } catch (error) { expect(error).toBeInstanceOf(InputValidationError); @@ -177,21 +185,24 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); try { - const mockObservations = MockObservations({ - 'timestamp-from': '2023-07-06T00:00', - 'timestamp-to': '2023-07-06T00:01', - components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], - generators: { - common: { - region: 'uk-west', - 'common-key': 'common-val', - }, - randint: { - 'cpu/utilization': {min: 10, max: 95}, - 'memory/utilization': {min: 10, max: 85}, + const mockObservations = MockObservations( + { + 'timestamp-from': '2023-07-06T00:00', + 'timestamp-to': '2023-07-06T00:01', + components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], + generators: { + common: { + region: 'uk-west', + 'common-key': 'common-val', + }, + randint: { + 'cpu/utilization': {min: 10, max: 95}, + 'memory/utilization': {min: 10, max: 85}, + }, }, }, - }); + parametersMetadata + ); await mockObservations.execute([]); } catch (error) { expect(error).toBeInstanceOf(InputValidationError); @@ -207,21 +218,25 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); try { - const mockObservations = MockObservations({ - 'timestamp-from': '2023-07-06T00:00', - duration: 5, - components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], - generators: { - common: { - region: 'uk-west', - 'common-key': 'common-val', - }, - randint: { - 'cpu/utilization': {min: 10, max: 95}, - 'memory/utilization': {min: 10, max: 85}, + const mockObservations = MockObservations( + { + 'timestamp-from': '2023-07-06T00:00', + duration: 5, + components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], + generators: { + common: { + region: 'uk-west', + 'common-key': 'common-val', + }, + randint: { + 'cpu/utilization': {min: 10, max: 95}, + 'memory/utilization': {min: 10, max: 85}, + }, }, }, - }); + parametersMetadata + ); + await mockObservations.execute([]); } catch (error) { expect(error).toBeInstanceOf(InputValidationError); @@ -237,21 +252,25 @@ describe('builtins/mock-observations: ', () => { expect.assertions(2); try { - const mockObservations = MockObservations({ - 'timestamp-to': '2023-07-06T00:01', - duration: 5, - components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], - generators: { - common: { - region: 'uk-west', - 'common-key': 'common-val', - }, - randint: { - 'cpu/utilization': {min: 10, max: 95}, - 'memory/utilization': {min: 10, max: 85}, + const mockObservations = MockObservations( + { + 'timestamp-to': '2023-07-06T00:01', + duration: 5, + components: [{'instance-type': 'A1'}, {'instance-type': 'B1'}], + generators: { + common: { + region: 'uk-west', + 'common-key': 'common-val', + }, + randint: { + 'cpu/utilization': {min: 10, max: 95}, + 'memory/utilization': {min: 10, max: 85}, + }, }, }, - }); + parametersMetadata + ); + await mockObservations.execute([]); } catch (error) { expect(error).toBeInstanceOf(InputValidationError); @@ -277,7 +296,7 @@ describe('builtins/mock-observations: ', () => { randint: null, }, }; - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); expect.assertions(2); @@ -307,7 +326,7 @@ describe('builtins/mock-observations: ', () => { }, }, }; - const mockObservations = MockObservations(config); + const mockObservations = MockObservations(config, parametersMetadata); expect.assertions(2); diff --git a/src/__tests__/if-run/builtins/shell.test.ts b/src/__tests__/if-run/builtins/shell.test.ts index 379863052..20b6a7e1c 100644 --- a/src/__tests__/if-run/builtins/shell.test.ts +++ b/src/__tests__/if-run/builtins/shell.test.ts @@ -10,8 +10,12 @@ jest.mock('child_process'); jest.mock('js-yaml'); describe('builtins/shell', () => { + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; describe('Shell', () => { - const shell = Shell({}); + const shell = Shell({}, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -22,7 +26,10 @@ describe('builtins/shell', () => { describe('execute(): ', () => { it('execute with valid inputs and command', async () => { - const shell = Shell({command: 'python3 /path/to/script.py'}); + const shell = Shell( + {command: 'python3 /path/to/script.py'}, + parametersMetadata + ); const mockSpawnSync = spawnSync as jest.MockedFunction< typeof spawnSync >; @@ -70,7 +77,10 @@ describe('builtins/shell', () => { }); it('throw an error when shell could not run command.', async () => { - const shell = Shell({command: 'python3 /path/to/script.py'}); + const shell = Shell( + {command: 'python3 /path/to/script.py'}, + parametersMetadata + ); (spawnSync as jest.Mock).mockImplementation(() => { throw new InputValidationError('Could not run the command'); }); diff --git a/src/__tests__/if-run/builtins/time-sync.test.ts b/src/__tests__/if-run/builtins/time-sync.test.ts index e216690df..322971711 100644 --- a/src/__tests__/if-run/builtins/time-sync.test.ts +++ b/src/__tests__/if-run/builtins/time-sync.test.ts @@ -3,7 +3,7 @@ import {Settings, DateTime} from 'luxon'; import {AggregationParams} from '../../../common/types/manifest'; -import {storeAggregateMetrics} from '../../../if-run/lib/aggregate'; +import {storeAggregationMetrics} from '../../../if-run/lib/aggregate'; import {TimeSync} from '../../../if-run/builtins/time-sync'; import {STRINGS} from '../../../if-run/config'; @@ -65,10 +65,14 @@ describe('builtins/time-sync:', () => { type: 'horizontal', }; - storeAggregateMetrics(metricStorage); + storeAggregationMetrics(metricStorage); }); describe('time-sync: ', () => { + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; const basicConfig = { 'start-time': '2023-12-12T00:01:00.000Z', 'end-time': '2023-12-12T00:01:00.000Z', @@ -76,7 +80,7 @@ describe('builtins/time-sync:', () => { 'allow-padding': true, }; - const timeSync = TimeSync(basicConfig); + const timeSync = TimeSync(basicConfig, parametersMetadata); describe('init: ', () => { it('successfully initalized.', () => { @@ -88,6 +92,11 @@ describe('builtins/time-sync:', () => { }); describe('execute(): ', () => { + const parametersMetadata = { + inputs: {}, + outputs: {}, + }; + it('throws error if `start-time` is missing.', async () => { const invalidStartTimeConfig = { 'start-time': '', @@ -96,7 +105,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(invalidStartTimeConfig); + const timeModel = TimeSync(invalidStartTimeConfig, parametersMetadata); expect.assertions(1); @@ -131,7 +140,7 @@ describe('execute(): ', () => { interval: 5, 'allow-padding': true, }; - const timeModel = TimeSync(invalidEndTimeConfig); + const timeModel = TimeSync(invalidEndTimeConfig, parametersMetadata); expect.assertions(1); @@ -160,7 +169,7 @@ describe('execute(): ', () => { interval: 5, 'allow-padding': true, }; - const timeModel = TimeSync(invalidStartTimeConfig); + const timeModel = TimeSync(invalidStartTimeConfig, parametersMetadata); expect.assertions(1); try { await timeModel.execute([ @@ -186,7 +195,7 @@ describe('execute(): ', () => { interval: 5, 'allow-padding': true, }; - const timeModel = TimeSync(invalidEndTimeConfig); + const timeModel = TimeSync(invalidEndTimeConfig, parametersMetadata); expect.assertions(1); try { @@ -208,7 +217,7 @@ describe('execute(): ', () => { it('throws error on missing global config.', async () => { const config = undefined; - const timeModel = TimeSync(config!); + const timeModel = TimeSync(config!, parametersMetadata); expect.assertions(1); @@ -240,7 +249,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(invalidIntervalConfig); + const timeModel = TimeSync(invalidIntervalConfig, parametersMetadata); expect.assertions(1); @@ -272,7 +281,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -302,7 +311,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -334,7 +343,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -374,7 +383,7 @@ describe('execute(): ', () => { }, ]; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); expect.assertions(2); try { @@ -395,7 +404,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -425,7 +434,7 @@ describe('execute(): ', () => { 'allow-padding': false, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { @@ -464,7 +473,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { @@ -538,7 +547,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { @@ -578,7 +587,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { @@ -622,7 +631,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -651,7 +660,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { @@ -690,7 +699,7 @@ describe('execute(): ', () => { 'allow-padding': false, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -720,7 +729,7 @@ describe('execute(): ', () => { 'allow-padding': false, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -750,7 +759,7 @@ describe('execute(): ', () => { 'allow-padding': false, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); try { await timeModel.execute([ @@ -781,7 +790,7 @@ describe('execute(): ', () => { 'allow-padding': true, }; - const timeModel = TimeSync(basicConfig); + const timeModel = TimeSync(basicConfig, parametersMetadata); const result = await timeModel.execute([ { timestamp: '2023-12-12T00:00:00.000Z', diff --git a/src/__tests__/if-run/lib/aggregate.test.ts b/src/__tests__/if-run/lib/aggregate.test.ts index 56488eea2..36bbc0d1f 100644 --- a/src/__tests__/if-run/lib/aggregate.test.ts +++ b/src/__tests__/if-run/lib/aggregate.test.ts @@ -2,7 +2,10 @@ import {AggregationParams} from '../../../common/types/manifest'; -import {aggregate, storeAggregateMetrics} from '../../../if-run/lib/aggregate'; +import { + aggregate, + storeAggregationMetrics, +} from '../../../if-run/lib/aggregate'; describe('lib/aggregate: ', () => { beforeAll(() => { @@ -13,7 +16,7 @@ describe('lib/aggregate: ', () => { type: 'horizontal', }; - storeAggregateMetrics(metricStorage); + storeAggregationMetrics(metricStorage); }); describe('aggregate(): ', () => { diff --git a/src/__tests__/if-run/util/aggregation-helper.test.ts b/src/__tests__/if-run/util/aggregation-helper.test.ts index 5f8bc3325..df8a74d9b 100644 --- a/src/__tests__/if-run/util/aggregation-helper.test.ts +++ b/src/__tests__/if-run/util/aggregation-helper.test.ts @@ -5,7 +5,7 @@ import {AggregationParams} from '../../../common/types/manifest'; import {aggregateInputsIntoOne} from '../../../if-run/util/aggregation-helper'; import {AggregationMetric} from '../../../if-run/types/aggregation'; -import {storeAggregateMetrics} from '../../../if-run/lib/aggregate'; +import {storeAggregationMetrics} from '../../../if-run/lib/aggregate'; import {STRINGS} from '../../../if-run/config'; @@ -23,7 +23,7 @@ describe('util/aggregation-helper: ', () => { type: 'horizontal', }; - storeAggregateMetrics(metricStorage); + storeAggregationMetrics(metricStorage); }); describe('aggregateInputsIntoOne(): ', () => { @@ -105,7 +105,7 @@ describe('util/aggregation-helper: ', () => { type: 'horizontal', }; - storeAggregateMetrics(metricStorage); + storeAggregationMetrics(metricStorage); const inputs: PluginParams[] = [ {timestamp: '', duration: 10, 'cpu/utilization': 10}, {timestamp: '', duration: 10, 'cpu/utilization': 90}, From 192f261628c1c035e7704b2a099617064af29ed0 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:20:59 +0400 Subject: [PATCH 22/35] feat(src): add `AggregationParamsWithoutType` type and update `storeAggregationMetrics` function --- src/common/types/manifest.ts | 5 +++++ src/if-run/lib/aggregate.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/common/types/manifest.ts b/src/common/types/manifest.ts index 1b003be2c..c28fe7194 100644 --- a/src/common/types/manifest.ts +++ b/src/common/types/manifest.ts @@ -9,6 +9,11 @@ export type GlobalPlugins = Manifest['initialize']['plugins']; export type PluginOptions = GlobalPlugins[string]; export type AggregationParams = Manifest['aggregation']; +export type AggregationParamsWithoutType = Omit< + Exclude, + 'type' +>; + export type AggregationParamsSure = Extract; export type Context = Omit; diff --git a/src/if-run/lib/aggregate.ts b/src/if-run/lib/aggregate.ts index a3d2d2bad..508117bb3 100644 --- a/src/if-run/lib/aggregate.ts +++ b/src/if-run/lib/aggregate.ts @@ -5,6 +5,7 @@ import {logger} from '../../common/util/logger'; import { AggregationParams, AggregationParamsSure, + AggregationParamsWithoutType, } from '../../common/types/manifest'; import {aggregateInputsIntoOne} from '../util/aggregation-helper'; @@ -105,13 +106,15 @@ export const aggregate = (tree: any, aggregationParams: AggregationParams) => { /** * Gets or stores aggregation metrics. - * @todo Remove these functions after resolving timeSync to be a builtin functionality. */ -export const storeAggregateMetrics = ( - aggregationParams?: AggregationParams +export const storeAggregationMetrics = ( + aggregationParams?: AggregationParamsWithoutType ) => { if (aggregationParams?.metrics) { - metricManager.metrics = aggregationParams?.metrics; + metricManager.metrics = { + ...metricManager.metrics, + ...aggregationParams?.metrics, + }; } return metricManager.metrics; @@ -141,7 +144,7 @@ const metricManager = (() => { export const getAggregationMethod = (unitName: string) => { debugLogger.setExecutingPluginName(); memoizedLog(console.debug, CHECKING_AGGREGATION_METHOD(unitName)); - const aggregationMetricsStorage = storeAggregateMetrics(); + const aggregationMetricsStorage = storeAggregationMetrics(); if (aggregationMetricsStorage && `${unitName}` in aggregationMetricsStorage) { return aggregationMetricsStorage[unitName].method; From d16ba4e9e340b48df4fcc9027ee42429feb6d61c Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:22:13 +0400 Subject: [PATCH 23/35] feat(util): add `storeAggregationMethods` functionality --- src/if-run/util/helpers.ts | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/if-run/util/helpers.ts b/src/if-run/util/helpers.ts index 978ef128f..5870181e9 100644 --- a/src/if-run/util/helpers.ts +++ b/src/if-run/util/helpers.ts @@ -1,8 +1,11 @@ import {ERRORS} from '@grnsft/if-core/utils'; -import {STRINGS} from '../config'; - import {logger} from '../../common/util/logger'; +import {GlobalPlugins} from '../../common/types/manifest'; +import {PluginStorageInterface} from '../types/plugin-storage'; +import {storeAggregationMetrics} from '../lib/aggregate'; + +import {STRINGS} from '../config'; const {UNSUPPORTED_ERROR} = STRINGS; @@ -39,3 +42,33 @@ export const mergeObjects = (defaults: any, input: any) => { return merged; }; + +/** + * Stores `aggregationMethod` of the plugins in the pipeline. + */ +export const storeAggregationMethods = ( + plugins: GlobalPlugins, + pluginStorage: PluginStorageInterface +) => { + Object.keys(plugins).forEach(pluginName => { + const plugin = pluginStorage.get(pluginName); + + if ('inputs' in plugin.metadata || 'outputs' in plugin.metadata) { + const pluginParameters = + {...plugin.metadata.inputs, ...plugin.metadata.outputs} || {}; + + Object.entries(pluginParameters).forEach( + ([parameterName, parameterMetadata]) => { + const {aggregationMethod} = parameterMetadata; + + if (aggregationMethod) { + const metrics = { + [parameterName]: {method: aggregationMethod}, + }; + storeAggregationMetrics({metrics}); + } + } + ); + } + }); +}; From 3836eb9f2e273e84fa94be3e8912386c143a6b6c Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:25:01 +0400 Subject: [PATCH 24/35] test(util): add tests for `storeAggregationMethods` function --- src/__tests__/if-run/util/helpers.test.ts | 111 +++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/src/__tests__/if-run/util/helpers.test.ts b/src/__tests__/if-run/util/helpers.test.ts index 35b60a01b..742990486 100644 --- a/src/__tests__/if-run/util/helpers.test.ts +++ b/src/__tests__/if-run/util/helpers.test.ts @@ -3,7 +3,15 @@ const mockError = jest.fn(); import {ERRORS} from '@grnsft/if-core/utils'; -import {andHandle, mergeObjects} from '../../../if-run/util/helpers'; +import {GlobalPlugins} from '../../../common/types/manifest'; + +import {storeAggregationMetrics} from '../../../if-run/lib/aggregate'; + +import { + andHandle, + mergeObjects, + storeAggregationMethods, +} from '../../../if-run/util/helpers'; const {WriteFileError} = ERRORS; @@ -14,6 +22,10 @@ jest.mock('../../../common/util/logger', () => ({ }, })); +jest.mock('../../../if-run/lib/aggregate', () => ({ + storeAggregationMetrics: jest.fn(), +})); + describe('if-run/util/helpers: ', () => { describe('andHandle(): ', () => { afterEach(() => { @@ -166,4 +178,101 @@ describe('if-run/util/helpers: ', () => { expect(result).toEqual(expectedResult); }); }); + + describe('storeAggregationMethods(): ', () => { + const mockPluginStorage = { + get: jest.fn(), + set: jest.fn((_name, _plugin) => {}), + }; + + const mockPlugins: GlobalPlugins = { + multiply: { + path: 'builtin', + method: 'Multiply', + }, + sci: { + path: 'builtin', + method: 'Sci', + }, + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('succefully executes with correct metrics.', () => { + const mockPlugin1 = { + execute: () => [{}], + metadata: { + kind: 'execute', + inputs: { + carbon: { + description: 'mock description', + unit: 'none', + aggregationMethod: 'sum', + }, + }, + outputs: { + cpu: { + description: 'mock description', + unit: 'none', + aggregationMethod: 'avg', + }, + }, + }, + }; + + const mockPlugin2 = { + metadata: { + inputs: {}, + outputs: { + carbon: {aggregationMethod: 'none'}, + }, + }, + }; + + mockPluginStorage.get + .mockReturnValueOnce(mockPlugin1) + .mockReturnValueOnce(mockPlugin2); + + // @ts-ignore + storeAggregationMethods(mockPlugins, mockPluginStorage); + + expect(storeAggregationMetrics).toHaveBeenCalledTimes(3); + expect(storeAggregationMetrics).toHaveBeenNthCalledWith(1, { + metrics: { + carbon: {method: 'sum'}, + }, + }); + expect(storeAggregationMetrics).toHaveBeenNthCalledWith(2, { + metrics: { + cpu: {method: 'avg'}, + }, + }); + expect(storeAggregationMetrics).toHaveBeenNthCalledWith(3, { + metrics: { + carbon: {method: 'none'}, + }, + }); + }); + + it('does not execute if there are no inputs or outputs.', () => { + mockPluginStorage.get.mockReturnValueOnce({ + execute: () => [{}], + metadata: {}, + }); + + const mockPlugin = { + execute: () => [{}], + metadata: { + kind: 'execute', + }, + }; + + mockPluginStorage.get.mockReturnValueOnce(mockPlugin); + // @ts-ignore + storeAggregationMethods(mockPlugins, mockPluginStorage); + expect(storeAggregationMetrics).not.toHaveBeenCalled(); + }); + }); }); From 4b20ff05bc19bd7d62414cb12217f1accbaacd09 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:30:39 +0400 Subject: [PATCH 25/35] feat(src): call `storeAggregationMethods` function from impactEngine --- src/if-run/index.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/if-run/index.ts b/src/if-run/index.ts index 5ffb62ded..eb0daeb24 100644 --- a/src/if-run/index.ts +++ b/src/if-run/index.ts @@ -1,19 +1,20 @@ #!/usr/bin/env node -import {aggregate, storeAggregateMetrics} from './lib/aggregate'; -import {compute} from './lib/compute'; +import {STRINGS as COMMON_STRINGS} from '../common/config'; +import {validateManifest} from '../common/util/validations'; +import {debugLogger} from '../common/util/debug-logger'; +import {logger} from '../common/util/logger'; +import {load} from '../common/lib/load'; + +import {aggregate, storeAggregationMetrics} from './lib/aggregate'; import {injectEnvironment} from './lib/environment'; -import {exhaust} from './lib/exhaust'; import {initialize} from './lib/initialize'; -import {load} from '../common/lib/load'; +import {compute} from './lib/compute'; +import {exhaust} from './lib/exhaust'; import {parseIfRunProcessArgs} from './util/args'; -import {andHandle} from './util/helpers'; -import {logger} from '../common/util/logger'; -import {validateManifest} from '../common/util/validations'; -import {debugLogger} from '../common/util/debug-logger'; +import {andHandle, storeAggregationMethods} from './util/helpers'; import {STRINGS} from './config'; -import {STRINGS as COMMON_STRINGS} from '../common/config'; const {EXITING_IF, STARTING_IF} = STRINGS; const {DISCLAIMER_MESSAGE} = COMMON_STRINGS; @@ -32,11 +33,14 @@ const impactEngine = async () => { try { const {tree, ...context} = validateManifest(envManifest); + const pluginStorage = await initialize(context.initialize.plugins); + + if (context.aggregation) { + storeAggregationMetrics({metrics: context.aggregation?.metrics}); + } - // TODO: remove this after resolving timeSync to be a builtin functionality. - storeAggregateMetrics(context.aggregation); + storeAggregationMethods(context.initialize.plugins, pluginStorage); - const pluginStorage = await initialize(context.initialize.plugins); const computedTree = await compute(tree, {context, pluginStorage}); const aggregatedTree = aggregate(computedTree, context.aggregation); await exhaust(aggregatedTree, context, outputOptions); From 24d6474ad723f4970b1b578041d28c4251d1f772 Mon Sep 17 00:00:00 2001 From: manushak Date: Tue, 23 Jul 2024 20:32:39 +0400 Subject: [PATCH 26/35] fix(manifests): update manifests with time-sync and mock-observations --- .../pipelines/pipeline-with-mocks.yml | 75 ++++++++++++++++++- .../outputs/pipelines/mock-obs-time-sync.yaml | 47 +++++++++++- 2 files changed, 115 insertions(+), 7 deletions(-) diff --git a/manifests/examples/pipelines/pipeline-with-mocks.yml b/manifests/examples/pipelines/pipeline-with-mocks.yml index 9e4292f51..fa681a918 100644 --- a/manifests/examples/pipelines/pipeline-with-mocks.yml +++ b/manifests/examples/pipelines/pipeline-with-mocks.yml @@ -13,19 +13,36 @@ initialize: method: MockObservations path: "builtin" global-config: - timestamp-from: 2023-07-06T00:00 - timestamp-to: 2023-07-06T00:10 + timestamp-from: 2023-12-12T00:00 + timestamp-to: 2023-12-12T00:10 duration: 60 components: - cloud/instance-type: A1 generators: common: cloud/region: uk-west - common-key: common-val randint: cpu/utilization: min: 1 max: 99 + parameter-metadata: + inputs: + timestamp: + description: refers to the time of occurrence of the input + unit: RFC3339 + aggregationMethod: none + duration: + description: refers to the duration of the input + unit: seconds + aggregationMethod: sum + cloud/instance-type: + description: type of Cloud Instance name used in the cloud provider APIs + unit: none + aggregationMethod: none + cloud/region: + description: region cloud instance + unit: none + aggregationMethod: none "interpolate": method: Interpolation path: "builtin" @@ -35,12 +52,34 @@ initialize: y: [0.12, 0.32, 0.75, 1.02] input-parameter: "cpu/utilization" output-parameter: "cpu-factor" + parameter-metadata: + inputs: + cpu/utilization: + description: refers to CPU utilization. + unit: percentage + aggregationMethod: avg + outputs: + cpu-factor: + description: result of interpolate + unit: kWh + aggregationMethod: avg "cpu-factor-to-wattage": method: Multiply path: builtin global-config: input-parameters: ["cpu-factor", "cpu/thermal-design-power"] output-parameter: "cpu-wattage" + parameter-metadata: + inputs: + cpu/thermal-design-power: + description: thermal design power for a processor + unit: kwh + aggregationMethod: avg + outputs: + cpu-wattage: + description: the energy used by the CPU + unit: kwh + aggregationMethod: sum "wattage-times-duration": method: Multiply path: builtin @@ -61,6 +100,16 @@ initialize: numerator: vcpus-total denominator: vcpus-allocated output: vcpu-ratio + parameter-metadata: + inputs: + vcpus-total: + description: total number of vcpus available on a particular resource + unit: count + aggregationMethod: none + vcpus-allocated: + description: number of vcpus allocated to particular resource + unit: count + aggregationMethod: none "correct-cpu-energy-for-vcpu-ratio": method: Divide path: "builtin" @@ -77,6 +126,12 @@ initialize: global-config: input-parameters: ["cpu-energy-kwh", "grid/carbon-intensity"] output-parameter: "carbon-operational" + parameter-metadata: + inputs: + grid/carbon-intensity: + description: Carbon intensity for the grid + unit: gCO2eq/kWh + aggregationMethod: avg "sum-carbon": path: "builtin" method: Sum @@ -90,6 +145,12 @@ initialize: method: Sci global-config: functional-unit: "requests" + parameter-metadata: + inputs: + requests: + description: expressed the final SCI value + unit: none + aggregationMethod: sum "time-sync": method: TimeSync path: "builtin" @@ -98,6 +159,12 @@ initialize: end-time: "2023-12-12T00:01:00.000Z" interval: 5 allow-padding: true + parameter-metadata: + inputs: + time-reserved: + description: time reserved for a component + unit: seconds + aggregationMethod: avg "group-by": path: builtin method: GroupBy @@ -105,6 +172,7 @@ tree: children: child-1: pipeline: + - mock-observations - interpolate - cpu-factor-to-wattage - wattage-times-duration @@ -156,6 +224,7 @@ tree: requests: 50 child-2: pipeline: + - mock-observations - interpolate - cpu-factor-to-wattage - wattage-times-duration diff --git a/manifests/outputs/pipelines/mock-obs-time-sync.yaml b/manifests/outputs/pipelines/mock-obs-time-sync.yaml index c22a14c3e..11d8b6c34 100644 --- a/manifests/outputs/pipelines/mock-obs-time-sync.yaml +++ b/manifests/outputs/pipelines/mock-obs-time-sync.yaml @@ -7,19 +7,36 @@ initialize: path: builtin method: MockObservations global-config: - timestamp-from: 2023-07-06T00:00 - timestamp-to: 2023-07-06T00:10 + timestamp-from: 2023-12-12T00:00 + timestamp-to: 2023-12-12T00:10 duration: 60 components: - cloud/instance-type: A1 generators: common: cloud/region: uk-west - common-key: common-val randint: cpu/utilization: min: 1 max: 99 + parameter-metadata: + inputs: + timestamp: + description: refers to the time of occurrence of the input + unit: RFC3339 + aggregationMethod: none + duration: + description: refers to the duration of the input + unit: seconds + aggregationMethod: sum + cloud/instance-type: + description: type of Cloud Instance name used in the cloud provider APIs + unit: none + aggregationMethod: none + cloud/region: + description: region cloud instance + unit: none + aggregationMethod: none interpolate: path: builtin method: Interpolation @@ -37,6 +54,12 @@ initialize: - 1.02 input-parameter: cpu/utilization output-parameter: cpu-factor + parameter-metadata: + inputs: + cpu/utilization: + description: refers to CPU utilization. + unit: percentage + aggregationMethod: avg cpu-factor-to-wattage: path: builtin method: Multiply @@ -45,6 +68,12 @@ initialize: - cpu-factor - cpu/thermal-design-power output-parameter: cpu-wattage + parameter-metadata: + inputs: + cpu/thermal-design-power: + description: thermal design power for a processor + unit: kwh + aggregationMethod: avg wattage-times-duration: path: builtin method: Multiply @@ -67,6 +96,16 @@ initialize: numerator: vcpus-total denominator: vcpus-allocated output: vcpu-ratio + parameter-metadata: + inputs: + vcpus-total: + description: total number of vcpus available on a particular resource + unit: count + aggregationMethod: none + vcpus-allocated: + description: number of vcpus allocated to particular resource + unit: count + aggregationMethod: none correct-cpu-energy-for-vcpu-ratio: path: builtin method: Divide @@ -100,7 +139,6 @@ execution: - "@commitlint/cli@18.6.0" - "@commitlint/config-conventional@18.6.0" - "@grnsft/if-core@0.0.10" - - "@jest/globals@29.7.0" - "@types/jest@29.5.8" - "@types/js-yaml@4.0.9" @@ -131,6 +169,7 @@ tree: children: child-1: pipeline: + - mock-observations - interpolate - cpu-factor-to-wattage - wattage-times-duration From 6e612f0fe4a874f4b9985964abc7a00c8154f9f9 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 13:40:04 +0400 Subject: [PATCH 27/35] feat(package): update if-core version --- package-lock.json | 16 +++++++++------- package.json | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 78e1a23a3..0ebf1239a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.13", + "@grnsft/if-core": "^0.0.15", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1185,11 +1185,12 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.13", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.13.tgz", - "integrity": "sha512-FSNzs0jL7sFaT8ZaaTS4yRl0IRBorVOgMQ7mVcQKZc9+uONosrudvWLPoDTZfxEQ5ZyFsJe6yEt2O1E53XagqQ==", + "version": "0.0.15", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.15.tgz", + "integrity": "sha512-2x38VgvoQNRXPQscIHi8s+OkgsbV38ZcU65IwgNEHEEptpo+7xlYblMUDwnZJX5alI2JFn/uVX3W1IDjxoqTfQ==", "dependencies": { - "typescript": "^5.1.6" + "typescript": "^5.1.6", + "zod": "^3.23.8" }, "engines": { "node": ">=18", @@ -11870,8 +11871,9 @@ } }, "node_modules/zod": { - "version": "3.22.4", - "license": "MIT", + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index ec8f48aed..9a9457f81 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.13", + "@grnsft/if-core": "^0.0.15", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 72db420085ca7a904bc264ff3bcfb54d6a35b4c8 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 13:41:25 +0400 Subject: [PATCH 28/35] test(builtins): fix time-sync tests error messages --- src/__tests__/if-run/builtins/time-sync.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/if-run/builtins/time-sync.test.ts b/src/__tests__/if-run/builtins/time-sync.test.ts index 322971711..314ed06d4 100644 --- a/src/__tests__/if-run/builtins/time-sync.test.ts +++ b/src/__tests__/if-run/builtins/time-sync.test.ts @@ -362,7 +362,7 @@ describe('execute(): ', () => { expect(error).toBeInstanceOf(InputValidationError); expect(error).toStrictEqual( new InputValidationError( - '"timestamp" parameter is required in input[0]. Error code: invalid_union.' + '"timestamp" parameter is invalid datetime in input[0]. Error code: invalid_string.' ) ); } @@ -645,7 +645,7 @@ describe('execute(): ', () => { expect(error).toBeInstanceOf(InputValidationError); expect(error).toStrictEqual( new InputValidationError( - '"timestamp" parameter is invalid datetime in input[1]. Error code: invalid_string.' + '"start-time" parameter is invalid datetime. Error code: invalid_string.' ) ); } From 44c74ecbb66e8c977dc68bf44a0bb614f8bde310 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 16:42:06 +0400 Subject: [PATCH 29/35] fix(manifests): rename 'aggregationMethod' to 'aggregation-method' --- .../pipelines/pipeline-with-mocks.yml | 26 +++++++++---------- .../outputs/pipelines/mock-obs-time-sync.yaml | 16 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/manifests/examples/pipelines/pipeline-with-mocks.yml b/manifests/examples/pipelines/pipeline-with-mocks.yml index fa681a918..0ef54f32c 100644 --- a/manifests/examples/pipelines/pipeline-with-mocks.yml +++ b/manifests/examples/pipelines/pipeline-with-mocks.yml @@ -30,19 +30,19 @@ initialize: timestamp: description: refers to the time of occurrence of the input unit: RFC3339 - aggregationMethod: none + aggregation-method: none duration: description: refers to the duration of the input unit: seconds - aggregationMethod: sum + aggregation-method: sum cloud/instance-type: description: type of Cloud Instance name used in the cloud provider APIs unit: none - aggregationMethod: none + aggregation-method: none cloud/region: description: region cloud instance unit: none - aggregationMethod: none + aggregation-method: none "interpolate": method: Interpolation path: "builtin" @@ -57,12 +57,12 @@ initialize: cpu/utilization: description: refers to CPU utilization. unit: percentage - aggregationMethod: avg + aggregation-method: avg outputs: cpu-factor: description: result of interpolate unit: kWh - aggregationMethod: avg + aggregation-method: avg "cpu-factor-to-wattage": method: Multiply path: builtin @@ -74,12 +74,12 @@ initialize: cpu/thermal-design-power: description: thermal design power for a processor unit: kwh - aggregationMethod: avg + aggregation-method: avg outputs: cpu-wattage: description: the energy used by the CPU unit: kwh - aggregationMethod: sum + aggregation-method: sum "wattage-times-duration": method: Multiply path: builtin @@ -105,11 +105,11 @@ initialize: vcpus-total: description: total number of vcpus available on a particular resource unit: count - aggregationMethod: none + aggregation-method: none vcpus-allocated: description: number of vcpus allocated to particular resource unit: count - aggregationMethod: none + aggregation-method: none "correct-cpu-energy-for-vcpu-ratio": method: Divide path: "builtin" @@ -131,7 +131,7 @@ initialize: grid/carbon-intensity: description: Carbon intensity for the grid unit: gCO2eq/kWh - aggregationMethod: avg + aggregation-method: avg "sum-carbon": path: "builtin" method: Sum @@ -150,7 +150,7 @@ initialize: requests: description: expressed the final SCI value unit: none - aggregationMethod: sum + aggregation-method: sum "time-sync": method: TimeSync path: "builtin" @@ -164,7 +164,7 @@ initialize: time-reserved: description: time reserved for a component unit: seconds - aggregationMethod: avg + aggregation-method: avg "group-by": path: builtin method: GroupBy diff --git a/manifests/outputs/pipelines/mock-obs-time-sync.yaml b/manifests/outputs/pipelines/mock-obs-time-sync.yaml index 11d8b6c34..623305f0b 100644 --- a/manifests/outputs/pipelines/mock-obs-time-sync.yaml +++ b/manifests/outputs/pipelines/mock-obs-time-sync.yaml @@ -24,19 +24,19 @@ initialize: timestamp: description: refers to the time of occurrence of the input unit: RFC3339 - aggregationMethod: none + aggregation-method: none duration: description: refers to the duration of the input unit: seconds - aggregationMethod: sum + aggregation-method: sum cloud/instance-type: description: type of Cloud Instance name used in the cloud provider APIs unit: none - aggregationMethod: none + aggregation-method: none cloud/region: description: region cloud instance unit: none - aggregationMethod: none + aggregation-method: none interpolate: path: builtin method: Interpolation @@ -59,7 +59,7 @@ initialize: cpu/utilization: description: refers to CPU utilization. unit: percentage - aggregationMethod: avg + aggregation-method: avg cpu-factor-to-wattage: path: builtin method: Multiply @@ -73,7 +73,7 @@ initialize: cpu/thermal-design-power: description: thermal design power for a processor unit: kwh - aggregationMethod: avg + aggregation-method: avg wattage-times-duration: path: builtin method: Multiply @@ -101,11 +101,11 @@ initialize: vcpus-total: description: total number of vcpus available on a particular resource unit: count - aggregationMethod: none + aggregation-method: none vcpus-allocated: description: number of vcpus allocated to particular resource unit: count - aggregationMethod: none + aggregation-method: none correct-cpu-energy-for-vcpu-ratio: path: builtin method: Divide From cf7f3ba99a1bd212d47f8e7d530446f41f8fcb98 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 16:44:43 +0400 Subject: [PATCH 30/35] fix(util): rename 'aggregationMethod' to 'aggregation-method' --- src/common/util/validations.ts | 4 ++-- src/if-run/util/helpers.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/util/validations.ts b/src/common/util/validations.ts index 39de2de1c..8599274bf 100644 --- a/src/common/util/validations.ts +++ b/src/common/util/validations.ts @@ -64,7 +64,7 @@ export const manifestSchema = z.object({ z.object({ unit: z.string(), description: z.string(), - aggregationMethod: z.string(), + 'aggregation-method': z.string(), }) ) .optional() @@ -75,7 +75,7 @@ export const manifestSchema = z.object({ z.object({ unit: z.string(), description: z.string(), - aggregationMethod: z.string(), + 'aggregation-method': z.string(), }) ) .optional() diff --git a/src/if-run/util/helpers.ts b/src/if-run/util/helpers.ts index 5870181e9..da50f22f4 100644 --- a/src/if-run/util/helpers.ts +++ b/src/if-run/util/helpers.ts @@ -44,7 +44,7 @@ export const mergeObjects = (defaults: any, input: any) => { }; /** - * Stores `aggregationMethod` of the plugins in the pipeline. + * Stores `'aggregation-method'` of the plugins in the pipeline. */ export const storeAggregationMethods = ( plugins: GlobalPlugins, @@ -59,7 +59,7 @@ export const storeAggregationMethods = ( Object.entries(pluginParameters).forEach( ([parameterName, parameterMetadata]) => { - const {aggregationMethod} = parameterMetadata; + const {'aggregation-method': aggregationMethod} = parameterMetadata; if (aggregationMethod) { const metrics = { From 8dbd79d7d3259fbfb18a2fe29257137110229e35 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 16:46:19 +0400 Subject: [PATCH 31/35] fix(builtins): rename 'aggregationMethod' to 'aggregation-method' --- src/if-run/builtins/coefficient/index.ts | 4 ++-- src/if-run/builtins/sci-embodied/index.ts | 12 ++++++------ src/if-run/builtins/sci/index.ts | 6 +++--- src/if-run/builtins/time-sync.ts | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/if-run/builtins/coefficient/index.ts b/src/if-run/builtins/coefficient/index.ts index f04a2ab74..13764bf0c 100644 --- a/src/if-run/builtins/coefficient/index.ts +++ b/src/if-run/builtins/coefficient/index.ts @@ -24,14 +24,14 @@ export const Coefficient = ( carbon: { description: 'an amount of carbon emitted into the atmosphere', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, outputs: parametersMetadata?.outputs || { 'carbon-product': { description: 'a product of cabon property and the coefficient', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, }; diff --git a/src/if-run/builtins/sci-embodied/index.ts b/src/if-run/builtins/sci-embodied/index.ts index 6bd7fd1b8..35e012b72 100644 --- a/src/if-run/builtins/sci-embodied/index.ts +++ b/src/if-run/builtins/sci-embodied/index.ts @@ -20,17 +20,17 @@ export const SciEmbodied = ( 'device/emissions-embodied': { description: 'total embodied emissions of some component', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, 'device/expected-lifespan': { description: 'Total Expected Lifespan of the Component in Seconds', unit: 'seconds', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, 'resources-reserved': { description: 'resources reserved for an application', unit: 'count', - aggregationMethod: 'none', + 'aggregation-method': 'none', }, 'resources-total': { description: 'total resources available', @@ -39,19 +39,19 @@ export const SciEmbodied = ( 'vcpus-allocated': { description: 'number of vcpus allocated to particular resource', unit: 'count', - aggregationMethod: 'none', + 'aggregation-method': 'none', }, 'vcpus-total': { description: 'total number of vcpus available on a particular resource', unit: 'count', - aggregationMethod: 'none', + 'aggregation-method': 'none', }, }, outputs: parametersMetadata?.outputs || { 'carbon-embodied': { description: 'embodied emissions of the component', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, }; diff --git a/src/if-run/builtins/sci/index.ts b/src/if-run/builtins/sci/index.ts index ac566fdb9..70608fe84 100644 --- a/src/if-run/builtins/sci/index.ts +++ b/src/if-run/builtins/sci/index.ts @@ -29,20 +29,20 @@ export const Sci = ( carbon: { description: 'an amount of carbon emitted into the atmosphere', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, 'functional-unit': { description: 'the name of the functional unit in which the final SCI value should be expressed, e.g. requests, users', unit: 'none', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, outputs: parametersMetadata?.outputs || { sci: { description: 'carbon expressed in terms of the given functional unit', unit: 'gCO2e', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, }; diff --git a/src/if-run/builtins/time-sync.ts b/src/if-run/builtins/time-sync.ts index ae5a91a87..9d589c491 100644 --- a/src/if-run/builtins/time-sync.ts +++ b/src/if-run/builtins/time-sync.ts @@ -46,12 +46,12 @@ export const TimeSync = ( timestamp: { description: 'refers to the time of occurrence of the input', unit: 'RFC3339', - aggregationMethod: 'none', + 'aggregation-method': 'none', }, duration: { description: 'refers to the duration of the input', unit: 'seconds', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, outputs: parametersMetadata?.outputs, From 8537a3e54c3c540872e3f48094fc66f3abb30761 Mon Sep 17 00:00:00 2001 From: manushak Date: Wed, 24 Jul 2024 16:48:49 +0400 Subject: [PATCH 32/35] test(util): rename 'aggregationMethod' to 'aggregation-method' --- src/__tests__/if-run/util/helpers.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/__tests__/if-run/util/helpers.test.ts b/src/__tests__/if-run/util/helpers.test.ts index 742990486..cd60b10a7 100644 --- a/src/__tests__/if-run/util/helpers.test.ts +++ b/src/__tests__/if-run/util/helpers.test.ts @@ -209,14 +209,14 @@ describe('if-run/util/helpers: ', () => { carbon: { description: 'mock description', unit: 'none', - aggregationMethod: 'sum', + 'aggregation-method': 'sum', }, }, outputs: { cpu: { description: 'mock description', unit: 'none', - aggregationMethod: 'avg', + 'aggregation-method': 'avg', }, }, }, @@ -226,7 +226,7 @@ describe('if-run/util/helpers: ', () => { metadata: { inputs: {}, outputs: { - carbon: {aggregationMethod: 'none'}, + carbon: {'aggregation-method': 'none'}, }, }, }; From 725fcfd95ebe8f754ae2213f054778bf9a002053 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 26 Jul 2024 18:50:09 +0400 Subject: [PATCH 33/35] feat(package): update if-core version --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0ebf1239a..df1de316d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.15", + "@grnsft/if-core": "^0.0.16", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", @@ -1185,9 +1185,9 @@ } }, "node_modules/@grnsft/if-core": { - "version": "0.0.15", - "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.15.tgz", - "integrity": "sha512-2x38VgvoQNRXPQscIHi8s+OkgsbV38ZcU65IwgNEHEEptpo+7xlYblMUDwnZJX5alI2JFn/uVX3W1IDjxoqTfQ==", + "version": "0.0.16", + "resolved": "https://registry.npmjs.org/@grnsft/if-core/-/if-core-0.0.16.tgz", + "integrity": "sha512-Ep/YRk8rpFK7+kgD3iKon6PtY8jEj8H3ihYglw9Jli5lPszObwIMb4e6aHXmW2kcCndpBQKuSXaruGTgQ/d9ww==", "dependencies": { "typescript": "^5.1.6", "zod": "^3.23.8" diff --git a/package.json b/package.json index 9a9457f81..f8df2255f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "dependencies": { "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", - "@grnsft/if-core": "^0.0.15", + "@grnsft/if-core": "^0.0.16", "axios": "^1.7.2", "csv-parse": "^5.5.6", "csv-stringify": "^6.4.6", From 14a2d1e9c4dd3d002eda6b49b0833de81f0ce8af Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 26 Jul 2024 18:51:54 +0400 Subject: [PATCH 34/35] test(lib): fix git and ts waning on these tests --- src/__tests__/if-run/lib/explain.test.ts | 15 ++++++++++++++- src/__tests__/if-run/util/helpers.test.ts | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/__tests__/if-run/lib/explain.test.ts b/src/__tests__/if-run/lib/explain.test.ts index 509c3ba32..506c62669 100644 --- a/src/__tests__/if-run/lib/explain.test.ts +++ b/src/__tests__/if-run/lib/explain.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import {explain, addExplainData} from '../../../if-run/lib/explain'; describe('lib/explain: ', () => { @@ -34,16 +35,19 @@ describe('lib/explain: ', () => { 'cpu/energy': { unit: 'kWh', description: 'energy consumed by the cpu', + 'aggregation-method': 'sum', }, 'network/energy': { unit: 'kWh', description: 'energy consumed by data ingress and egress', + 'aggregation-method': 'sum', }, }, outputs: { 'energy-sum': { unit: 'kWh', description: 'sum of energy components', + 'aggregation-method': 'sum', }, }, }, @@ -66,20 +70,29 @@ describe('lib/explain: ', () => { 'cpu/energy': { unit: 'kWh', description: 'energy consumed by the cpu', + 'aggregation-method': 'sum', }, 'network/energy': { unit: 'kWh', description: 'energy consumed by data ingress and egress', + 'aggregation-method': 'sum', }, }, outputs: { - 'energy-sum': {unit: 'kWh', description: 'sum of energy components'}, + 'energy-sum': { + unit: 'kWh', + description: 'sum of energy components', + 'aggregation-method': 'sum', + }, }, }, }; + // @ts-ignore addExplainData(mockData); + const result = explain(); + expect.assertions(1); expect(result).toEqual(expectedResult); }); diff --git a/src/__tests__/if-run/util/helpers.test.ts b/src/__tests__/if-run/util/helpers.test.ts index cd60b10a7..c694c0a9a 100644 --- a/src/__tests__/if-run/util/helpers.test.ts +++ b/src/__tests__/if-run/util/helpers.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ const mockWarn = jest.fn(); const mockError = jest.fn(); @@ -180,9 +181,10 @@ describe('if-run/util/helpers: ', () => { }); describe('storeAggregationMethods(): ', () => { + // @typescript-eslint/no-unused-vars const mockPluginStorage = { get: jest.fn(), - set: jest.fn((_name, _plugin) => {}), + set: jest.fn(() => {}), }; const mockPlugins: GlobalPlugins = { From bbb219d2955127338cf1c7b0d3c5908573a751a7 Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 26 Jul 2024 19:13:40 +0400 Subject: [PATCH 35/35] docs(builtins): add `aggregation-method` to the docs --- src/if-run/builtins/coefficient/README.md | 4 +++- src/if-run/builtins/copy-param/README.md | 4 +++- src/if-run/builtins/csv-lookup/README.md | 15 +++++++++++++++ src/if-run/builtins/divide/README.md | 4 +++- src/if-run/builtins/exponent/README.md | 4 +++- src/if-run/builtins/interpolation/README.md | 4 +++- src/if-run/builtins/mock-observations/README.md | 15 +++++++++++++++ src/if-run/builtins/multiply/README.md | 4 +++- src/if-run/builtins/regex/README.md | 5 +++-- src/if-run/builtins/sci-embodied/README.md | 4 +++- src/if-run/builtins/sci/README.md | 4 +++- src/if-run/builtins/shell/README.md | 15 +++++++++++++++ src/if-run/builtins/subtract/README.md | 4 +++- src/if-run/builtins/sum/README.md | 4 +++- 14 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/if-run/builtins/coefficient/README.md b/src/if-run/builtins/coefficient/README.md index f0e16cb4b..a80f4e4fb 100644 --- a/src/if-run/builtins/coefficient/README.md +++ b/src/if-run/builtins/coefficient/README.md @@ -18,17 +18,19 @@ Three parameters are required in global config: `input-parameter`, `coefficient` ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe parameters of the `input-parameter` of the global config. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe parameters of the `output-parameter` of the global config. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/copy-param/README.md b/src/if-run/builtins/copy-param/README.md index 8e6ef563a..309a83fde 100644 --- a/src/if-run/builtins/copy-param/README.md +++ b/src/if-run/builtins/copy-param/README.md @@ -41,16 +41,18 @@ Three parameters are required in config: `from` and `to` and `keep-existing`. ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameter of the `from` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameters of the `to` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/csv-lookup/README.md b/src/if-run/builtins/csv-lookup/README.md index 317f3c897..31bdcdb17 100644 --- a/src/if-run/builtins/csv-lookup/README.md +++ b/src/if-run/builtins/csv-lookup/README.md @@ -53,6 +53,21 @@ All the following values are valid for the `output` field: - `["processor-name", "processor-model-id"]` - `[["processor-name", "processor-model-id"],["tdp","thermal-design-power"]]` +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs + +- `inputs`: describe the parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + +- `outputs`: describe the parameters in the `output` of the config block. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + ### Inputs There are no strict requirements on input for this plugin because they depend upon the contents of the target CSV and your input data at the time the CSV lookup is invoked. Please make sure you are requesting data from columns that exist in the target csv file and that your query values are available in your `input` data. diff --git a/src/if-run/builtins/divide/README.md b/src/if-run/builtins/divide/README.md index 98e5c0314..b17925dff 100644 --- a/src/if-run/builtins/divide/README.md +++ b/src/if-run/builtins/divide/README.md @@ -14,16 +14,18 @@ You provide the names of the values you want to divide, and a name to use to add ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameter of the `numerator` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameter of the `denominator` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/exponent/README.md b/src/if-run/builtins/exponent/README.md index ed1c74b35..b4f4d7d17 100644 --- a/src/if-run/builtins/exponent/README.md +++ b/src/if-run/builtins/exponent/README.md @@ -18,16 +18,18 @@ Three parameters are required in global config: `input-parameter`, `exponent` an ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes:: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/interpolation/README.md b/src/if-run/builtins/interpolation/README.md index dedcfe5e9..a6d897f32 100644 --- a/src/if-run/builtins/interpolation/README.md +++ b/src/if-run/builtins/interpolation/README.md @@ -27,16 +27,18 @@ To employ the `Interpolation` plugin, adhere to these steps: ## Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameter of the `input-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameters of the `output-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ## Input Parameters diff --git a/src/if-run/builtins/mock-observations/README.md b/src/if-run/builtins/mock-observations/README.md index 0da9211da..91f418ccb 100644 --- a/src/if-run/builtins/mock-observations/README.md +++ b/src/if-run/builtins/mock-observations/README.md @@ -17,6 +17,21 @@ The mode currently mocks 2 types of observation data: - `generators` define which fields to generate for each observation - `components` define the components for which to generate observations. The observations generated according to `timestamp-from`, `timestamp-to`, `duration` and `generators` will be duplicated for each component. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs + +- `inputs`: describe the parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + +- `outputs`: describe the output parameters. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + ### Authentication N/A diff --git a/src/if-run/builtins/multiply/README.md b/src/if-run/builtins/multiply/README.md index 6acbb847a..86a65aecb 100644 --- a/src/if-run/builtins/multiply/README.md +++ b/src/if-run/builtins/multiply/README.md @@ -17,16 +17,18 @@ Two parameters are required in global config: `input-parameters` and `output-par ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/regex/README.md b/src/if-run/builtins/regex/README.md index 9a0d388c2..d9f382274 100644 --- a/src/if-run/builtins/regex/README.md +++ b/src/if-run/builtins/regex/README.md @@ -18,16 +18,18 @@ Intel® Xeon® Platinum 8272CL,Intel® Xeon® 8171M 2.1 GHz,Intel® Xeon® E5-26 ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameter of the `parameter` value of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameters of the `output` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs @@ -37,7 +39,6 @@ The `parameter-metadata` section contains information about `description` and `u - `output`: The match of the `parameter` value using the `match` regex defined in the global config. If the `match` regex includes the global flag (`g`), a string containing all matches separated by spaces. - ## Implementation To run the plugin, you must first create an instance of `Regex`. Then, you can call `execute()`. diff --git a/src/if-run/builtins/sci-embodied/README.md b/src/if-run/builtins/sci-embodied/README.md index 21266fba7..ed9c1841e 100644 --- a/src/if-run/builtins/sci-embodied/README.md +++ b/src/if-run/builtins/sci-embodied/README.md @@ -12,16 +12,18 @@ Not Needed ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe the parameters of the `inputs`. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the `carbon-embodied` parameter. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/sci/README.md b/src/if-run/builtins/sci/README.md index 4d9544ad2..d0b08c9c5 100644 --- a/src/if-run/builtins/sci/README.md +++ b/src/if-run/builtins/sci/README.md @@ -10,16 +10,18 @@ ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe parameters of the `inputs`. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the `sci` parameter which has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/shell/README.md b/src/if-run/builtins/shell/README.md index 962fb46d4..5e529f922 100644 --- a/src/if-run/builtins/shell/README.md +++ b/src/if-run/builtins/shell/README.md @@ -22,6 +22,21 @@ The `shell` plugin interface requires a path to the plugin command. This path is - `command`: the path to the plugin executable along with the execution command as it would be entered into a shell. +### Plugin parameter metadata + +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs + +- `inputs`: describe the parameters of the `inputs`. Each parameter has: + + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + +- `outputs`: describe the output parameter. The parameter has the following attributes: + - `description`: description of the parameter + - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) + ### Inputs The parameters included in the `inputs` field in the `manifest` depend entirely on the plugin itself. A typical plugin might expect the following common data to be provided as `inputs`: diff --git a/src/if-run/builtins/subtract/README.md b/src/if-run/builtins/subtract/README.md index 9916404bc..89a186ab3 100644 --- a/src/if-run/builtins/subtract/README.md +++ b/src/if-run/builtins/subtract/README.md @@ -17,16 +17,18 @@ Two parameters are required in global config: `input-parameters` and `output-par ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs diff --git a/src/if-run/builtins/sum/README.md b/src/if-run/builtins/sum/README.md index 4d861f2c9..014111c6c 100644 --- a/src/if-run/builtins/sum/README.md +++ b/src/if-run/builtins/sum/README.md @@ -17,16 +17,18 @@ Two parameters are required in global config: `input-parameters` and `output-par ### Plugin parameter metadata -The `parameter-metadata` section contains information about `description` and `unit` of the parameters of the inputs and outputs +The `parameter-metadata` section contains information about `description`, `unit` and `aggregation-method` of the parameters of the inputs and outputs - `inputs`: describe parameters of the `input-parameters` of the global config. Each parameter has: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) - `outputs`: describe the parameter of the `output-parameter` of the global config. The parameter has the following attributes: - `description`: description of the parameter - `unit`: unit of the parameter + - `aggregation-method`: aggregation method of the parameter (it can be `sum`, `avg` or `none`) ### Inputs