Skip to content

Commit

Permalink
Merge pull request #908 from Green-Software-Foundation/remove-overrid…
Browse files Browse the repository at this point in the history
…e-params

Remove `params.ts` file and `override-params` section from the manifest
  • Loading branch information
narekhovhannisyan committed Jul 16, 2024
2 parents 3ea46b3 + 6dd3984 commit 55276c9
Show file tree
Hide file tree
Showing 40 changed files with 206 additions and 628 deletions.
5 changes: 4 additions & 1 deletion Refactor-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,17 @@ This is a builtin feature of IF, meaning it does not have to be initialized as a
- `metrics`: which metrics do you want to aggregate? Every metric you provide here must exist in the output array.
- `method`: the aggregation method for the specied metric
- `type`: the options are `horizontal`, `vertical` or both. Horizontal aggregation is the type that condenses each time series into a single summary value. Vertical aggregation is aggregated across components.
Here's what the config block should look like:
```yaml
aggregation:
metrics:
- 'carbon'
'carbon':
method: 'sum'
type: 'both'
```
Expand Down
4 changes: 2 additions & 2 deletions manifests/examples/pipelines/nesting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ tags:
category: on-premise
aggregation:
metrics:
- "carbon"
"carbon":
method: sum
type: "both"
params:
initialize:
plugins:
"interpolate":
Expand Down
11 changes: 6 additions & 5 deletions manifests/examples/pipelines/pipeline-with-aggregate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ description: a full pipeline with the aggregate feature enabled
tags:
aggregation:
metrics:
- "carbon"
"carbon":
method: sum
type: "both"
initialize:
plugins:
"interpolate":
method: Interpolation
path: 'builtin'
path: "builtin"
global-config:
method: linear
x: [0, 10, 50, 100]
y: [0.12, 0.32, 0.75, 1.02]
input-parameter: 'cpu/utilization'
output-parameter: 'cpu-factor'
input-parameter: "cpu/utilization"
output-parameter: "cpu-factor"
"cpu-factor-to-wattage":
method: Multiply
path: builtin
Expand Down Expand Up @@ -182,4 +183,4 @@ tree:
cpu/utilization: 33
cloud/instance-type: A1
cloud/region: uk-west
requests: 180
requests: 180
3 changes: 2 additions & 1 deletion manifests/examples/pipelines/pipeline-with-mocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ description: a full pipeline seeded with data from mock-observations feature
tags:
aggregation:
metrics:
- "carbon"
"carbon":
method: sum
type: "both"
initialize:
plugins:
Expand Down
3 changes: 2 additions & 1 deletion manifests/outputs/bugs/aggregation-error-wrong-metric.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description: >-
tags: null
aggregation:
metrics:
- dummy-param
"dummy-param":
method: sum
type: both
initialize:
plugins:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Aggregation
description: Fails with invalid metric.
aggregation:
metrics:
- test
"test":
method: sum
type: both
initialize:
plugins:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Aggregation
description: Fails with missing metric in inputs.
aggregation:
metrics:
- cpu/utilization
"cpu/utilization":
method: sum
type: both
initialize:
plugins:
Expand Down
3 changes: 2 additions & 1 deletion manifests/outputs/features/aggregate-horizontal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Aggregation
description: Apply `horizontal` aggregation
aggregation:
metrics:
- cpu/utilization
"cpu/utilization":
method: sum
type: horizontal
initialize:
plugins:
Expand Down
3 changes: 2 additions & 1 deletion manifests/outputs/features/aggregate-vertical.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Aggregation
description: Apply `vertical` aggregation
aggregation:
metrics:
- cpu/utilization
"cpu/utilization":
method: sum
type: vertical
initialize:
plugins:
Expand Down
3 changes: 2 additions & 1 deletion manifests/outputs/features/aggregate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Aggregation
description: Apply both `horizontal` and `vertical` aggregations
aggregation:
metrics:
- cpu/utilization
"cpu/utilization":
method: sum
type: both
initialize:
plugins:
Expand Down
2 changes: 1 addition & 1 deletion src/__mocks__/builtins/export-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ export const aggregated = {
};

export const aggregation = {
metrics: ['carbon'],
metrics: {carbon: {method: 'sum'}},
type: 'both',
};
20 changes: 0 additions & 20 deletions src/__mocks__/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,7 @@ export const readFile = async (filePath: string) => {
return fs.readFileSync(updatedPath, 'utf8');
}

/** mock for util/json */
if (filePath.includes('json-reject')) {
return Promise.reject(new Error('rejected'));
}

if (filePath.includes('json')) {
if (filePath.includes('param')) {
return JSON.stringify({
'mock-carbon': {
description: 'an amount of carbon emitted into the atmosphere',
unit: 'gCO2e',
aggregation: 'sum',
},
'mock-cpu': {
description: 'number of cores available',
unit: 'cores',
aggregation: 'none',
},
});
}

return JSON.stringify(filePath);
}

Expand Down
14 changes: 0 additions & 14 deletions src/__mocks__/json.ts

This file was deleted.

35 changes: 2 additions & 33 deletions src/__tests__/common/lib/load.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
jest.mock('../../../if-run/util/json', () =>
require('../../../__mocks__/json')
);
jest.mock(
'mockavizta',
() => ({
Expand Down Expand Up @@ -42,45 +39,17 @@ jest.mock('../../../common/util/yaml', () => ({

import {PluginParams} from '@grnsft/if-core/types';

import {PARAMETERS} from '../../../if-run/config';
import {load} from '../../../common/lib/load';

describe('lib/load: ', () => {
describe('load(): ', () => {
it('loads yaml with default parameters.', async () => {
const inputPath = 'load-default.yml';
const paramPath = undefined;

const result = await load(inputPath, paramPath);

const expectedValue = {
rawManifest: 'raw-manifest',
parameters: PARAMETERS,
};

expect(result).toEqual(expectedValue);
});

it('loads yaml with custom parameters.', async () => {
it('successfully loads yaml.', async () => {
const inputPath = 'load-default.yml';
const paramPath = 'param-mock.json';

const result = await load(inputPath, paramPath);
const result = await load(inputPath);

const expectedValue = {
rawManifest: 'raw-manifest',
parameters: {
'mock-carbon': {
description: 'an amount of carbon emitted into the atmosphere',
unit: 'gCO2e',
aggregation: 'sum',
},
'mock-cpu': {
description: 'number of cores available',
unit: 'cores',
aggregation: 'none',
},
},
};

expect(result).toEqual(expectedValue);
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/if-diff/lib/load.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
jest.mock('../../../if-run/util/json', () =>
require('../../../__mocks__/json')
);
jest.mock(
'mockavizta',
() => ({
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/if-run/builtins/time-sync.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {ERRORS} from '@grnsft/if-core/utils';
import {Settings, DateTime} from 'luxon';

import {AggregationParams} from '../../../common/types/manifest';

import {storeAggregateMetrics} from '../../../if-run/lib/aggregate';
import {TimeSync} from '../../../if-run/builtins/time-sync';

import {STRINGS} from '../../../if-run/config';
Expand Down Expand Up @@ -51,6 +54,20 @@ jest.mock('luxon', () => {
});

describe('builtins/time-sync:', () => {
beforeAll(() => {
const metricStorage: AggregationParams = {
metrics: {
carbon: {method: 'sum'},
'cpu/utilization': {method: 'sum'},
'time-reserved': {method: 'avg'},
'resources-total': {method: 'none'},
},
type: 'horizontal',
};

storeAggregateMetrics(metricStorage);
});

describe('time-sync: ', () => {
const basicConfig = {
'start-time': '2023-12-12T00:01:00.000Z',
Expand Down
21 changes: 17 additions & 4 deletions src/__tests__/if-run/lib/aggregate.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import {aggregate} from '../../../if-run/lib/aggregate';
import {AggregationParams} from '../../../common/types/manifest';

import {aggregate, storeAggregateMetrics} from '../../../if-run/lib/aggregate';

describe('lib/aggregate: ', () => {
beforeAll(() => {
const metricStorage: AggregationParams = {
metrics: {
carbon: {method: 'sum'},
},
type: 'horizontal',
};

storeAggregateMetrics(metricStorage);
});

describe('aggregate(): ', () => {
it('returns tree if aggregation is missing.', () => {
const tree = {};
Expand Down Expand Up @@ -44,7 +57,7 @@ describe('lib/aggregate: ', () => {
};

const aggregatedTree = aggregate(tree, {
metrics: ['carbon'],
metrics: {carbon: {method: 'sum'}},
type: 'horizontal',
});
const expectedAggregated = {
Expand Down Expand Up @@ -92,7 +105,7 @@ describe('lib/aggregate: ', () => {
};

const aggregatedTree = aggregate(tree, {
metrics: ['carbon'],
metrics: {carbon: {method: 'sum'}},
type: 'vertical',
});
const expectedOutputs = [
Expand Down Expand Up @@ -153,7 +166,7 @@ describe('lib/aggregate: ', () => {
};

const aggregatedTree = aggregate(tree, {
metrics: ['carbon'],
metrics: {carbon: {method: 'sum'}},
type: 'both',
});

Expand Down
Loading

0 comments on commit 55276c9

Please sign in to comment.