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

Dump logs errors #691

Merged
merged 21 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9b15ee3
feat(src): implement error writing strategy
narekhovhannisyan May 1, 2024
2b66257
test(lib): fix typo in initialize
narekhovhannisyan May 1, 2024
6f244b9
feat(types): add status and error to execution
narekhovhannisyan May 1, 2024
1d5df3b
test(lib): fix typo in initialize
narekhovhannisyan May 1, 2024
cd1af79
feat(lib): add execution status to inject env
narekhovhannisyan May 1, 2024
7e74afb
fix(util): tune manifest validation
narekhovhannisyan May 8, 2024
638451b
fix(types): remove manually declared types
narekhovhannisyan May 8, 2024
430fb33
fix(util): tune manifest validation
narekhovhannisyan May 8, 2024
1fe6a3f
fix(lib): return raw manifest in response
narekhovhannisyan May 8, 2024
9376c54
fix(lib): env return type
narekhovhannisyan May 8, 2024
349d482
test(lib): fix load cases
narekhovhannisyan May 8, 2024
5d72e99
test(mocks): tune export csv
narekhovhannisyan May 8, 2024
1edbed6
fix(src): tune impact engine strategy
narekhovhannisyan May 8, 2024
33cd1a0
chore(src): pull changes from main
narekhovhannisyan May 8, 2024
85190d3
feat(util): add exhaust error to errors
narekhovhannisyan May 8, 2024
1780c40
feat(lib): introduce exhaust error
narekhovhannisyan May 8, 2024
c109ffe
fix(builtins): introduce exhaust error to builtins
narekhovhannisyan May 8, 2024
88338db
test(lib): use exhaust error
narekhovhannisyan May 8, 2024
e1faafc
test(lib): remove console.log
narekhovhannisyan May 8, 2024
22ca3b6
test(builtins): change errors to exhaust
narekhovhannisyan May 8, 2024
6185ee0
feat(src): handle exhaust errors
narekhovhannisyan May 8, 2024
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
2 changes: 2 additions & 0 deletions src/__mocks__/builtins/export-csv.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {Context} from '../../types/manifest';

export const tree = {
Expand Down Expand Up @@ -117,6 +118,7 @@ export const tree = {
},
};

// @ts-ignore
export const context: Context = {
name: 'demo',
description: '',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/unit/builtins/export-csv-raw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ERRORS} from '../../../util/errors';

import {tree, context, outputs} from '../../../__mocks__/builtins/export-csv';

const {CliInputError, WriteFileError} = ERRORS;
const {ExhaustError} = ERRORS;

jest.mock('fs/promises', () => ({
__esModule: true,
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('builtins/export-csv-raw: ', () => {
await expect(
exportCSVRaw.execute(tree, context, outputPath)
).rejects.toThrow(
new WriteFileError(
new ExhaustError(
'Failed to write CSV to output#carbon: Could not write CSV file.'
)
);
Expand All @@ -65,8 +65,8 @@ describe('builtins/export-csv-raw: ', () => {
try {
await exportCSVRaw.execute(tree, context, outputPath);
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toEqual(new CliInputError('Output path is required.'));
expect(error).toBeInstanceOf(ExhaustError);
expect(error).toEqual(new ExhaustError('Output path is required.'));
}
});
});
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/unit/builtins/export-csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
aggregation,
} from '../../../__mocks__/builtins/export-csv';

const {CliInputError} = ERRORS;
const {ExhaustError} = ERRORS;

jest.mock('fs/promises', () => ({
writeFile: jest.fn<() => Promise<void>>().mockResolvedValue(),
Expand Down Expand Up @@ -197,8 +197,8 @@ describe('builtins/export-csv: ', () => {
try {
await exportCSV.execute(tree, context, outputPath);
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toEqual(new CliInputError('Output path is required.'));
expect(error).toBeInstanceOf(ExhaustError);
expect(error).toEqual(new ExhaustError('Output path is required.'));
}
});

Expand All @@ -210,9 +210,9 @@ describe('builtins/export-csv: ', () => {
try {
await exportCSV.execute(tree, context, outputPath);
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toBeInstanceOf(ExhaustError);
expect(error).toEqual(
new CliInputError('Output path should contains `#`.')
new ExhaustError('Output path should contain `#`.')
);
}
});
Expand All @@ -225,9 +225,9 @@ describe('builtins/export-csv: ', () => {
try {
await exportCSV.execute(tree, context, outputPath);
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toBeInstanceOf(ExhaustError);
expect(error).toEqual(
new CliInputError(
new ExhaustError(
'CSV export criteria is not found in output path. Please append it after --output <path>#.'
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/unit/builtins/export-yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('../../../util/yaml', () => ({
saveYamlFileAs: jest.fn(),
}));

const {CliInputError} = ERRORS;
const {ExhaustError} = ERRORS;

describe('builtins/export-yaml: ', () => {
describe('ExportYaml: ', () => {
Expand Down Expand Up @@ -38,8 +38,8 @@ describe('builtins/export-yaml: ', () => {
try {
await exportYaml.execute({}, context, '');
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toEqual(new CliInputError('Output path is required.'));
expect(error).toBeInstanceOf(ExhaustError);
expect(error).toEqual(new ExhaustError('Output path is required.'));
}
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/unit/lib/compute.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {compute} from '../../../lib/compute';

import {ComputeParams} from '../../../types/compute';
Expand Down Expand Up @@ -28,6 +29,7 @@ describe('lib/compute: ', () => {
* Compute params.
*/
const paramsExecute: ComputeParams = {
// @ts-ignore
context: {
name: 'mock-name',
initialize: {
Expand All @@ -42,6 +44,7 @@ describe('lib/compute: ', () => {
pluginStorage: pluginStorage().set('mock', mockExecutePlugin()),
};
const params: ComputeParams = {
// @ts-ignore
context: {
name: 'mock-name',
initialize: {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/unit/lib/exhaust.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ERRORS} from '../../../util/errors';

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

const {CliInputError, ModuleInitializationError} = ERRORS;
const {ExhaustError} = ERRORS;
const {INVALID_EXHAUST_PLUGIN} = STRINGS;

describe('lib/exhaust: ', () => {
Expand Down Expand Up @@ -58,9 +58,9 @@ describe('lib/exhaust: ', () => {
// @ts-ignore
await exhaust(tree, context, {});
} catch (error) {
expect(error).toBeInstanceOf(CliInputError);
expect(error).toBeInstanceOf(ExhaustError);

if (error instanceof CliInputError) {
if (error instanceof ExhaustError) {
expect(error.message).toEqual(expectedMessage);
}
}
Expand All @@ -83,9 +83,9 @@ describe('lib/exhaust: ', () => {
// @ts-ignore
await exhaust(tree, context, {});
} catch (error) {
expect(error).toBeInstanceOf(ModuleInitializationError);
expect(error).toBeInstanceOf(ExhaustError);

if (error instanceof ModuleInitializationError) {
if (error instanceof ExhaustError) {
expect(error.message).toEqual(expectedMessage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('../../../util/log-memoize', () => ({
memoizedLog: mockLog,
}));

import {initalize} from '../../../lib/initialize';
import {initialize} from '../../../lib/initialize';

import {ERRORS} from '../../../util/errors';

Expand All @@ -25,7 +25,7 @@ describe('lib/initalize: ', () => {
describe('initalize(): ', () => {
it('creates instance with get and set methods.', async () => {
const plugins = {};
const response = await initalize(plugins);
const response = await initialize(plugins);

expect(response).toHaveProperty('get');
expect(response).toHaveProperty('set');
Expand All @@ -40,7 +40,7 @@ describe('lib/initalize: ', () => {
method: 'Mockavizta',
},
};
const storage = await initalize(plugins);
const storage = await initialize(plugins);

const pluginName = Object.keys(plugins)[0];
const module = storage.get(pluginName);
Expand All @@ -59,7 +59,7 @@ describe('lib/initalize: ', () => {
},
},
};
const storage = await initalize(plugins);
const storage = await initialize(plugins);

const pluginName = Object.keys(plugins)[0];
const module = storage.get(pluginName);
Expand All @@ -79,7 +79,7 @@ describe('lib/initalize: ', () => {
};

try {
await initalize(plugins);
await initialize(plugins);
} catch (error) {
expect(error).toBeInstanceOf(PluginCredentialError);

Expand All @@ -101,7 +101,7 @@ describe('lib/initalize: ', () => {
};

try {
await initalize(plugins);
await initialize(plugins);
} catch (error) {
expect(error).toBeInstanceOf(PluginCredentialError);

Expand All @@ -121,7 +121,7 @@ describe('lib/initalize: ', () => {
},
},
};
const storage = await initalize(plugins);
const storage = await initialize(plugins);

const pluginName = Object.keys(plugins)[0];
const module = storage.get(pluginName);
Expand All @@ -139,7 +139,7 @@ describe('lib/initalize: ', () => {
},
},
};
const storage = await initalize(plugins);
const storage = await initialize(plugins);

const pluginName = Object.keys(plugins)[0];
const module = storage.get(pluginName);
Expand All @@ -159,7 +159,7 @@ describe('lib/initalize: ', () => {
};

try {
await initalize(plugins);
await initialize(plugins);
} catch (error) {
expect(error).toBeInstanceOf(ModuleInitializationError);

Expand Down
129 changes: 64 additions & 65 deletions src/__tests__/unit/lib/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,7 @@ describe('lib/load: ', () => {
const result = await load(inputPath, paramPath);

const expectedValue = {
tree: {
children: {
'front-end': {
pipeline: ['boavizta-cpu'],
config: {
'boavizta-cpu': {
'core-units': 24,
processor: 'Intel® Core™ i7-1185G7',
},
},
inputs: [
{
timestamp: '2023-07-06T00:00',
duration: 3600,
'cpu/utilization': 18.392,
},
{
timestamp: '2023-08-06T00:00',
duration: 3600,
'cpu/utilization': 16,
},
],
},
},
},
rawContext: {
rawManifest: {
name: 'gsf-demo',
description: 'Hello',
tags: {
Expand All @@ -69,6 +44,31 @@ describe('lib/load: ', () => {
},
},
},
tree: {
children: {
'front-end': {
pipeline: ['boavizta-cpu'],
config: {
'boavizta-cpu': {
'core-units': 24,
processor: 'Intel® Core™ i7-1185G7',
},
},
inputs: [
{
timestamp: '2023-07-06T00:00',
duration: 3600,
'cpu/utilization': 18.392,
},
{
timestamp: '2023-08-06T00:00',
duration: 3600,
'cpu/utilization': 16,
},
],
},
},
},
},
parameters: PARAMETERS,
};
Expand All @@ -82,45 +82,8 @@ describe('lib/load: ', () => {

const result = await load(inputPath, paramPath);

const expectedParameters = {
'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',
},
};
const expectedValue = {
tree: {
children: {
'front-end': {
pipeline: ['boavizta-cpu'],
config: {
'boavizta-cpu': {
'core-units': 24,
processor: 'Intel® Core™ i7-1185G7',
},
},
inputs: [
{
timestamp: '2023-07-06T00:00',
duration: 3600,
'cpu/utilization': 18.392,
},
{
timestamp: '2023-08-06T00:00',
duration: 3600,
'cpu/utilization': 16,
},
],
},
},
},
rawContext: {
rawManifest: {
name: 'gsf-demo',
description: 'Hello',
tags: {
Expand All @@ -136,8 +99,44 @@ describe('lib/load: ', () => {
},
},
},
tree: {
children: {
'front-end': {
pipeline: ['boavizta-cpu'],
config: {
'boavizta-cpu': {
'core-units': 24,
processor: 'Intel® Core™ i7-1185G7',
},
},
inputs: [
{
timestamp: '2023-07-06T00:00',
duration: 3600,
'cpu/utilization': 18.392,
},
{
timestamp: '2023-08-06T00:00',
duration: 3600,
'cpu/utilization': 16,
},
],
},
},
},
},
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',
},
},
parameters: expectedParameters,
};

expect(result).toEqual(expectedValue);
Expand Down
Loading