Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit warning about node-level config #962

Merged
merged 11 commits into from
Aug 13, 2024
26 changes: 1 addition & 25 deletions Refactor-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,6 @@ There have also been some changes to the structure of manifest files. Some of th
allow-padding: true
```

- **Node level config**

We have also introduced the concept of node-level config. This is designed for pluin configuration that might vary between components in the tree. For example, for each child in the tree you might wish to use the `regroup` feature to group the outputs according to a different set of keys.

```yaml
tree:
children:
child-1:
pipeline:
compute:
- teads-curve
- sci-e
- sci-embodied
- sci-o
- time-sync
- sci
regroup:
- region
- cloud/instance-type
```

- **Defaults**

We have also introduced the concept of `defaults`. This is a section in each component's definition that can be used to provide fallbacks for missing input data. For example, perhaps you have a value arriving from an external API that should be present in every observation in your inputs array, but for soem reason the API fails to deliver a value for some timestamps. In this case, IF would fallback to the value provided for that metric in the `defaults` section of the manifest for that component.
Expand Down Expand Up @@ -226,10 +205,7 @@ Instead of the old class-based model, plugins are now functions. They conform to

```ts
export type PluginInterface = {
execute: (
inputs: PluginParams[],
config?: Record<string, any>
) => PluginParams[];
execute: (inputs: PluginParams[]) => PluginParams[];
metadata: {
kind: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ tree:
pipeline:
compute:
- coefficient
config:
sum:
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ tree:
pipeline:
compute:
- coefficient
config:
sum:
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
Expand Down
2 changes: 0 additions & 2 deletions manifests/examples/builtins/coefficient/success.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ tree:
pipeline:
compute:
- coefficient
config:
sum:
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tree:
pipeline:
compute:
- cloud-metadata
config:
inputs:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
cloud/vendor: aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tree:
pipeline:
compute:
- cloud-metadata
config:
inputs:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
cloud/vendor: gcp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tree:
pipeline:
compute:
- cloud-metadata
config:
inputs:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
#cloud/vendor: aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tree:
pipeline:
compute:
- cloud-metadata
config:
inputs:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
cloud/vendor: aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ tree:
pipeline:
compute:
- tdp-finder
config:
inputs:
- timestamp: 2023-07-06T00:00
duration: 300
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ tree:
pipeline:
compute:
- tdp-finder
config:
inputs:
- timestamp: 2023-07-06T00:00
duration: 300
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ tree:
pipeline:
compute:
- tdp-finder
config:
inputs:
- timestamp: 2023-07-06T00:00
duration: 300
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ tree:
compute:
- cloud-metadata
- divide
config:
divide:
defaults:
cloud/vendor: aws
cloud/instance-type: m5n.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ tree:
compute:
- cloud-metadata
- divide
config:
divide:
defaults:
cloud/vendor: aws
cloud/instance-type: m5n.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ tree:
compute:
- cloud-metadata
- divide
config:
divide:
defaults:
cloud/vendor: aws
cloud/instance-type: m5n.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ tree:
pipeline:
compute:
- sci
config:
sci:
functional-unit: 999 # factor to convert per time to per f.unit
defaults:
functional-unit: 999 # factor to convert per time to per f.unit
inputs:
- timestamp: 2023-07-06T00:00
duration: 3600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ tree:
pipeline:
compute:
- divide
config:
divide: null
defaults:
cloud/vendor: aws
cloud/instance-type: m5n.large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ tree:
pipeline:
compute:
- sci
config:
sci:
functional-unit: 999
defaults:
functional-unit: 999
inputs:
- timestamp: 2023-07-06T00:00
duration: 3600
Expand Down
1 change: 0 additions & 1 deletion manifests/outputs/pipelines/pipeline-teads-sci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ tree:
- operational-carbon
- sum-carbon
- sci
config: null
defaults:
cpu/thermal-design-power: 100
grid/carbon-intensity: 800
Expand Down
2 changes: 0 additions & 2 deletions src/__mocks__/builtins/export-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const tree = {
children: {
'child-1': {
pipeline: ['teads-curve', 'sum', 'sci-embodied', 'sci-o', 'sci'],
config: null,
defaults: {
'cpu/thermal-design-power': 100,
'grid/carbon-intensity': 800,
Expand Down Expand Up @@ -55,7 +54,6 @@ export const tree = {
},
'child-2': {
pipeline: ['teads-curve', 'sum', 'sci-embodied', 'sci-o', 'sci'],
config: null,
defaults: {
'cpu/thermal-design-power': 100,
'grid/carbon-intensity': 800,
Expand Down
7 changes: 3 additions & 4 deletions src/__mocks__/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ cpu-cores-available,cpu-cores-utilized,cpu-manufacturer,cpu-model-name,cpu-tdp,g
pipeline:
compute:
- boavizta-cpu
config:
boavizta-cpu:
core-units: 24
processor: Intel® Core™ i7-1185G7
defaults:
core-units: 24
processor: Intel® Core™ i7-1185G7
inputs:
- timestamp: 2023-07-06T00:00
duration: 3600 # Secs
Expand Down
1 change: 0 additions & 1 deletion src/__mocks__/mock-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ tree:
pipeline:
compute:
- memory-energy-from-memory-util
config: null
inputs:
- timestamp: 2023-12-12T00:00:00.000Z
duration: 3600
Expand Down
25 changes: 0 additions & 25 deletions src/__tests__/if-run/lib/compute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,6 @@ describe('lib/compute: ', () => {

expect(response.children.mockChild.outputs).toEqual(expectedResult);
});

it('computes simple tree with node config and execute plugin.', async () => {
const tree = {
children: {
mockChild: {
pipeline: {
compute: ['mock'],
},
config: {
'cpu/name': 'Intel CPU',
},
inputs: [
{timestamp: 'mock-timestamp-1', duration: 10},
{timestamp: 'mock-timestamp-2', duration: 10},
],
},
},
};
const response = await compute(tree, paramsExecute);
const expectedResult = mockExecutePlugin().execute(
tree.children.mockChild.inputs
);

expect(response.children.mockChild.outputs).toEqual(expectedResult);
});
});

it('computes simple tree with observe plugin.', async () => {
Expand Down
3 changes: 1 addition & 2 deletions src/if-env/config/env-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ initialize:
memory-energy-from-memory-util: # you can name this any way you like!
method: Coefficient # the name of the function exported from the plugin
path: "builtin" # the import path
global-config: # anmy config required by the plugin
global-config: # any config required by the plugin
input-parameter: "memory/utilization"
coefficient: 0.0001 #kwH/GB
output-parameter: "memory/energy"
Expand All @@ -16,7 +16,6 @@ tree:
pipeline: # the pipeline is an ordered list of plugins you want to execute
compute:
- memory-energy-from-memory-util # must match the name in initialize!
config: # any plugin specific, node-level config
inputs:
- timestamp: 2023-12-12T00:00:00.000Z # ISO 8061 string
duration: 3600 # units of seconds
Expand Down
25 changes: 12 additions & 13 deletions src/if-run/builtins/time-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ initialize:
method: TeadsCurve
path: '@grnsft/if-unofficial-plugins'
sci-e:
method: SciE
path: '@grnsft/if-plugins'
method: SciEmbodied
path: 'builtin'
sci-embodied:
path: 'builtin'
method: SciEmbodied
Expand All @@ -228,6 +228,7 @@ initialize:
start-time: '2023-12-12T00:00:00.000Z' # ISO timestamp
end-time: '2023-12-12T00:01:00.000Z' # ISO timestamp
interval: 5 # seconds
allow-padding: true
tree:
children:
child: # an advanced grouping node
Expand All @@ -238,19 +239,16 @@ tree:
- sci-embodied
- sci-o
- time-sync
config:
teads-curve:
cpu/thermal-design-power: 65
sci-embodied:
device/emissions-embodied: 251000 # gCO2eq
time-reserved: 3600 # 1 hour in s
device/expected-lifespan: 126144000 # 4 years in seconds
resources-reserved: 1
resources-total: 1
sci-o:
grid/carbon-intensity: 457 # gCO2/kwh
children:
child-1:
defaults:
device/emissions-embodied: 251000 # gCO2eq
time-reserved: 3600 # 1 hour in s
device/expected-lifespan: 126144000 # 4 years in seconds
resources-reserved: 1
resources-total: 1
grid/carbon-intensity: 457 # gCO2/kwh
cpu/thermal-design-power: 65
inputs:
- timestamp: '2023-12-12T00:00:00.000Z'
duration: 10
Expand All @@ -260,6 +258,7 @@ tree:
requests: 300
- timestamp: '2023-12-12T00:00:10.000Z'
duration: 10
cpu/thermal-design-power: 65
cpu/utilization: 20
carbon: 200
energy: 200
Expand Down
6 changes: 6 additions & 0 deletions src/if-run/config/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ ${error}`,
MISSING_GLOBAL_CONFIG: 'Global config is not provided.',
MISSING_INPUT_DATA: (param: string) =>
`${param} is missing from the input array, or has nullish value.`,
CONFIG_WARN: (plugins: string, isMore: boolean) =>
`You have included node-level config in your manifest to support \`${plugins}\` plugin${
isMore ? 's' : ''
}. IF no longer supports node-level config. \`${plugins}\` plugin${
isMore ? 's' : ''
} should be refactored to accept all its config from global config or input data.`,
};
20 changes: 18 additions & 2 deletions src/if-run/lib/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import {PluginParams} from '@grnsft/if-core/types';
import {Regroup} from './regroup';
import {addExplainData} from './explain';

import {mergeObjects} from '../util/helpers';
import {debugLogger} from '../../common/util/debug-logger';
import {logger} from '../../common/util/logger';

import {mergeObjects} from '../util/helpers';

import {STRINGS} from '../config/strings';

import {ComputeParams, Node, PhasedPipeline} from '../types/compute';
import {isExecute} from '../types/interface';

const {MERGING_DEFAULTS_WITH_INPUT_DATA, EMPTY_PIPELINE} = STRINGS;
const {MERGING_DEFAULTS_WITH_INPUT_DATA, EMPTY_PIPELINE, CONFIG_WARN} = STRINGS;

/**
* Traverses all child nodes based on children grouping.
Expand Down Expand Up @@ -65,6 +66,8 @@ const computeNode = async (node: Node, params: ComputeParams): Promise<any> => {
const defaults = node.defaults || params.defaults;
const noFlags = !params.observe && !params.regroup && !params.compute;

warnIfConfigProvided(node);

if (node.children) {
return traverse(node.children, {
...params,
Expand Down Expand Up @@ -157,6 +160,19 @@ const computeNode = async (node: Node, params: ComputeParams): Promise<any> => {
}
};

/**
* Warns if the `config` is provided in the manifest.
*/
const warnIfConfigProvided = (node: any) => {
if ('config' in node) {
const plugins = Object.keys(node.config);
const joinedPlugins = plugins.join(', ');
const isMore = plugins.length > 1;

logger.warn(CONFIG_WARN(joinedPlugins, isMore));
}
};

/**
* Creates copy of existing tree, then applies computing strategy.
*/
Expand Down
Loading