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

Send proper data to boavizta API #45

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/__tests__/unit/lib/boavizta/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ describe('lib/boavizta: ', () => {
])
).toStrictEqual([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 15,
'cpu/utilization': 34,
'instance-type': 't2.micro',
country: 'USA',
provider: 'aws',
'carbon-embodied': 1.6,
energy: 1.6408333333333334,
},
Expand Down
78 changes: 68 additions & 10 deletions src/lib/boavizta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@ Boavizta exposes a [REST API](https://doc.api.boavizta.org/). If the `boavizta`

### Inputs

- `cpu/name`: the name of the physical processor being used
- `cpu/number-cores`: number of physical cores on a CPU
- `cpu/expected-lifespan`: the lifespan of the component, in seconds
- `cpu/name`: the name of the physical processor being used (required for `BoaviztaCpuOutput`)
- `cpu/number-cores`: number of physical cores on a CPU (required for `BoaviztaCpuOutput`)
- `cpu/expected-lifespan`: the lifespan of the component, in seconds (optional)
- `country`: the country used to lookup grid carbon intensity, e.g. "USA" (optional - falls back to Boavizta default)
- `cpu/utilization`: percentage CPU utilization for a given observation
- `instance-type`: the name of the specific instance
- `cpu/utilization`: percentage CPU utilization for a given observation (required)
- `instance-type`: the name of the specific instance (required for `BoaviztaCloudOutput`, optional for `BoaviztaCpuOutput`)
- `provider`: the name of cloud provider (required for `BoaviztaCloudOutput`)

## Returns

- `carbon-embodied`: carbon emitted in manufacturing the device, in gCO2eq
- `cpu/energy`: energy used by CPU in kWh

## Usage
## Usage for `BoaviztaCpuOutput`

To run the `boavista-cpu` plugin an instance of `BoaviztaCpuImpact` must be created using `BoaviztaCpuImpact()` and, if applicable, passing global configurations. Subsequently, the `execute()` function can be invoked to retrieve data on `carbon-embodied` and `cpu/energy`.
To run the `boavista-cpu` plugin an instance of `BoaviztaCpuOutput` must be created using `BoaviztaCpuOutput()` and, if applicable, passing global configurations. Subsequently, the `execute()` function can be invoked to retrieve data on `carbon-embodied` and `cpu/energy`.

This is how you could run the plugin in Typescript:

```typescript
import {BoaviztaCpuImpact} from '@grnsft/if-unofficial-plugins';
import {BoaviztaCpuOutput} from '@grnsft/if-unofficial-plugins';

const output = BoaviztaCpuImpact({});
const usage = await output.calculate([
const output = BoaviztaCpuOutput({});
const usage = await output.execute([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 1,
Expand Down Expand Up @@ -115,3 +116,60 @@ npm i -g @grnsft/if
npm i -g @grnsft/if-unofficial-plugins
ie --manifest ./examples/manifests/test/boavizta.yml --output ./examples/outputs/boavizta.yml
```

## Usage for `BoaviztaCloudOutput`

To run the `boavista-cloud` plugin an instance of `BoaviztaCloudOutput` must be created using `BoaviztaCloudOutput()` and, if applicable, passing global configurations. Subsequently, the `execute()` function can be invoked to retrieve data on `carbon-embodied` and `cpu/energy`.

This is how you could run the plugin in Typescript:

```typescript
import {BoaviztaCloudOutput} from '@grnsft/if-unofficial-plugins';

const output = BoaviztaCloudOutput({});
const usage = await output.execute([
{
timestamp: '2021-01-01T00:00:00Z',
duration: 15,
'cpu/utilization': 34,
'instance-type': 't2.micro',
country: 'USA',
provider: 'aws',
},
]);
```

## Example `manifest`

In IF plugins are expected to be invoked from an `manifest` file. This is a yaml containing the plugin configuration and inputs. The following `manifest` initializes and runs the `boavizta-cloud` plugin:

```yaml
name: boavizta cloud demo
description: calls boavizta api
tags:
initialize:
plugins:
'boavizta-cloud':
method: BoaviztaCloudOutput
path: '@grnsft/if-unofficial-plugins'
tree:
children:
child:
pipeline:
- boavizta-cloud
defaults:
instance-type: r6g.medium
provider: aws
inputs:
- timestamp: '2021-01-01T00:00:00Z'
duration: 15 # Secs
cpu/utilization: 34
```

You can run this by passing it to `ie`. Run impact using the following command run from the project root:

```sh
npm i -g @grnsft/if
npm i -g @grnsft/if-unofficial-plugins
ie --manifest ./examples/manifests/test/boavizta-cloud.yml --output ./examples/outputs/boavizta-cloud.yml
```
7 changes: 6 additions & 1 deletion src/lib/boavizta/boavizta-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export const BoaviztaAPI = () => {
componentType: string,
verbose: boolean
): Promise<object> => {
const dataCast = {
core_units: data['cpu/number-cores'],
name: data['cpu/name'],
tdp: data['cpu/thermal-design-power'],
};
const response = await axios.post(
`${BASE_URL}/component/${componentType}?verbose=${verbose}&duration=${data['usage']['hours_use_time']}`,
data
dataCast
);

return response.data;
Expand Down
5 changes: 4 additions & 1 deletion src/lib/boavizta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ export const BoaviztaCloudOutput = (
fetchData
);

result.push(usageResult);
result.push({
...input,
...usageResult,
});
}

return result;
Expand Down
Loading