@grnsft/if 0.3.4 → 0.4.0-beta.1
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/build/builtins/coefficient/index.d.ts +3 -0
- package/build/builtins/coefficient/index.js +51 -0
- package/build/builtins/coefficient/types.d.ts +5 -0
- package/build/builtins/coefficient/types.js +3 -0
- package/build/builtins/csv-lookup/index.d.ts +2 -0
- package/build/builtins/csv-lookup/index.js +181 -0
- package/build/builtins/divide/index.d.ts +2 -0
- package/build/builtins/divide/index.js +67 -0
- package/build/builtins/exponent/index.d.ts +3 -0
- package/build/builtins/exponent/index.js +72 -0
- package/build/builtins/exponent/types.d.ts +5 -0
- package/build/builtins/exponent/types.js +3 -0
- package/build/builtins/export-csv-raw.js +4 -1
- package/build/builtins/export-csv.js +4 -1
- package/build/builtins/export-log.js +4 -2
- package/build/builtins/export-yaml.js +4 -1
- package/build/builtins/index.d.ts +13 -0
- package/build/builtins/index.js +28 -2
- package/build/builtins/interpolation/index.d.ts +2 -0
- package/build/builtins/interpolation/index.js +146 -0
- package/build/builtins/interpolation/types.d.ts +5 -0
- package/build/builtins/interpolation/types.js +10 -0
- package/build/builtins/mock-observations/helpers/common-generator.d.ts +3 -0
- package/build/builtins/mock-observations/helpers/common-generator.js +32 -0
- package/build/builtins/mock-observations/helpers/rand-int-generator.d.ts +3 -0
- package/build/builtins/mock-observations/helpers/rand-int-generator.js +58 -0
- package/build/builtins/mock-observations/index.d.ts +3 -0
- package/build/builtins/mock-observations/index.js +116 -0
- package/build/builtins/mock-observations/interfaces/index.d.ts +6 -0
- package/build/builtins/mock-observations/interfaces/index.js +3 -0
- package/build/builtins/mock-observations/types.d.ts +13 -0
- package/build/builtins/mock-observations/types.js +3 -0
- package/build/builtins/multiply/index.d.ts +3 -0
- package/build/builtins/multiply/index.js +63 -0
- package/build/builtins/multiply/types.d.ts +4 -0
- package/build/builtins/multiply/types.js +3 -0
- package/build/builtins/regex/index.d.ts +3 -0
- package/build/builtins/regex/index.js +78 -0
- package/build/builtins/sci/config.d.ts +1 -0
- package/build/builtins/sci/config.js +44 -0
- package/build/builtins/sci/index.d.ts +3 -0
- package/build/builtins/sci/index.js +69 -0
- package/build/builtins/sci-embodied/index.d.ts +2 -0
- package/build/builtins/sci-embodied/index.js +115 -0
- package/build/builtins/shell/index.d.ts +3 -0
- package/build/builtins/shell/index.js +58 -0
- package/build/builtins/subtract/index.d.ts +3 -0
- package/build/builtins/subtract/index.js +75 -0
- package/build/builtins/subtract/types.d.ts +4 -0
- package/build/builtins/subtract/types.js +3 -0
- package/build/builtins/sum/index.d.ts +3 -0
- package/build/builtins/sum/index.js +61 -0
- package/build/builtins/sum/types.d.ts +4 -0
- package/build/builtins/sum/types.js +3 -0
- package/build/config/config.d.ts +8 -2
- package/build/config/config.js +34 -1
- package/build/config/strings.d.ts +22 -0
- package/build/config/strings.js +23 -1
- package/build/diff.d.ts +2 -0
- package/build/diff.js +41 -0
- package/build/index.js +8 -4
- package/build/lib/aggregate.js +5 -1
- package/build/lib/compare.d.ts +10 -0
- package/build/lib/compare.js +56 -0
- package/build/lib/compute.js +9 -1
- package/build/lib/environment.js +9 -3
- package/build/lib/exhaust.js +3 -2
- package/build/lib/initialize.js +5 -2
- package/build/lib/load.d.ts +48 -0
- package/build/lib/load.js +51 -2
- package/build/lib/parameterize.js +8 -4
- package/build/types/common.d.ts +4 -0
- package/build/types/common.js +3 -0
- package/build/types/helpers.d.ts +4 -0
- package/build/types/helpers.js +3 -0
- package/build/types/interface.d.ts +2 -1
- package/build/types/interface.js +1 -1
- package/build/types/lib/compare.d.ts +7 -0
- package/build/types/lib/compare.js +3 -0
- package/build/types/process-args.d.ts +7 -1
- package/build/types/process-args.js +1 -1
- package/build/types/util/args.d.ts +4 -0
- package/build/types/util/args.js +3 -0
- package/build/util/args.d.ts +7 -2
- package/build/util/args.js +49 -11
- package/build/util/debug-logger.d.ts +4 -0
- package/build/util/debug-logger.js +117 -0
- package/build/util/errors.d.ts +1 -1
- package/build/util/errors.js +6 -1
- package/build/util/helpers.d.ts +23 -0
- package/build/util/helpers.js +116 -2
- package/build/util/log-memoize.d.ts +1 -1
- package/build/util/log-memoize.js +1 -1
- package/build/util/validations.d.ts +59 -51
- package/build/util/validations.js +49 -18
- 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
- package/.env +0 -5
- package/coverage/clover.xml +0 -1590
- package/coverage/coverage-final.json +0 -50
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/builtins/coefficient/index.html +0 -116
- package/coverage/lcov-report/builtins/coefficient/index.ts.html +0 -295
- package/coverage/lcov-report/builtins/csv-lookup/index.html +0 -116
- package/coverage/lcov-report/builtins/csv-lookup/index.ts.html +0 -832
- package/coverage/lcov-report/builtins/divide/index.html +0 -116
- package/coverage/lcov-report/builtins/divide/index.ts.html +0 -361
- package/coverage/lcov-report/builtins/exponent/index.html +0 -116
- package/coverage/lcov-report/builtins/exponent/index.ts.html +0 -355
- package/coverage/lcov-report/builtins/export-csv-raw.ts.html +0 -553
- package/coverage/lcov-report/builtins/export-csv.ts.html +0 -433
- package/coverage/lcov-report/builtins/export-log.ts.html +0 -145
- package/coverage/lcov-report/builtins/export-yaml.ts.html +0 -184
- package/coverage/lcov-report/builtins/group-by.ts.html +0 -364
- package/coverage/lcov-report/builtins/index.html +0 -206
- package/coverage/lcov-report/builtins/index.ts.html +0 -130
- package/coverage/lcov-report/builtins/interpolation/index.html +0 -131
- package/coverage/lcov-report/builtins/interpolation/index.ts.html +0 -670
- package/coverage/lcov-report/builtins/interpolation/types.ts.html +0 -100
- package/coverage/lcov-report/builtins/mock-observations/helpers/common-generator.ts.html +0 -181
- package/coverage/lcov-report/builtins/mock-observations/helpers/index.html +0 -131
- package/coverage/lcov-report/builtins/mock-observations/helpers/rand-int-generator.ts.html +0 -295
- package/coverage/lcov-report/builtins/mock-observations/index.html +0 -116
- package/coverage/lcov-report/builtins/mock-observations/index.ts.html +0 -613
- package/coverage/lcov-report/builtins/multiply/index.html +0 -116
- package/coverage/lcov-report/builtins/multiply/index.ts.html +0 -337
- package/coverage/lcov-report/builtins/regex/index.html +0 -116
- package/coverage/lcov-report/builtins/regex/index.ts.html +0 -379
- package/coverage/lcov-report/builtins/sci/config.ts.html +0 -205
- package/coverage/lcov-report/builtins/sci/index.html +0 -116
- package/coverage/lcov-report/builtins/sci/index.ts.html +0 -331
- package/coverage/lcov-report/builtins/sci-embodied/index.html +0 -116
- package/coverage/lcov-report/builtins/sci-embodied/index.ts.html +0 -481
- package/coverage/lcov-report/builtins/shell/index.html +0 -116
- package/coverage/lcov-report/builtins/shell/index.ts.html +0 -283
- package/coverage/lcov-report/builtins/subtract/index.html +0 -116
- package/coverage/lcov-report/builtins/subtract/index.ts.html +0 -373
- package/coverage/lcov-report/builtins/sum/index.html +0 -116
- package/coverage/lcov-report/builtins/sum/index.ts.html +0 -340
- package/coverage/lcov-report/builtins/time-sync.ts.html +0 -1459
- package/coverage/lcov-report/config/config.ts.html +0 -334
- package/coverage/lcov-report/config/index.html +0 -161
- package/coverage/lcov-report/config/index.ts.html +0 -94
- package/coverage/lcov-report/config/params.ts.html +0 -697
- package/coverage/lcov-report/config/strings.ts.html +0 -415
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -386
- package/coverage/lcov-report/lib/aggregate.ts.html +0 -331
- package/coverage/lcov-report/lib/compare.ts.html +0 -283
- package/coverage/lcov-report/lib/compute.ts.html +0 -391
- package/coverage/lcov-report/lib/environment.ts.html +0 -343
- package/coverage/lcov-report/lib/exhaust.ts.html +0 -283
- package/coverage/lcov-report/lib/index.html +0 -221
- package/coverage/lcov-report/lib/initialize.ts.html +0 -388
- package/coverage/lcov-report/lib/load.ts.html +0 -268
- package/coverage/lcov-report/lib/parameterize.ts.html +0 -283
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/types/aggregation.ts.html +0 -94
- package/coverage/lcov-report/types/index.html +0 -146
- package/coverage/lcov-report/types/interface.ts.html +0 -181
- package/coverage/lcov-report/types/parameters.ts.html +0 -106
- package/coverage/lcov-report/util/aggregation-helper.ts.html +0 -286
- package/coverage/lcov-report/util/args.ts.html +0 -508
- package/coverage/lcov-report/util/errors.ts.html +0 -232
- package/coverage/lcov-report/util/helpers.ts.html +0 -613
- package/coverage/lcov-report/util/index.html +0 -266
- package/coverage/lcov-report/util/json.ts.html +0 -115
- package/coverage/lcov-report/util/log-memoize.ts.html +0 -145
- package/coverage/lcov-report/util/logger.ts.html +0 -151
- package/coverage/lcov-report/util/os-checker.ts.html +0 -421
- package/coverage/lcov-report/util/plugin-storage.ts.html +0 -199
- package/coverage/lcov-report/util/validations.ts.html +0 -526
- package/coverage/lcov-report/util/yaml.ts.html +0 -193
- package/coverage/lcov.info +0 -2811
- package/src/__tests__/integration/manifest/sci-e.yaml +0 -23
|
@@ -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`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Exponent
|
|
2
|
+
|
|
3
|
+
`exponent` is a generic plugin for calculating exponent of an input param (as base) and another (as the exponent) in an `input` array.
|
|
4
|
+
|
|
5
|
+
You provide the names of the values you want to use for the exponent calculation, and a name to use to add the exponent result to the output array.
|
|
6
|
+
|
|
7
|
+
For example, you use `cpu/energy` as base and `network/energy` as and name the result `energy`. `energy` would then be added to every observation in your input array as `cpu/energy` raised by the exponent `network/energy`.
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### Plugin config
|
|
12
|
+
|
|
13
|
+
Three parameters are required in global config: `input-parameter`, `exponent` and `output-parameter`.
|
|
14
|
+
|
|
15
|
+
`input-parameter`: a string defining the base. Must match an existing key in the `inputs` array
|
|
16
|
+
`exponent`: a number defining the exponent.
|
|
17
|
+
`output-parameter`: a string defining the name to use to add the result of the exponent to the output array.
|
|
18
|
+
|
|
19
|
+
### Inputs
|
|
20
|
+
|
|
21
|
+
`input-parameter` and `exponent` must be available in the input array.
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
- `output-parameter`: `input-parameter` raised by `exponent` with the parameter name defined by `output-parameter` in global config.
|
|
26
|
+
|
|
27
|
+
## Calculation
|
|
28
|
+
|
|
29
|
+
```pseudocode
|
|
30
|
+
output = input ^ exponent
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Implementation
|
|
34
|
+
|
|
35
|
+
To run the plugin, you must first create an instance of `Exponent`. Then, you can call `execute()`.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import {Exponent} from 'builtins';
|
|
39
|
+
|
|
40
|
+
const config = {
|
|
41
|
+
inputParameter: ['cpu/energy'],
|
|
42
|
+
exponent: 2
|
|
43
|
+
outputParameter: 'energy',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const exponent = Exponent(config);
|
|
47
|
+
const result = await exponent.execute([
|
|
48
|
+
{
|
|
49
|
+
duration: 3600,
|
|
50
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
51
|
+
'cpu/energy': 0.1,
|
|
52
|
+
'energy': 0.01,
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Example manifest
|
|
58
|
+
|
|
59
|
+
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 and does not have to be done explicitly by the user. The following is an example manifest that calls `exponent`:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
name: exponent demo
|
|
63
|
+
description:
|
|
64
|
+
tags:
|
|
65
|
+
initialize:
|
|
66
|
+
outputs:
|
|
67
|
+
- yaml
|
|
68
|
+
plugins:
|
|
69
|
+
exponent:
|
|
70
|
+
method: Exponent
|
|
71
|
+
path: 'builtin'
|
|
72
|
+
global-config:
|
|
73
|
+
input-parameter: 'cpu/energy'
|
|
74
|
+
exponent: 2
|
|
75
|
+
output-parameter: 'energy'
|
|
76
|
+
tree:
|
|
77
|
+
children:
|
|
78
|
+
child:
|
|
79
|
+
pipeline:
|
|
80
|
+
- exponent
|
|
81
|
+
config:
|
|
82
|
+
exponent:
|
|
83
|
+
inputs:
|
|
84
|
+
- timestamp: 2023-08-06T00:00
|
|
85
|
+
duration: 3600
|
|
86
|
+
cpu/energy: 0.001
|
|
87
|
+
network/energy: 0.001
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can run this example by saving it as `manifests/examples/test/exponent.yml` and executing the following command from the project root:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm i -g @grnsft/if
|
|
94
|
+
ie --manifest manifests/examples/test/exponent.yml --output manifests/outputs/exponent.yml
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The results will be saved to a new `yaml` file in `manifests/outputs`.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Interpolation Plugin
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Interpolation is a way to infer new data points from a previously known set of points.
|
|
6
|
+
This plugin provides the `y` value at a given `x` by interpolating between known points. You provide a set of known `x`s and `y`s and a target `x`, the plugin returns the `y` for your `x`.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
To employ the `Interpolation` plugin, adhere to these steps:
|
|
11
|
+
|
|
12
|
+
1. **Initialize Plugin**: Import the `Interpolation` function and initialize it with global configuration parameters `method`, `x`, `y`, `input-parameter` and `output-parameter`.
|
|
13
|
+
|
|
14
|
+
2. **Execute Plugin**: Invoke the `execute` method of the initialized plugin instance with an array of input parameters. Each input parameter should include a `timestamp`, `duration` and `[input-parameter]` information.
|
|
15
|
+
|
|
16
|
+
3. **Result**: The plugin will return an array of plugin parameters enriched with the calculated average carbon intensity for each input.
|
|
17
|
+
|
|
18
|
+
## Global Config
|
|
19
|
+
|
|
20
|
+
- `method`: specifies the interpolation method for the data. Acceptable values are 'linear', 'spline', or 'polynomial'. The default method is linear. (optional)
|
|
21
|
+
- `x`: array of x points. Numbers should be in ascending order (required).
|
|
22
|
+
- `y`: array of y points. Numbers should be in ascending order (required).
|
|
23
|
+
- `input-parameter`: a string defining the name to use its value to calculate the interpolation. It should match an existing key in the inputs array (required).
|
|
24
|
+
- `output-parameter`: a string defining the name to use to add the result of interpolation with additional calculation (required).
|
|
25
|
+
|
|
26
|
+
`x` and `y` arrays must be equal lengths.
|
|
27
|
+
|
|
28
|
+
## Input Parameters
|
|
29
|
+
|
|
30
|
+
The plugin expects the following input parameters:
|
|
31
|
+
|
|
32
|
+
- `timestamp`: a timestamp for the input (required)
|
|
33
|
+
- `duration`: the amount of time, in seconds, that the input covers. (required)
|
|
34
|
+
- `[input-parameter]` - a field whose name matches the string provided to input-parameter in global config (i.e. if the input-parameter in global config is cpu/utilisation then cpu-utilisation must exist in the input data)
|
|
35
|
+
|
|
36
|
+
## Output
|
|
37
|
+
|
|
38
|
+
The plugin outputs a value `z` that is the result of looking up the `y` value at `x = 'input-parameter'` using the user-defined interpolation method in `kWh` units. `z` is assigned to a field with a name defined by `output-parameter` in the output data.
|
|
39
|
+
|
|
40
|
+
## Error Handling
|
|
41
|
+
|
|
42
|
+
The plugin conducts input validation using the `zod` library and may throw errors if the provided parameters are invalid.
|
|
43
|
+
|
|
44
|
+
## Plugin Algorithm
|
|
45
|
+
|
|
46
|
+
1. **Execution**:
|
|
47
|
+
|
|
48
|
+
- Validate Global config
|
|
49
|
+
|
|
50
|
+
- `method` - validates if the method is one of these methods: `linear`, `spline`, or `polynomial`. If the method isn’t provided, it sets to `linear`.
|
|
51
|
+
- `x` and `y` should be arrays of numbers, the length should be equal, and elements should be ordered in the ascendant order.
|
|
52
|
+
- `input-parameter` - validates if the parameter is string.
|
|
53
|
+
- `output-parameter` - validates if the parameter is string.
|
|
54
|
+
|
|
55
|
+
- Iterate through each input, and do corresponding validation and calculation.
|
|
56
|
+
|
|
57
|
+
- Validate input parameters
|
|
58
|
+
|
|
59
|
+
- `duration` - validate if the duration is a number
|
|
60
|
+
- `timestamp` - should be in string or date format
|
|
61
|
+
- `[input-parameter]` - validates whether the parameter name is included in the input, and if its value should be a number within the range of x points.
|
|
62
|
+
|
|
63
|
+
- Calculation
|
|
64
|
+
|
|
65
|
+
- If the `method` is provided, choose the right way to calculate. For the `linear` and `polynomial` methods, calculate according to their formulas. For spline interpolation, use the npm module `typescript-cubic-spline`.
|
|
66
|
+
|
|
67
|
+
2. **Output**: Output the provided input along with the calculated `cpu/energy`
|
|
68
|
+
|
|
69
|
+
### TypeScript Usage
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const globalConfig = {
|
|
73
|
+
method: 'linear',
|
|
74
|
+
x: [0, 10, 50, 100],
|
|
75
|
+
y: [0.12, 0.32, 0.75, 1.02],
|
|
76
|
+
'input-parameter': 'cpu/utilization'
|
|
77
|
+
'output-parameter': 'cpu/energy'
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const interpolationPlugin = Interpolation(globalConfig);
|
|
82
|
+
|
|
83
|
+
const inputs = [
|
|
84
|
+
{
|
|
85
|
+
timestamp: '2024-04-16T12:00:00Z',
|
|
86
|
+
duration: 3600,
|
|
87
|
+
'cpu/utilization': 45
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
const results = interpolationPlugin.execute(inputs);
|
|
92
|
+
|
|
93
|
+
console.log(results);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Manifest Usage
|
|
97
|
+
|
|
98
|
+
#### Input
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
name: interpolation-demo
|
|
102
|
+
description: simple demo of interpolation plugin
|
|
103
|
+
tags:
|
|
104
|
+
initialize:
|
|
105
|
+
outputs:
|
|
106
|
+
- yaml
|
|
107
|
+
plugins:
|
|
108
|
+
interpolation:
|
|
109
|
+
method: Interpolation
|
|
110
|
+
path: 'builtin'
|
|
111
|
+
global-config:
|
|
112
|
+
method: linear
|
|
113
|
+
x: [0, 10, 50, 100]
|
|
114
|
+
y: [0.12, 0.32, 0.75, 1.02]
|
|
115
|
+
input-parameter: 'cpu/utilization'
|
|
116
|
+
output-parameter: 'cpu/energy'
|
|
117
|
+
tree:
|
|
118
|
+
children:
|
|
119
|
+
child:
|
|
120
|
+
pipeline:
|
|
121
|
+
- interpolation
|
|
122
|
+
inputs:
|
|
123
|
+
- timestamp: 2023-07-06T00:00
|
|
124
|
+
duration: 3600
|
|
125
|
+
cpu/utilization: 45
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Output
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
name: interpolation-demo
|
|
132
|
+
description: simple demo of interpolation plugin
|
|
133
|
+
tags:
|
|
134
|
+
initialize:
|
|
135
|
+
outputs:
|
|
136
|
+
- yaml
|
|
137
|
+
plugins:
|
|
138
|
+
interpolation:
|
|
139
|
+
method: Interpolation
|
|
140
|
+
path: 'builtin'
|
|
141
|
+
global-config:
|
|
142
|
+
method: linear
|
|
143
|
+
x: [0, 10, 50, 100]
|
|
144
|
+
y: [0.12, 0.32, 0.75, 1.02]
|
|
145
|
+
input-parameter: 'cpu/utilization'
|
|
146
|
+
output-parameter: 'cpu/energy'
|
|
147
|
+
tree:
|
|
148
|
+
children:
|
|
149
|
+
child:
|
|
150
|
+
pipeline:
|
|
151
|
+
- interpolation
|
|
152
|
+
inputs:
|
|
153
|
+
- timestamp: 2023-07-06T00:00
|
|
154
|
+
duration: 3600
|
|
155
|
+
cpu/utilization: 45
|
|
156
|
+
outputs:
|
|
157
|
+
- timestamp: 2023-07-06T00:00
|
|
158
|
+
duration: 3600
|
|
159
|
+
cpu/utilization: 45
|
|
160
|
+
cpu/energy: 0.00069625
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
You can execute this by passing it to `ie`. Run the impact using the following command from the project root:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
npm i -g @grnsft/if
|
|
167
|
+
ie --manifest ./manifests/examples/interpolation.yml --output ./manifests/outputs/interpolation.yml
|
|
168
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Mock Observations Plugin
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
A plugin for mocking observations (inputs) for testing and demo purposes
|
|
6
|
+
|
|
7
|
+
## Scope
|
|
8
|
+
|
|
9
|
+
The mode currently mocks 2 types of observation data:
|
|
10
|
+
|
|
11
|
+
- Common key-value pairs, that are generated statically and are the same for each generated observation/input (see 'helpers/CommonGenerator.ts')
|
|
12
|
+
- Randomly generated integer values for predefined keys (see 'helpers/RandIntGenerator.ts')
|
|
13
|
+
|
|
14
|
+
### Plugin global config
|
|
15
|
+
|
|
16
|
+
- `timestamp-from`, `timestamp-to` and `duration` define time buckets for which to generate observations.
|
|
17
|
+
- `generators` define which fields to generate for each observation
|
|
18
|
+
- `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.
|
|
19
|
+
|
|
20
|
+
### Authentication
|
|
21
|
+
|
|
22
|
+
N/A
|
|
23
|
+
|
|
24
|
+
### Inputs
|
|
25
|
+
|
|
26
|
+
The plugin's `global-config` section in the manifest file determines its behaviour.
|
|
27
|
+
'inputs' section is ignored.
|
|
28
|
+
|
|
29
|
+
### Typescript Usage
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const mockObservations = MockObservations({
|
|
33
|
+
'timestamp-from': '2023-07-06T00:00',
|
|
34
|
+
'timestamp-to': '2023-07-06T00:10',
|
|
35
|
+
duration: 60,
|
|
36
|
+
components: {
|
|
37
|
+
'instance-type': 'A1',
|
|
38
|
+
},
|
|
39
|
+
generators: {
|
|
40
|
+
common: {
|
|
41
|
+
region: 'uk-west',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const result = await mockObservations.execute([]);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### manifest Example
|
|
49
|
+
|
|
50
|
+
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 `mock-observation`:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
name: mock-observation-demo
|
|
54
|
+
description: example invoking mock-observation plugin
|
|
55
|
+
tags:
|
|
56
|
+
initialize:
|
|
57
|
+
outputs:
|
|
58
|
+
- yaml
|
|
59
|
+
plugins:
|
|
60
|
+
mock-observations:
|
|
61
|
+
kind: plugin
|
|
62
|
+
method: MockObservations
|
|
63
|
+
path: 'builtin'
|
|
64
|
+
global-config:
|
|
65
|
+
timestamp-from: 2023-07-06T00:00
|
|
66
|
+
timestamp-to: 2023-07-06T00:10
|
|
67
|
+
duration: 60
|
|
68
|
+
components:
|
|
69
|
+
- instance-type: A1
|
|
70
|
+
- instance-type: B1
|
|
71
|
+
generators:
|
|
72
|
+
common:
|
|
73
|
+
region: uk-west
|
|
74
|
+
common-key: common-val
|
|
75
|
+
randint:
|
|
76
|
+
cpu/utilization:
|
|
77
|
+
min: 1
|
|
78
|
+
max: 99
|
|
79
|
+
memory/utilization:
|
|
80
|
+
min: 1
|
|
81
|
+
max: 99
|
|
82
|
+
tree:
|
|
83
|
+
children:
|
|
84
|
+
child:
|
|
85
|
+
pipeline:
|
|
86
|
+
- mock-observations
|
|
87
|
+
inputs:
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can run this example `manifest` by saving it as `manifests/plugins/mock-observation.yml` and executing the following command from the project root:
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm i -g @grnsft/if
|
|
94
|
+
ie --manifest ./examples/manifests/test/mock-observation.yml --output ./examples/outputs/mock-observation
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Multiply
|
|
2
|
+
|
|
3
|
+
`multiply` is a generic plugin for multiplying two or more values in an `input` array.
|
|
4
|
+
|
|
5
|
+
You provide the names of the values you want to multiply, and a name to use to append the product to the output array.
|
|
6
|
+
|
|
7
|
+
For example, you could multiply `cpu/energy` and `network/energy` 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 `network/energy`.
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
### Plugin config
|
|
12
|
+
|
|
13
|
+
Two parameters are required in global config: `input-parameters` and `output-parameter`.
|
|
14
|
+
|
|
15
|
+
`input-parameters`: an array of strings. Each string should match an existing key in the `inputs` array
|
|
16
|
+
`output-parameter`: a string defining the name to use to add the product of the input parameters to the output array.
|
|
17
|
+
|
|
18
|
+
### Inputs
|
|
19
|
+
|
|
20
|
+
All of `input-parameters` must be available in the input array.
|
|
21
|
+
|
|
22
|
+
## Returns
|
|
23
|
+
|
|
24
|
+
- `output-parameter`: the product of all `input-parameters` with the parameter name defined by `output-parameter` in global config.
|
|
25
|
+
|
|
26
|
+
## Calculation
|
|
27
|
+
|
|
28
|
+
```pseudocode
|
|
29
|
+
output = input0 * input1 * input2 ... inputN
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Implementation
|
|
33
|
+
|
|
34
|
+
To run the plugin, you must first create an instance of `Multiply`. Then, you can call `execute()`.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import {Multiply} from 'builtins';
|
|
38
|
+
|
|
39
|
+
const config = {
|
|
40
|
+
inputParameters: ['cpu/energy', 'network/energy'],
|
|
41
|
+
outputParameter: 'energy-product',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const mult = Multiply(config);
|
|
45
|
+
const result = await mult.execute([
|
|
46
|
+
{
|
|
47
|
+
duration: 3600,
|
|
48
|
+
timestamp: '2021-01-01T00:00:00Z',
|
|
49
|
+
'cpu/energy': 0.001,
|
|
50
|
+
'memory/energy': 0.0005,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Example manifest
|
|
56
|
+
|
|
57
|
+
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 `multiply`:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
name: multiply-demo
|
|
61
|
+
description:
|
|
62
|
+
tags:
|
|
63
|
+
initialize:
|
|
64
|
+
outputs:
|
|
65
|
+
- yaml
|
|
66
|
+
plugins:
|
|
67
|
+
multiply:
|
|
68
|
+
method: Multiply
|
|
69
|
+
path: 'builtin'
|
|
70
|
+
global-config:
|
|
71
|
+
input-parameters: ['cpu/energy', 'network/energy']
|
|
72
|
+
output-parameter: 'energy-product'
|
|
73
|
+
tree:
|
|
74
|
+
children:
|
|
75
|
+
child:
|
|
76
|
+
pipeline:
|
|
77
|
+
- multiply
|
|
78
|
+
config:
|
|
79
|
+
multiply:
|
|
80
|
+
inputs:
|
|
81
|
+
- timestamp: 2023-08-06T00:00
|
|
82
|
+
duration: 3600
|
|
83
|
+
cpu/energy: 0.001
|
|
84
|
+
network/energy: 0.001
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
You can run this example by saving it as `./examples/manifests/test/multiply.yml` and executing the following command from the project root:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npm i -g @grnsft/if
|
|
91
|
+
ie --manifest ./examples/manifests/test/multiply.yml --output ./examples/outputs/multiply.yml
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The results will be saved to a new `yaml` file in `./examples/outputs`
|