@grnsft/if 0.3.4 → 0.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.js +0 -1
- package/.lintstagedrc.js +6 -0
- package/README.md +12 -8
- package/Refactor-migration-guide.md +6 -6
- package/github-processes.md +16 -42
- package/manifests/bugs/aggregation-error-wrong-metric.yml +6 -6
- package/manifests/bugs/azure-importer-ignoring-defaults.yml +3 -3
- package/manifests/bugs/azure-importer-incorrect-calculation.yml +2 -2
- package/manifests/bugs/mock-observations-failure-duration-is-zero.yml +34 -0
- package/manifests/bugs/pipeline-error-uninitialized-plugin.yml +1 -1
- package/manifests/bugs/pipeline-ordering-error.yml +6 -6
- package/manifests/bugs/sci-embodied-missing-resources-total.yml +23 -0
- package/manifests/examples/generics.yml +3 -3
- package/manifests/examples/instance-metadata.yml +36 -0
- package/manifests/examples/mock-cpu-util-to-carbon.yml +3 -3
- package/manifests/examples/nesting.yml +37 -10
- package/manifests/examples/pipeline-teads-sci.yml +17 -9
- package/manifests/examples/pipeline-with-aggregate.yml +24 -9
- package/manifests/examples/pipeline-with-mocks.yml +26 -9
- package/manifests/examples/sci.yml +131 -0
- package/manifests/examples/teads-curve.yml +78 -0
- package/manifests/features/aggregate-failure-inalid-metrics.yml +43 -0
- package/manifests/features/aggregate-failure-missing-metric-in-inputs.yml +43 -0
- package/manifests/integrations/cloud-metadata-divide-boavizta.yml +1 -1
- package/manifests/integrations/mock-obs-group-by-cloud-meta.yml +51 -0
- package/manifests/integrations/mock-obs-groupby.yml +2 -2
- package/manifests/integrations/mock-obs-time-sync.yml +1 -1
- package/manifests/plugins/cloud-metadata/failure-invalid-instance-type.yaml +21 -0
- package/manifests/plugins/cloud-metadata/failure-invalid-vendor.yaml +1 -1
- package/manifests/plugins/cloud-metadata/failure-missing-cloud-vendor.yml +21 -0
- package/manifests/plugins/cloud-metadata/success.yml +1 -1
- package/manifests/plugins/coefficient/failure-invalid-config-input-param.yml +1 -1
- package/manifests/plugins/coefficient/failure-output-param-is-null.yaml +24 -0
- package/manifests/plugins/coefficient/success.yml +1 -1
- package/manifests/plugins/csv-lookup/failure-missing-column.yml +26 -0
- package/manifests/plugins/csv-lookup/failure-missing-output.yml +26 -0
- package/manifests/plugins/csv-lookup/success-renaming.yml +26 -0
- package/manifests/plugins/csv-lookup/success.yml +26 -0
- package/manifests/plugins/divide/failure-denominator-equal-zero.yml +39 -0
- package/manifests/plugins/divide/failure-invalid-config-denominator.yml +1 -1
- package/manifests/plugins/divide/failure-missing-numerator.yml +39 -0
- package/manifests/plugins/divide/success.yml +2 -2
- package/manifests/plugins/groupby/failure-missing-cloud-instance-type.yml +49 -0
- package/manifests/plugins/interpolation/interpolation.yml +24 -0
- package/manifests/plugins/mock-observations/failure-invalid-config-cpu-range.yml +1 -1
- package/manifests/plugins/mock-observations/failure-invalid-memory-utilization-range.yml +34 -0
- package/manifests/plugins/mock-observations/failure-missing-timestamp-from-param.yml +34 -0
- package/manifests/plugins/mock-observations/success.yml +2 -2
- package/manifests/plugins/multiply/failure-input-parameter-is-missing.yml +1 -1
- package/manifests/plugins/multiply/success-with-multiple-inputs.yml +32 -0
- package/manifests/plugins/multiply/success.yml +3 -3
- package/manifests/plugins/regex/failure-missing-input-param.yml +1 -1
- package/manifests/plugins/regex/failure-not-matching-with-regex.yml +24 -0
- package/manifests/plugins/regex/success.yml +2 -2
- package/manifests/plugins/sci/failure-invalid-config-value.yml +2 -3
- package/manifests/plugins/sci/failure-missing-input-param.yml +27 -0
- package/manifests/plugins/sci/success.yml +5 -4
- package/manifests/plugins/{sci-m → sci-embodied}/failure-invalid-default-emission-value.yml +5 -6
- package/manifests/plugins/sci-embodied/failure-missing-expected-lifespan.yml +23 -0
- package/manifests/plugins/{sci-m → sci-embodied}/success.yml +5 -6
- package/manifests/plugins/shell/failure-invalid-command.yml +1 -1
- package/manifests/plugins/shell/success.yml +1 -2
- package/manifests/plugins/sum/failure-missing-input-param.yml +1 -1
- package/manifests/plugins/sum/failure-missing-output-param.yml +28 -0
- package/manifests/plugins/sum/success.yml +1 -1
- package/manifests/plugins/tdp-finder/failure-unsupported-physical-processor.yml +19 -0
- package/manifests/plugins/time-sync/failure-missing-global-config.yml +34 -0
- package/package.json +10 -2
- package/src/builtins/README.md +5 -5
- package/src/builtins/coefficient/README.md +92 -0
- package/src/builtins/csv-lookup/README.md +142 -0
- package/src/builtins/divide/README.md +95 -0
- package/src/builtins/exponent/README.md +97 -0
- package/src/builtins/interpolation/README.md +168 -0
- package/src/builtins/mock-observations/README.md +97 -0
- package/src/builtins/multiply/README.md +94 -0
- package/src/builtins/regex/README.md +91 -0
- package/src/builtins/sci/README.md +89 -0
- package/src/builtins/sci-embodied/README.md +110 -0
- package/src/builtins/shell/README.md +130 -0
- package/src/builtins/subtract/README.md +94 -0
- package/src/builtins/sum/README.md +91 -0
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
name: sci-
|
|
1
|
+
name: sci-embodied
|
|
2
2
|
description: failure with `defaults.device/emissions-embodied` being string instead of number
|
|
3
3
|
tags:
|
|
4
4
|
initialize:
|
|
5
5
|
outputs: ['yaml']
|
|
6
6
|
plugins:
|
|
7
|
-
"sci-
|
|
8
|
-
method:
|
|
9
|
-
|
|
10
|
-
path: "@grnsft/if-plugins"
|
|
7
|
+
"sci-embodied": # a model that calculates m from te, tir, el, rr and rtor
|
|
8
|
+
method: SciEmbodied
|
|
9
|
+
path: "builtin"
|
|
11
10
|
tree:
|
|
12
11
|
children:
|
|
13
12
|
child:
|
|
14
13
|
pipeline:
|
|
15
|
-
- sci-
|
|
14
|
+
- sci-embodied # duration & config -> embodied
|
|
16
15
|
defaults:
|
|
17
16
|
device/emissions-embodied: 'fail' # gCO2eq
|
|
18
17
|
time-reserved: 3600 # 1hr in seconds
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: sci-embodied
|
|
2
|
+
description: missing device/expected-lifespan
|
|
3
|
+
tags:
|
|
4
|
+
initialize:
|
|
5
|
+
#outputs: ['yaml']
|
|
6
|
+
plugins:
|
|
7
|
+
"sci-embodied": # a model that calculates m from te, tir, el, rr and rtor
|
|
8
|
+
method: SciEmbodied
|
|
9
|
+
path: "builtin"
|
|
10
|
+
tree:
|
|
11
|
+
children:
|
|
12
|
+
child:
|
|
13
|
+
pipeline:
|
|
14
|
+
- sci-embodied # duration & config -> embodied
|
|
15
|
+
defaults:
|
|
16
|
+
device/emissions-embodied: 1533.120 # gCO2eq
|
|
17
|
+
time-reserved: 3600 # 1hr in seconds
|
|
18
|
+
#device/expected-lifespan: 94608000 # 3 years in seconds
|
|
19
|
+
resources-reserved: 1
|
|
20
|
+
resources-total: 8
|
|
21
|
+
inputs:
|
|
22
|
+
- timestamp: 2023-07-06T00:00
|
|
23
|
+
duration: 3600
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
name: sci-
|
|
1
|
+
name: sci-embodied
|
|
2
2
|
description: successful path
|
|
3
3
|
tags:
|
|
4
4
|
initialize:
|
|
5
5
|
outputs: ['yaml']
|
|
6
6
|
plugins:
|
|
7
|
-
"sci-
|
|
8
|
-
method:
|
|
9
|
-
|
|
10
|
-
path: "@grnsft/if-plugins"
|
|
7
|
+
"sci-embodied": # a model that calculates m from te, tir, el, rr and rtor
|
|
8
|
+
method: SciEmbodied
|
|
9
|
+
path: "builtin"
|
|
11
10
|
tree:
|
|
12
11
|
children:
|
|
13
12
|
child:
|
|
14
13
|
pipeline:
|
|
15
|
-
- sci-
|
|
14
|
+
- sci-embodied # duration & config -> embodied
|
|
16
15
|
defaults:
|
|
17
16
|
device/emissions-embodied: 1533.120 # gCO2eq
|
|
18
17
|
time-reserved: 3600 # 1hr in seconds
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: sum
|
|
2
|
+
description: missing `output-parameter` in global-config
|
|
3
|
+
tags:
|
|
4
|
+
initialize:
|
|
5
|
+
outputs: ['yaml']
|
|
6
|
+
plugins:
|
|
7
|
+
sum:
|
|
8
|
+
method: Sum
|
|
9
|
+
path: "builtin"
|
|
10
|
+
global-config:
|
|
11
|
+
input-parameters: ["cpu/energy", "network/energy"]
|
|
12
|
+
# output-parameter: "energy"
|
|
13
|
+
tree:
|
|
14
|
+
children:
|
|
15
|
+
child:
|
|
16
|
+
pipeline:
|
|
17
|
+
- sum
|
|
18
|
+
config:
|
|
19
|
+
sum:
|
|
20
|
+
inputs:
|
|
21
|
+
- timestamp: 2023-08-06T00:00
|
|
22
|
+
duration: 3600
|
|
23
|
+
cpu/energy: 0.001
|
|
24
|
+
network/energy: 0.001
|
|
25
|
+
- timestamp: 2023-08-06T00:00
|
|
26
|
+
duration: 3600
|
|
27
|
+
cpu/energy: 0.001
|
|
28
|
+
network/energy: e
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: tdp-finder
|
|
2
|
+
description: successful path
|
|
3
|
+
tags:
|
|
4
|
+
initialize:
|
|
5
|
+
outputs: ['yaml']
|
|
6
|
+
plugins:
|
|
7
|
+
tdp-finder: # a model that returns an embodied value given the sci embodied attribution equation.
|
|
8
|
+
method: TdpFinder
|
|
9
|
+
path: "@grnsft/if-plugins"
|
|
10
|
+
tree:
|
|
11
|
+
children:
|
|
12
|
+
child:
|
|
13
|
+
pipeline:
|
|
14
|
+
- tdp-finder
|
|
15
|
+
config:
|
|
16
|
+
inputs:
|
|
17
|
+
- timestamp: 2023-07-06T00:00
|
|
18
|
+
duration: 300
|
|
19
|
+
physical-processor: AMD 302
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: time-sync
|
|
2
|
+
description: missing global config
|
|
3
|
+
tags:
|
|
4
|
+
initialize:
|
|
5
|
+
output:
|
|
6
|
+
- yaml
|
|
7
|
+
plugins:
|
|
8
|
+
'time-sync':
|
|
9
|
+
method: TimeSync
|
|
10
|
+
path: "builtin"
|
|
11
|
+
global-config:
|
|
12
|
+
# start-time: '2023-12-12T00:00:00.000Z'
|
|
13
|
+
# end-time: '2023-12-12T00:01:00.000Z'
|
|
14
|
+
# interval: 5
|
|
15
|
+
# allow-padding: true
|
|
16
|
+
tree:
|
|
17
|
+
children:
|
|
18
|
+
child:
|
|
19
|
+
pipeline:
|
|
20
|
+
- time-sync
|
|
21
|
+
config:
|
|
22
|
+
inputs:
|
|
23
|
+
- timestamp: '2023-12-12T00:00:00.000Z'
|
|
24
|
+
duration: 3
|
|
25
|
+
energy-cpu: 0.001
|
|
26
|
+
- timestamp: '2023-12-12T00:00:01.000Z'
|
|
27
|
+
duration: 5
|
|
28
|
+
energy-cpu: 0.001
|
|
29
|
+
- timestamp: '2023-12-12T00:00:06.000Z'
|
|
30
|
+
duration: 7
|
|
31
|
+
energy-cpu: 0.001
|
|
32
|
+
- timestamp: '2023-12-12T00:00:13.000Z'
|
|
33
|
+
duration: 30
|
|
34
|
+
energy-cpu: 0.001
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grnsft/if",
|
|
3
3
|
"description": "Impact Framework",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0-beta.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Green Software Foundation",
|
|
7
7
|
"email": "info@gsf.com"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"ie": "./build/index.js"
|
|
10
|
+
"ie": "./build/index.js",
|
|
11
|
+
"if-diff": "./build/diff.js"
|
|
11
12
|
},
|
|
12
13
|
"bugs": {
|
|
13
14
|
"url": "https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
|
|
@@ -15,11 +16,14 @@
|
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@commitlint/cli": "^18.6.0",
|
|
17
18
|
"@commitlint/config-conventional": "^18.6.0",
|
|
19
|
+
"axios": "^1.7.2",
|
|
20
|
+
"csv-parse": "^5.5.6",
|
|
18
21
|
"csv-stringify": "^6.4.6",
|
|
19
22
|
"js-yaml": "^4.1.0",
|
|
20
23
|
"luxon": "^3.4.4",
|
|
21
24
|
"ts-command-line-args": "^2.5.1",
|
|
22
25
|
"typescript": "^5.1.6",
|
|
26
|
+
"typescript-cubic-spline": "^1.0.1",
|
|
23
27
|
"winston": "^3.11.0",
|
|
24
28
|
"zod": "^3.22.4"
|
|
25
29
|
},
|
|
@@ -31,10 +35,12 @@
|
|
|
31
35
|
"@types/js-yaml": "^4.0.5",
|
|
32
36
|
"@types/luxon": "^3.4.2",
|
|
33
37
|
"@types/node": "^20.8.9",
|
|
38
|
+
"axios-mock-adapter": "^1.22.0",
|
|
34
39
|
"fixpack": "^4.0.0",
|
|
35
40
|
"gts": "^5.0.0",
|
|
36
41
|
"husky": "^8.0.0",
|
|
37
42
|
"jest": "^29.6.1",
|
|
43
|
+
"lint-staged": "^15.2.2",
|
|
38
44
|
"release-it": "^16.3.0",
|
|
39
45
|
"rimraf": "^5.0.5",
|
|
40
46
|
"ts-jest": "^29.1.1"
|
|
@@ -67,7 +73,9 @@
|
|
|
67
73
|
"fix": "gts fix",
|
|
68
74
|
"fix:package": "fixpack",
|
|
69
75
|
"ie": "npx ts-node src/index.ts",
|
|
76
|
+
"if-diff": "npx ts-node src/diff.ts",
|
|
70
77
|
"lint": "gts lint",
|
|
78
|
+
"pre-commit": "lint-staged",
|
|
71
79
|
"prepare": "husky install",
|
|
72
80
|
"prepublish": "npm run build",
|
|
73
81
|
"release": "release-it",
|
package/src/builtins/README.md
CHANGED
|
@@ -231,9 +231,9 @@ initialize:
|
|
|
231
231
|
sci-e:
|
|
232
232
|
method: SciE
|
|
233
233
|
path: '@grnsft/if-plugins'
|
|
234
|
-
sci-
|
|
235
|
-
path: '
|
|
236
|
-
method:
|
|
234
|
+
sci-embodied:
|
|
235
|
+
path: 'builtin'
|
|
236
|
+
method: SciEmbodied
|
|
237
237
|
sci-o:
|
|
238
238
|
method: SciO
|
|
239
239
|
path: '@grnsft/if-plugins'
|
|
@@ -250,13 +250,13 @@ tree:
|
|
|
250
250
|
pipeline:
|
|
251
251
|
- teads-curve
|
|
252
252
|
- sci-e
|
|
253
|
-
- sci-
|
|
253
|
+
- sci-embodied
|
|
254
254
|
- sci-o
|
|
255
255
|
- time-sync
|
|
256
256
|
config:
|
|
257
257
|
teads-curve:
|
|
258
258
|
cpu/thermal-design-power: 65
|
|
259
|
-
sci-
|
|
259
|
+
sci-embodied:
|
|
260
260
|
device/emissions-embodied: 251000 # gCO2eq
|
|
261
261
|
time-reserved: 3600 # 1 hour in s
|
|
262
262
|
device/expected-lifespan: 126144000 # 4 years in seconds
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Coefficient
|
|
2
|
+
|
|
3
|
+
`Coefficient` is a generic plugin for multiplying a value in an `input` array by a given coefficient.
|
|
4
|
+
|
|
5
|
+
You provide the name of the value you want to multiply, a coefficient value, and a name to use to append the product to the output array.
|
|
6
|
+
|
|
7
|
+
For example, you could multiply `cpu/energy` by 10 and name the result `energy-product`. `energy-product` would then be added to every observation in your input array as the product of `cpu/energy` and 10.
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### Plugin global config
|
|
12
|
+
|
|
13
|
+
Three parameters are required in global config: `input-parameter`, `coefficient` and `output-parameter`.
|
|
14
|
+
|
|
15
|
+
- `input-parameter`: a string matching an existing key in the `inputs` array
|
|
16
|
+
- `coefficient`: the value to multiply `input-parameter` by.
|
|
17
|
+
- `output-parameter`: a string defining the name to use to add the product of the input parameters to the output array.
|
|
18
|
+
|
|
19
|
+
### Inputs
|
|
20
|
+
|
|
21
|
+
All of `input-parameters` must be available in the input array.
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
- `output-parameter`: the product of all `input-parameters` with the parameter name defined by `output-parameter` in global config.
|
|
26
|
+
|
|
27
|
+
## Calculation
|
|
28
|
+
|
|
29
|
+
```pseudocode
|
|
30
|
+
output = input * coefficient
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Implementation
|
|
34
|
+
|
|
35
|
+
To run the plugin from a Typescript app, you must first create an instance of `Coefficient`. Then, you can call `execute()`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const config = {
|
|
39
|
+
'input-parameter': 'carbon',
|
|
40
|
+
coefficient: 10,
|
|
41
|
+
'output-parameter': 'carbon-product',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const coeff = Coefficient(config);
|
|
45
|
+
const result = coeff.execute([
|
|
46
|
+
{
|
|
47
|
+
duration: 3600,
|
|
48
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
49
|
+
carbon: 3,
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Example manifest
|
|
55
|
+
|
|
56
|
+
IF users will typically call the plugin as part of a pipeline defined in a manifest file. In this case, instantiating the plugin is handled by `ie` and does not have to be done explicitly by the user. The following is an example manifest that calls `coefficient`:
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
name: coefficient-demo
|
|
60
|
+
description:
|
|
61
|
+
tags:
|
|
62
|
+
initialize:
|
|
63
|
+
outputs:
|
|
64
|
+
- yaml
|
|
65
|
+
plugins:
|
|
66
|
+
coefficient:
|
|
67
|
+
method: Coefficient
|
|
68
|
+
path: 'builtin'
|
|
69
|
+
global-config:
|
|
70
|
+
input-parameter: 'carbon'
|
|
71
|
+
coefficient: 3
|
|
72
|
+
output-parameter: 'carbon-product'
|
|
73
|
+
tree:
|
|
74
|
+
children:
|
|
75
|
+
child:
|
|
76
|
+
pipeline:
|
|
77
|
+
- coefficient
|
|
78
|
+
config:
|
|
79
|
+
coefficient:
|
|
80
|
+
inputs:
|
|
81
|
+
- timestamp: 2023-08-06T00:00
|
|
82
|
+
duration: 3600
|
|
83
|
+
carbon: 30
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
You can run this example by saving it as `./examples/manifests/coefficient.yml` and executing the following command from the project root:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
ie --manifest ./examples/manifests/coefficient.yml --output ./examples/outputs/coefficient.yml
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# CSV Lookup Plugin
|
|
2
|
+
|
|
3
|
+
`csv-lookup` is a generic plugin that enables you to select arbitrary data from a given csv file and add it to your manifest file's `input` data.
|
|
4
|
+
|
|
5
|
+
You provide path to the target csv file pus some query parameters. The filepath can point to a location on the local filesystem or it can be a URL for an online resource. The query parameters include the column names for the target data you want to return (can be one column name, multiple column names or all column names, indicated using `"*"`), plus the column names and values you want to use as selectors.
|
|
6
|
+
|
|
7
|
+
For example, for the following CSV:
|
|
8
|
+
|
|
9
|
+
| | | | | | | | | | | | | | | | | |
|
|
10
|
+
| ---- | -------------- | --------------- | ---------- | ---------- | ------------ | --------- | ---------------- | ---------- | ---------- | ---------------------- | ---------- | -------------------------- | --------------------------------- | ------------------------------ | -------------------------------- | --------------------- |
|
|
11
|
+
| year | cloud-provider | cloud-region | cfe-region | em-zone-id | wt-region-id | location | geolocation | cfe-hourly | cfe-annual | power-usage-efficiency | net-carbon | grid-carbon-intensity-24x7 | grid-carbon-intensity-consumption | grid-carbon-intensity-marginal | grid-carbon-intensity-production | grid-carbon-intensity |
|
|
12
|
+
| 2022 | Google Cloud | asia-east1 | Taiwan | TW | TW | Taiwan | 25.0375,121.5625 | 0.18 | | | 0 | 453 | | | | 453 |
|
|
13
|
+
| 2022 | Google Cloud | asia-east2 | Hong Kong | HK | HK | Hong Kong | 22.3,114.2 | 0.28 | | | 0 | 453 | | | | 360 |
|
|
14
|
+
| 2022 | Google Cloud | asia-northeast1 | Tokyo | JP-TK | JP-TK | Tokyo | 35.6897,139.692 | 0.28 | | | 0 | 463 | | | | 463 |
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
You could select all the data for the cloud provider `Google Cloud` in the region `asia-east2` using the following configuration:
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
|
|
21
|
+
query:
|
|
22
|
+
cloud-provider: "cloud/provider"
|
|
23
|
+
cloud-region: "cloud/region"
|
|
24
|
+
output: "*"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Notice that the query parameters are key/value pairs where the key is the column name in the target CSV and the value is a **reference to a value** in your `input` data (*not* an actual value - a reference). This is to enable you to chain CSV lookups together based on information from other plugins in your pipeline.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Parameters
|
|
31
|
+
|
|
32
|
+
### Plugin config
|
|
33
|
+
|
|
34
|
+
- `filepath` - path to a csv file, either on the local filesystem or on the internet
|
|
35
|
+
- `query` - an array of key/value pairs where the key is a column name in the target csv and the value is a parameter from inputs
|
|
36
|
+
- `output` - the columns to grab data from and add to output data - should support wildcard or multiple values.
|
|
37
|
+
|
|
38
|
+
The plugin also supports data renaming. This means you can grab data from a named column but push it into your manifest file data under another name, for example, maybe we want to grab data from the `processor-name` column int he target csv and add it to the manifest file data as `processor-id` because this is the name expected by some other plugin in your piepline. You can do this by passing comma separated values in arrays.
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
output:
|
|
42
|
+
["processor-name": "processor-id"]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
You can nest arrays to do this renaming for multiple columns.
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
output:
|
|
49
|
+
[["processor-name", "processor-model-id"],["tdp","thermal-design-power"]]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
All the following values are valid for the `output` field:
|
|
53
|
+
- `"*"`
|
|
54
|
+
- `"tdp"`
|
|
55
|
+
- `["processor-name", "processor-model-id"]`
|
|
56
|
+
- `[["processor-name", "processor-model-id"],["tdp","thermal-design-power"]]`
|
|
57
|
+
|
|
58
|
+
### Inputs
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
|
|
62
|
+
## Returns
|
|
63
|
+
|
|
64
|
+
The input data with the requested csv content appended to it.
|
|
65
|
+
|
|
66
|
+
## Plugin logic
|
|
67
|
+
|
|
68
|
+
1. Validates global config which contains `filepath`, `query` and `output`.
|
|
69
|
+
2. Tries to retrieve given file (with url or local path).
|
|
70
|
+
3. Parses given CSV.
|
|
71
|
+
4. Filters requested information from CSV.
|
|
72
|
+
5. Adds new key-value pairs to the input data
|
|
73
|
+
6. Returns enriched input data
|
|
74
|
+
|
|
75
|
+
## Implementation
|
|
76
|
+
|
|
77
|
+
To run the plugin, you must first create an instance of `CSVLookup`. Then, you can call `execute()`.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const globalConfig = {
|
|
81
|
+
filepath: 'https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/cloud-metdata-aws-instances.csv',
|
|
82
|
+
query: {
|
|
83
|
+
'cloud-provider': 'cloud/provider'
|
|
84
|
+
region: 'cloud/region'
|
|
85
|
+
'instance-type': 'cloud/instance-type'
|
|
86
|
+
},
|
|
87
|
+
output: ['cpu-tdp', 'tdp'],
|
|
88
|
+
};
|
|
89
|
+
const divide = CSVLookup(globalConfig);
|
|
90
|
+
|
|
91
|
+
const input = [
|
|
92
|
+
{
|
|
93
|
+
timestamp: '2023-08-06T00:00'
|
|
94
|
+
duration: 3600
|
|
95
|
+
'cpu/energy': 0.001
|
|
96
|
+
'cloud/provider': gcp
|
|
97
|
+
'cloud/region': asia-east
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Example manifest
|
|
103
|
+
|
|
104
|
+
IF users will typically call the plugin as part of a pipeline defined in a manifest file. In this case, instantiating the plugin is handled by `if` and does not have to be done explicitly by the user. The following is an example manifest that calls `csv-lookup`:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
name: csv-lookup-demo
|
|
108
|
+
description:
|
|
109
|
+
tags:
|
|
110
|
+
initialize:
|
|
111
|
+
outputs:
|
|
112
|
+
- yaml
|
|
113
|
+
plugins:
|
|
114
|
+
cloud-metadata:
|
|
115
|
+
method: CSVLookup
|
|
116
|
+
path: 'builtin'
|
|
117
|
+
global-config:
|
|
118
|
+
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
|
|
119
|
+
query:
|
|
120
|
+
cloud-provider: "cloud/provider"
|
|
121
|
+
cloud-region: "cloud/region"
|
|
122
|
+
output: "*"
|
|
123
|
+
tree:
|
|
124
|
+
children:
|
|
125
|
+
child:
|
|
126
|
+
pipeline:
|
|
127
|
+
- cloud-metadata
|
|
128
|
+
inputs:
|
|
129
|
+
- timestamp: 2023-08-06T00:00
|
|
130
|
+
duration: 3600
|
|
131
|
+
cloud/provider: Google Cloud
|
|
132
|
+
cloud/region: europe-north1
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
You can run this example by saving it as `./examples/manifests/csv-lookup.yml` and executing the following command from the project root:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
npm i -g @grnsft/if
|
|
139
|
+
ie --manifest manifests/plugins/csv-lookup.yml --output manifests/outputs/csv-lookup
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The results will be saved to a new `yaml` file in `manifests/outputs`.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Divide
|
|
2
|
+
|
|
3
|
+
`divide` is a generic plugin for doing arithmetic division of two values in an `input` array.
|
|
4
|
+
|
|
5
|
+
You provide the names of the values you want to divide, and a name to use to add the divide to the output array.
|
|
6
|
+
|
|
7
|
+
For example, `boavizta-cpu` need `cpu/number-cores` to work, however `cloud-metadata` returns `vcpus-allocated`, to get number of cores you divide `vcpus-allocated` by 2.
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### Plugin config
|
|
12
|
+
|
|
13
|
+
- `numerator` - a parameter by a specific configured number
|
|
14
|
+
- `denominator` - a parameter by a specific configured number or the number by which `numerator` is divided
|
|
15
|
+
- `output` - the number to a configured output parameter
|
|
16
|
+
|
|
17
|
+
### Inputs
|
|
18
|
+
|
|
19
|
+
- `numerator` - as input parameter, must be available in the input array
|
|
20
|
+
- `denominator` - must be available in the input array if is an input parameter
|
|
21
|
+
- `output` - as input parameter, must be available in the input array
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
- `output`: the division of `numerator` with the parameter name into `denominator` with the parameter name defined by `output` in global config.
|
|
26
|
+
|
|
27
|
+
The plugin throws an exception if the division result is not a number.
|
|
28
|
+
|
|
29
|
+
## Calculation
|
|
30
|
+
|
|
31
|
+
```pseudocode
|
|
32
|
+
output = input0 / input1
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Implementation
|
|
36
|
+
|
|
37
|
+
To run the plugin, you must first create an instance of `Divide`. Then, you can call `execute()`.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const globalConfig = {
|
|
41
|
+
numerator: 'vcpus-allocated',
|
|
42
|
+
denominator: 2,
|
|
43
|
+
output: 'cpu/number-cores',
|
|
44
|
+
};
|
|
45
|
+
const divide = Divide(globalConfig);
|
|
46
|
+
|
|
47
|
+
const input = [
|
|
48
|
+
{
|
|
49
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
50
|
+
duration: 3600,
|
|
51
|
+
'vcpus-allocated': 24,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Example manifest
|
|
57
|
+
|
|
58
|
+
IF users will typically call the plugin as part of a pipeline defined in a manifest file. In this case, instantiating the plugin is handled by `if` and does not have to be done explicitly by the user. The following is an example manifest that calls `divide`:
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
name: divide-demo
|
|
62
|
+
description:
|
|
63
|
+
tags:
|
|
64
|
+
initialize:
|
|
65
|
+
outputs:
|
|
66
|
+
- yaml
|
|
67
|
+
plugins:
|
|
68
|
+
divide:
|
|
69
|
+
method: Divide
|
|
70
|
+
path: 'builtin'
|
|
71
|
+
global-config:
|
|
72
|
+
numerator: vcpus-allocated
|
|
73
|
+
denominator: 2
|
|
74
|
+
output: cpu/number-cores
|
|
75
|
+
tree:
|
|
76
|
+
children:
|
|
77
|
+
child:
|
|
78
|
+
pipeline:
|
|
79
|
+
- divide
|
|
80
|
+
config:
|
|
81
|
+
divide:
|
|
82
|
+
inputs:
|
|
83
|
+
- timestamp: 2023-08-06T00:00
|
|
84
|
+
duration: 3600
|
|
85
|
+
vcpus-allocated: 24
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You can run this example by saving it as `./examples/manifests/divide.yml` and executing the following command from the project root:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
npm i -g @grnsft/if
|
|
92
|
+
ie --manifest ./examples/manifests/divide.yml --output ./examples/outputs/divide.yml
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`.
|