Skip to content

Commit

Permalink
chore(src): fetch changes from main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Jul 17, 2024
2 parents 7bb370b + 55276c9 commit a8fcb3e
Show file tree
Hide file tree
Showing 58 changed files with 850 additions and 714 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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"if-diff": "./build/if-diff/index.js",
"if-run": "./build/if-run/index.js",
"if-env": "./build/if-env/index.js",
"if-check": "./build/if-check/index.js"
"if-check": "./build/if-check/index.js",
"if-csv": "./build/if-csv/index.js"
},
"bugs": {
"url": "https://github.com/Green-Software-Foundation/if/issues/new?assignees=&labels=feedback&projects=&template=feedback.md&title=Feedback+-+"
Expand Down Expand Up @@ -76,6 +77,7 @@
"fix": "gts fix",
"fix:package": "fixpack",
"if-check": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-check/index.ts",
"if-csv": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-csv/index.ts",
"if-diff": "npx ts-node src/if-diff/index.ts",
"if-env": "cross-env CURRENT_DIR=$(node -p \"process.env.INIT_CWD\") npx ts-node src/if-env/index.ts",
"if-run": "npx ts-node src/if-run/index.ts",
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.

37 changes: 3 additions & 34 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 All @@ -14,7 +11,7 @@ jest.mock(
}),
{virtual: true}
);
jest.mock('../../../if-diff/util/helpers', () => ({
jest.mock('../../../common/util/helpers', () => ({
parseManifestFromStdin: () => {
if (process.env.readline === 'valid-source') {
return `
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
44 changes: 44 additions & 0 deletions src/__tests__/common/util/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
jest.mock('node:readline/promises', () =>
require('../../../__mocks__/readline')
);

import {parseManifestFromStdin} from '../../../common/util/helpers';

describe('common/util/helpers: ', () => {
describe('parseManifestFromStdin(): ', () => {
it('returns empty string if there is no data in stdin.', async () => {
const response = await parseManifestFromStdin();
const expectedResult = '';

expect(response).toEqual(expectedResult);
});

it('returns empty string if nothing is piped.', async () => {
const originalIsTTY = process.stdin.isTTY;
process.stdin.isTTY = true;
const response = await parseManifestFromStdin();
const expectedResult = '';

expect(response).toEqual(expectedResult);
process.stdin.isTTY = originalIsTTY;
});

it('throws error if there is no manifest in stdin.', async () => {
process.env.readline = 'no_manifest';
expect.assertions(1);

const response = await parseManifestFromStdin();

expect(response).toEqual('');
});

it('returns empty string if there is no data in stdin.', async () => {
process.env.readline = 'manifest';
const response = await parseManifestFromStdin();
const expectedMessage =
'\nname: mock-name\ndescription: mock-description\n';

expect(response).toEqual(expectedMessage);
});
});
});
Loading

0 comments on commit a8fcb3e

Please sign in to comment.