Skip to content

Commit f1039f9

Browse files
Merge pull request #1038 from Green-Software-Foundation/release-v0.7.0-beta.0
Release v0.7.0-beta.0
2 parents 57ed30e + 44ce841 commit f1039f9

File tree

243 files changed

+8928
-6945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+8928
-6945
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Refactor-migration-guide.md

Lines changed: 68 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -105,45 +105,24 @@ There have also been some changes to the structure of manifest files. Some of th
105105
method: SciEmbodied
106106
```
107107
108-
- **Global config**
109-
We have introduced the concept of global config to the plugins. This is truly global configuration data that should be kept constant regardless of where the plugin is invoked across the manifest file.
108+
- **Config**
109+
We have introduced the concept of config to the plugins. This is truly configuration data that should be kept constant regardless of where the plugin is invoked across the manifest file.
110110
111-
A good example is the `interpolation` method to use in the Teads curve plugin - this is not expected to vary from component to component and can therefore be defined in global config. The plugin code itself must expect the global config. Then, the config can be passed in the `Initialize` block, for example:
111+
A good example is the `interpolation` method to use in the Teads curve plugin - this is not expected to vary from component to component and can therefore be defined in config. The plugin code itself must expect the config. Then, the config can be passed in the `Initialize` block, for example:
112112
113113
```yaml
114114
initialize:
115115
plugins:
116116
'time-sync':
117117
method: TimeSync
118118
path: 'builtin'
119-
global-config:
119+
config:
120120
start-time: '2023-12-12T00:00:00.000Z'
121121
end-time: '2023-12-12T00:01:00.000Z'
122122
interval: 5
123123
allow-padding: true
124124
```
125125
126-
- **Node level config**
127-
128-
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.
129-
130-
```yaml
131-
tree:
132-
children:
133-
child-1:
134-
pipeline:
135-
compute:
136-
- teads-curve
137-
- sci-e
138-
- sci-embodied
139-
- sci-o
140-
- time-sync
141-
- sci
142-
regroup:
143-
- region
144-
- cloud/instance-type
145-
```
146-
147126
- **Defaults**
148127
149128
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.
@@ -178,15 +157,15 @@ There have also been some changes to the structure of manifest files. Some of th
178157
179158
Technically time-sync is not a new feature as it was present in IF before the refactor, but there are some tweaks to how the plugin is configured that are worth explaining here. Time sync snaps all input arrays across an entire graph to a common time grid.
180159
181-
This means you have to define a global start time, end time and interval to use everywhere. There is also a boolean to toggle whether you should allow the time sync model to pad the start and end of your time series with zeroes. You should default to `true` unless you have a specific reason not to. In the refactored IF we expect this information to be provided in global config, as follows:
160+
This means you have to define a start time, end time and interval to use everywhere. There is also a boolean to toggle whether you should allow the time sync model to pad the start and end of your time series with zeroes. You should default to `true` unless you have a specific reason not to. In the refactored IF we expect this information to be provided in config, as follows:
182161
183162
```yaml
184163
initialize:
185164
plugins:
186165
'time-sync':
187166
method: TimeSync
188167
path: 'builtin'
189-
global-config:
168+
config:
190169
start-time: '2023-12-12T00:00:00.000Z'
191170
end-time: '2023-12-12T00:01:00.000Z'
192171
interval: 5
@@ -220,68 +199,75 @@ Details tbc...
220199
221200
## Plugins
222201
223-
The plugins themselves require some changes to keep them compatible with the refactored IF.
202+
Plugins require some modifications to remain compatible with the refactored IF interface.
224203
225-
Instead of the old class-based model, plugins are now functions. They conform to the following interface:
204+
Each plugin follows the `PluginFactory` interface, which is a higher-order function that accepts a `params` object of type `PluginFactoryParams`. This function returns another function (the inner function), which handles the plugin’s `config`, `parametersMetadata`, and `mapping`.
226205
227206
```ts
228-
export type PluginInterface = {
229-
execute: (
230-
inputs: PluginParams[],
231-
config?: Record<string, any>
232-
) => PluginParams[];
233-
metadata: {
234-
kind: string;
235-
};
236-
[key: string]: any;
237-
};
207+
export const PluginFactory =
208+
(params: PluginFactoryParams) =>
209+
(
210+
config: ConfigParams = {},
211+
parametersMetadata: PluginParametersMetadata,
212+
mapping: MappingParams
213+
) => ({
214+
metadata: {
215+
inputs: {...params.metadata.inputs, ...parametersMetadata?.inputs},
216+
outputs: parametersMetadata?.outputs || params.metadata.outputs,
217+
},
218+
execute: async (inputs: PluginParams[]) => {
219+
// Generic plugin functionality goes here
220+
// E.g., mapping, arithmetic operations, validation
221+
// Process inputs and mapping logic
222+
});
223+
})
238224
```
239225
240-
The plugin still requires an execute function. This is where you implement the plugin logic.
226+
Inner Function Parameters:
227+
228+
- `config`: This is of type `ConfigParams` and has a default value of an empty object ({}). This might hold configuration settings for the plugin.
229+
- `parametersMetadata`: A `PluginParametersMetadata` object that describes the metadata for the plugin’s parameters.
230+
- `mapping`: A `MappingParams` object, describing parameters are mapped.
231+
232+
Implementation Function:
241233
242-
Here's a minimal example for a plugin that sums some inputs defined in global config - see inline comments for some important notes:
234+
The plugin requires an `implementation` function, where the actual plugin logic is defined.
235+
Here’s a minimal example of a plugin that sums inputs as defined in the config. See the inline comments for further clarification.
243236
244237
```ts
245-
// Here's the function definition - notice that global config is passed in here!
246-
export const Sum = (globalConfig: SumConfig): PluginInterface => {
247-
const inputParameters = globalConfig['input-parameters'] || [];
248-
const outputParameter = globalConfig['output-parameter'];
249-
250-
// we also return metadata now too - you can add more or just use this default
251-
const metadata = {
252-
kind: 'execute',
253-
};
254-
255-
/**
256-
* Calculate the sum of the input metrics for each timestamp.
257-
*/
258-
const execute = async (inputs: PluginParams[]): Promise<PluginParams[]> => {
259-
inputs.map(input => {
260-
return calculateSum(input, inputParameters, outputParameter);
238+
// Here's the function definition!
239+
export const Sum = PluginFactory({
240+
configValidation: z.object({
241+
'input-parameters': z.array(z.string()),
242+
'output-parameter': z.string().min(1),
243+
}),
244+
inputValidation: (input: PluginParams, config: ConfigParams) => {
245+
return validate(validationSchema, inputData);
246+
},
247+
implementation: async (inputs: PluginParams[], config: ConfigParams) => {
248+
const {
249+
'input-parameters': inputParameters,
250+
'output-parameter': outputParameter,
251+
} = config;
252+
253+
return inputs.map(input => {
254+
const calculatedResult = calculateSum(input, inputParameters);
255+
256+
return {
257+
...input,
258+
[outputParameter]: calculatedResult,
259+
};
261260
});
262-
return inputs;
263-
};
264-
265-
/**
266-
* Calculates the sum of the energy components.
267-
*/
268-
const calculateSum = (
269-
input: PluginParams,
270-
inputParameters: string[],
271-
outputParameter: string
272-
) => {
273-
input[outputParameter] = inputParameters.reduce(
274-
(accumulator, metricToSum) => {
275-
return accumulator + input[metricToSum];
276-
},
277-
0
278-
);
279-
};
280-
281-
// return the metadata and the execute function
282-
return {
283-
metadata,
284-
execute,
285-
};
286-
};
261+
},
262+
allowArithmeticExpressions: [],
263+
});
264+
265+
/**
266+
* Calculates the sum of the energy components.
267+
*/
268+
const calculateSum = (input: PluginParams, inputParameters: string[]) =>
269+
inputParameters.reduce(
270+
(accumulator, metricToSum) => accumulator + input[metricToSum],
271+
0
272+
);
287273
```

github-processes.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@
33

44
- [`if`](https://github.com/Green-Software-Foundation/if)
55
- source code for the IF
6+
- [`if-core`](https://github.com/Green-Software-Foundation/if-core)
7+
- helper types, interfaces and utilities for IF and plugin development
68
- [`if-plugins`](https://github.com/Green-Software-Foundation/if-plugins) **DEPRECATED**
79
- source code for standard library of plugins
810
- IF core team commit to maintaining these plugins
9-
- [`if-unofficial-plugins`](https://github.com/Green-Software-Foundation/if-unofficial-plugins)
11+
- [`if-unofficial-plugins`](https://github.com/Green-Software-Foundation/if-unofficial-plugins) **DEPRECATED**
1012
- source code for plugins relying on third-party data/APIs
1113
- intended to be deprecated and removed in mid-term future
1214
- plugins in this repo should be handed over to relevant organizations to maintain
1315
- [`if-plugin-template`](https://github.com/Green-Software-Foundation/if-plugin-template)
1416
- template for new plugins
1517
- intended for builders to bootstrap IF-compatible plugin development
16-
- [`if-standards`](https://github.com/Green-Software-Foundation/if-standards)
17-
- not currently used, but intended to be the home of params.ts
18-
- will have a dedicated discussion board and governance to set IF standards
19-
- [`if-exhaust plugins`](https://github.com/Green-Software-Foundation/if-exhaust-plugins)
20-
- not currently used
21-
- intended to become a separate repo just for exhaust plugins
22-
- requires strict rules from if
23-
2418

2519
## Branch names and purposes
2620

grafana/IF_GRAFANA_SETUP.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)