Made changes in ec2 invoice to return the appropriate usage type

This commit is contained in:
Aswin B. S 2025-05-20 13:34:32 +05:30
parent 4fff09443d
commit 9fb76e7277
3 changed files with 99 additions and 59 deletions

105
package-lock.json generated
View File

@ -12,8 +12,9 @@
"@aws-sdk/client-athena": "^3.699.0", "@aws-sdk/client-athena": "^3.699.0",
"@aws-sdk/client-s3": "^3.701.0", "@aws-sdk/client-s3": "^3.701.0",
"@aws-sdk/credential-providers": "^3.699.0", "@aws-sdk/credential-providers": "^3.699.0",
"awsmetrics": "file:",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"fastify": "^5.1.0", "fastify": "^5.3.0",
"fastify-plugin": "^5.0.1", "fastify-plugin": "^5.0.1",
"sequelize": "^6.37.5", "sequelize": "^6.37.5",
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"
@ -1053,6 +1054,12 @@
"fast-json-stringify": "^6.0.0" "fast-json-stringify": "^6.0.0"
} }
}, },
"node_modules/@fastify/forwarded": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@fastify/forwarded/-/forwarded-3.0.0.tgz",
"integrity": "sha512-kJExsp4JCms7ipzg7SJ3y8DwmePaELHxKYtg+tZow+k0znUTf3cb+npgyqm8+ATZOdmfgfydIebPDWM172wfyA==",
"license": "MIT"
},
"node_modules/@fastify/merge-json-schemas": { "node_modules/@fastify/merge-json-schemas": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.1.1.tgz", "resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.1.1.tgz",
@ -1061,6 +1068,16 @@
"fast-deep-equal": "^3.1.3" "fast-deep-equal": "^3.1.3"
} }
}, },
"node_modules/@fastify/proxy-addr": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/@fastify/proxy-addr/-/proxy-addr-5.0.0.tgz",
"integrity": "sha512-37qVVA1qZ5sgH7KpHkkC4z9SK6StIsIcOmpjvMPXNb3vx2GQxhZocogVYbr2PbbeLCQxYIPDok307xEvRZOzGA==",
"license": "MIT",
"dependencies": {
"@fastify/forwarded": "^3.0.0",
"ipaddr.js": "^2.1.0"
}
},
"node_modules/@gar/promisify": { "node_modules/@gar/promisify": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz", "resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz",
@ -1896,6 +1913,10 @@
"fastq": "^1.17.1" "fastq": "^1.17.1"
} }
}, },
"node_modules/awsmetrics": {
"resolved": "",
"link": true
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -2238,9 +2259,9 @@
} }
}, },
"node_modules/fastify": { "node_modules/fastify": {
"version": "5.2.0", "version": "5.3.2",
"resolved": "https://registry.npmjs.org/fastify/-/fastify-5.2.0.tgz", "resolved": "https://registry.npmjs.org/fastify/-/fastify-5.3.2.tgz",
"integrity": "sha512-3s+Qt5S14Eq5dCpnE0FxTp3z4xKChI83ZnMv+k0FwX+VUoZrgCFoLAxpfdi/vT4y6Mk+g7aAMt9pgXDoZmkefQ==", "integrity": "sha512-AIPqBgtqBAwkOkrnwesEE+dOyU30dQ4kh7udxeGVR05CRGwubZx+p2H8P0C4cRnQT0+EPK4VGea2DTL2RtWttg==",
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
@ -2251,20 +2272,21 @@
"url": "https://opencollective.com/fastify" "url": "https://opencollective.com/fastify"
} }
], ],
"license": "MIT",
"dependencies": { "dependencies": {
"@fastify/ajv-compiler": "^4.0.0", "@fastify/ajv-compiler": "^4.0.0",
"@fastify/error": "^4.0.0", "@fastify/error": "^4.0.0",
"@fastify/fast-json-stringify-compiler": "^5.0.0", "@fastify/fast-json-stringify-compiler": "^5.0.0",
"@fastify/proxy-addr": "^5.0.0",
"abstract-logging": "^2.0.1", "abstract-logging": "^2.0.1",
"avvio": "^9.0.0", "avvio": "^9.0.0",
"fast-json-stringify": "^6.0.0", "fast-json-stringify": "^6.0.0",
"find-my-way": "^9.0.0", "find-my-way": "^9.0.0",
"light-my-request": "^6.0.0", "light-my-request": "^6.0.0",
"pino": "^9.0.0", "pino": "^9.0.0",
"process-warning": "^4.0.0", "process-warning": "^5.0.0",
"proxy-addr": "^2.0.7",
"rfdc": "^1.3.1", "rfdc": "^1.3.1",
"secure-json-parse": "^3.0.1", "secure-json-parse": "^4.0.0",
"semver": "^7.6.0", "semver": "^7.6.0",
"toad-cache": "^3.7.0" "toad-cache": "^3.7.0"
} }
@ -2274,6 +2296,22 @@
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-5.0.1.tgz", "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-5.0.1.tgz",
"integrity": "sha512-HCxs+YnRaWzCl+cWRYFnHmeRFyR5GVnJTAaCJQiYzQSDwK9MgJdyAsuL3nh0EWRCYMgQ5MeziymvmAhUHYHDUQ==" "integrity": "sha512-HCxs+YnRaWzCl+cWRYFnHmeRFyR5GVnJTAaCJQiYzQSDwK9MgJdyAsuL3nh0EWRCYMgQ5MeziymvmAhUHYHDUQ=="
}, },
"node_modules/fastify/node_modules/process-warning": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz",
"integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "MIT"
},
"node_modules/fastq": { "node_modules/fastq": {
"version": "1.17.1", "version": "1.17.1",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz",
@ -2300,14 +2338,6 @@
"node": ">=14" "node": ">=14"
} }
}, },
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fs-constants": { "node_modules/fs-constants": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
@ -2528,11 +2558,12 @@
} }
}, },
"node_modules/ipaddr.js": { "node_modules/ipaddr.js": {
"version": "1.9.1", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.2.0.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", "integrity": "sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==",
"license": "MIT",
"engines": { "engines": {
"node": ">= 0.10" "node": ">= 10"
} }
}, },
"node_modules/is-fullwidth-code-point": { "node_modules/is-fullwidth-code-point": {
@ -3001,18 +3032,6 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/pump": { "node_modules/pump": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
@ -3164,9 +3183,20 @@
"optional": true "optional": true
}, },
"node_modules/secure-json-parse": { "node_modules/secure-json-parse": {
"version": "3.0.1", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-3.0.1.tgz", "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.0.0.tgz",
"integrity": "sha512-9QR7G96th4QJ2+dJwvZB+JoXyt8PN+DbEjOr6kL2/JU4KH8Eb2sFdU+gt8EDdzWDWoWH0uocDdfCoFzdVSixUA==" "integrity": "sha512-dxtLJO6sc35jWidmLxo7ij+Eg48PM/kleBsxpC8QJE0qJICe+KawkDQmvCMZUr9u7WKVHgMW6vy3fQ7zMiFZMA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fastify"
},
{
"type": "opencollective",
"url": "https://opencollective.com/fastify"
}
],
"license": "BSD-3-Clause"
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.6.3", "version": "7.6.3",
@ -3475,9 +3505,10 @@
} }
}, },
"node_modules/tar-fs": { "node_modules/tar-fs": {
"version": "2.1.1", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.2.tgz",
"integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", "integrity": "sha512-EsaAXwxmx8UB7FRKqeozqEPop69DXcmYwTQwXvyAPF352HJsPdkVhvTaDPYqfNgruveJIJy3TA2l+2zj8LJIJA==",
"license": "MIT",
"dependencies": { "dependencies": {
"chownr": "^1.1.1", "chownr": "^1.1.1",
"mkdirp-classic": "^0.5.2", "mkdirp-classic": "^0.5.2",

View File

@ -12,8 +12,9 @@
"@aws-sdk/client-athena": "^3.699.0", "@aws-sdk/client-athena": "^3.699.0",
"@aws-sdk/client-s3": "^3.701.0", "@aws-sdk/client-s3": "^3.701.0",
"@aws-sdk/credential-providers": "^3.699.0", "@aws-sdk/credential-providers": "^3.699.0",
"awsmetrics": "file:",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"fastify": "^5.1.0", "fastify": "^5.3.0",
"fastify-plugin": "^5.0.1", "fastify-plugin": "^5.0.1",
"sequelize": "^6.37.5", "sequelize": "^6.37.5",
"sqlite3": "^5.1.7" "sqlite3": "^5.1.7"

View File

@ -217,7 +217,8 @@ FROM ${process.env.ATHENA_CU_TABLE}
WHERE bill_invoice_id = '%invoiceId%' WHERE bill_invoice_id = '%invoiceId%'
AND LOWER(line_item_product_code) = LOWER('%productCode%');`; AND LOWER(line_item_product_code) = LOWER('%productCode%');`;
export const invoiceByProductCodeUsage = `select DISTINCT export const invoiceByProductCodeUsage = `
SELECT DISTINCT
bill_invoice_id as invoiceId, bill_invoice_id as invoiceId,
year, month, year, month,
line_item_product_code as productCode, line_item_product_code as productCode,
@ -234,10 +235,17 @@ export const invoiceByProductCodeUsage = `select DISTINCT
pricing_rate_code AS pricingRateCode, pricing_rate_code AS pricingRateCode,
pricing_currency AS pricingCurrency, pricing_currency AS pricingCurrency,
line_item_usage_start_date AS startDate, line_item_usage_start_date AS startDate,
line_item_usage_end_date AS endDate line_item_usage_end_date AS endDate,
FROM ${process.env.ATHENA_CU_TABLE} CASE
WHERE bill_invoice_id = '%invoiceId%' WHEN line_item_usage_type LIKE '%BoxUsage:%'
AND LOWER(line_item_product_code) = LOWER('%productCode%');`; THEN SUBSTRING(line_item_usage_type, POSITION('BoxUsage:' IN line_item_usage_type) + 9)
ELSE NULL
END AS instanceType
FROM ${process.env.ATHENA_CU_TABLE}
WHERE bill_invoice_id = '%invoiceId%'
AND LOWER(line_item_product_code) = LOWER('%productCode%')
AND line_item_usage_type LIKE '%BoxUsage%'
`;
export const invoiceByIdAccounts = `select DISTINCT export const invoiceByIdAccounts = `select DISTINCT
bill_invoice_id as invoiceId, bill_invoice_id as invoiceId,