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

CSV Lookup builtin plugin #754

Merged
merged 22 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8d56c6
fix(types): tune plugin interface
narekhovhannisyan May 31, 2024
8ac2ed8
feat(builtins): implement csv lookup plugin
narekhovhannisyan May 31, 2024
96ec1eb
fix(builtins): add newline to coefficient
narekhovhannisyan May 31, 2024
9fff971
feat(builtins): re-export CSVLookup from index
narekhovhannisyan May 31, 2024
6d3fb16
test(builtins): implement units for csv lookup
narekhovhannisyan May 31, 2024
7d68af5
test(mocks): add case to read csv from fs
narekhovhannisyan May 31, 2024
804786f
chore(package): add axios, csv-parse, axios-mock-adapter
narekhovhannisyan May 31, 2024
a5a33af
chore(src): fetch changes from `main`branch
narekhovhannisyan May 31, 2024
84acb00
feat(doc): init csv lookup README.md
narekhovhannisyan Jun 2, 2024
acf5bad
feat(builtins): nanify empty values in csv lookup
narekhovhannisyan Jun 2, 2024
d3a16a6
feat(manifests): init csv loojup success flow
narekhovhannisyan Jun 2, 2024
192433b
chore(config): remove examples from commitlint
narekhovhannisyan Jun 2, 2024
2cbe8a4
fix(lib): update invalid query error message to be more precise
jmcook1186 Jun 3, 2024
42fed74
fix(lib): apply linter
jmcook1186 Jun 3, 2024
a3ddc1e
fix(lib): update readme
jmcook1186 Jun 3, 2024
48f063d
feat(lib): add test manifests
jmcook1186 Jun 3, 2024
65f49e2
feat(lib): refine readme
jmcook1186 Jun 3, 2024
9236575
test(builtins): update csv lookup cases
narekhovhannisyan Jun 5, 2024
fed5cda
fix(builtins): improve csv lookup csv handling
narekhovhannisyan Jun 5, 2024
a3221ba
feat(mocks): tune csv to handle more cases
narekhovhannisyan Jun 5, 2024
cf78dda
fix(builtins): remove redundant throw case
narekhovhannisyan Jun 5, 2024
fb7d904
test(builtins): add cases for csv lookup
narekhovhannisyan Jun 5, 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
1 change: 0 additions & 1 deletion .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
'package',
'config',
'mocks',
'examples',
'.github',
'.husky',
'scripts',
Expand Down
26 changes: 26 additions & 0 deletions manifests/plugins/csv-lookup/failure-missing-column.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: csv-lookup-demo
description:
tags:
initialize:
# outputs:
# - yaml
plugins:
cloud-metadata:
method: CSVLookup
path: 'builtin'
global-config:
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
query:
cloud-provider: "nonexistant"
cloud-region: "cloud/region"
output: "*"
tree:
children:
child:
pipeline:
- cloud-metadata
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cloud/provider: Google Cloud
cloud/region: asia-east1
26 changes: 26 additions & 0 deletions manifests/plugins/csv-lookup/failure-missing-output.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: csv-lookup-demo
description:
tags:
initialize:
# outputs:
# - yaml
plugins:
cloud-metadata:
method: CSVLookup
path: 'builtin'
global-config:
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
query:
cloud-provider: "cloud/provider"
cloud-region: "cloud/region"
output: "*"
tree:
children:
child:
pipeline:
- cloud-metadata
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cloud/provider: Google Cloud
cloud/region: asia-east1
26 changes: 26 additions & 0 deletions manifests/plugins/csv-lookup/success-renaming.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: csv-lookup-demo
description:
tags:
initialize:
# outputs:
# - yaml
plugins:
cloud-metadata:
method: CSVLookup
path: 'builtin'
global-config:
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
query:
cloud-provider: "cloud/provider"
cloud-region: "cloud/region"
output: ['em-zone-id','renamed-em-zone-data']
tree:
children:
child:
pipeline:
- cloud-metadata
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cloud/provider: Google Cloud
cloud/region: asia-east1
26 changes: 26 additions & 0 deletions manifests/plugins/csv-lookup/success.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: csv-lookup-demo
description:
tags:
initialize:
# outputs:
# - yaml
plugins:
cloud-metadata:
method: CSVLookup
path: 'builtin'
global-config:
filepath: https://raw.githubusercontent.com/Green-Software-Foundation/if-data/main/region-metadata.csv
query:
cloud-provider: "cloud/provider"
cloud-region: "cloud/region"
output: "*"
tree:
children:
child:
pipeline:
- cloud-metadata
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cloud/provider: Google Cloud
cloud/region: asia-east-1
115 changes: 111 additions & 4 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"dependencies": {
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"axios": "^1.7.2",
"csv-parse": "^5.5.6",
"csv-stringify": "^6.4.6",
"js-yaml": "^4.1.0",
"luxon": "^3.4.4",
Expand All @@ -33,6 +35,7 @@
"@types/js-yaml": "^4.0.5",
"@types/luxon": "^3.4.2",
"@types/node": "^20.8.9",
"axios-mock-adapter": "^1.22.0",
"fixpack": "^4.0.0",
"gts": "^5.0.0",
"husky": "^8.0.0",
Expand Down
14 changes: 14 additions & 0 deletions src/__mocks__/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ export const readFile = async (filePath: string) => {
return JSON.stringify(filePath);
}

if (filePath.includes('fail.csv')) {
throw new Error('file not found');
}

/**
* Used for csv lookup plugin.
*/
if (filePath.includes('.csv')) {
return `
cpu-cores-available,cpu-cores-utilized,cpu-manufacturer,cpu-model-name,cpu-tdp,gpu-count,gpu-model-name,Hardware Information on AWS Documentation & Comments,instance-class,instance-storage,memory-available,platform-memory,release-date,storage-drives
16,8,AWS,AWS Graviton,150.00,N/A,N/A,AWS Graviton (ARM),a1.2xlarge,EBS-Only,16,32,November 2018,
16,16,AWS,AWS Graviton,150.00,N/A,N/A,AWS Graviton (ARM),a1.4xlarge,EBS-Only,32,32,November 2018,`;
}

/** mock for util/yaml */
return `
name: gsf-demo
Expand Down
Loading