Skip to content

Commit

Permalink
Merge pull request #754 from Green-Software-Foundation/csv-lookup
Browse files Browse the repository at this point in the history
CSV Lookup builtin plugin
  • Loading branch information
MariamKhalatova authored Jun 5, 2024
2 parents 3c31d98 + fb7d904 commit 45e48ba
Show file tree
Hide file tree
Showing 14 changed files with 1,085 additions and 6 deletions.
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

0 comments on commit 45e48ba

Please sign in to comment.