@polaris-sloc/cost-efficiency
Advanced tools
Comparing version 0.5.0 to 0.6.0-beta.2
{ | ||
"name": "@polaris-sloc/cost-efficiency", | ||
"version": "0.5.0", | ||
"version": "0.6.0-beta.2", | ||
"license": "Apache-2.0", | ||
@@ -9,14 +9,16 @@ "author": "Polaris SLO Cloud Authors", | ||
"peerDependencies": { | ||
"@polaris-sloc/core": "~0.5.0", | ||
"change-case": "^4.1.2", | ||
"class-transformer": "~0.5.1", | ||
"lodash": "^4.17.21", | ||
"reflect-metadata": "~0.1.13", | ||
"rxjs": "6.6.7", | ||
"@polaris-sloc/common-mappings": "0.5.0", | ||
"tslib": "^2.4.0" | ||
"@polaris-sloc/core": "~0.6.0-beta.2", | ||
"@polaris-sloc/common-mappings": "0.6.0-beta.2", | ||
"tslib": "2.5.0" | ||
}, | ||
"dependencies": { | ||
"change-case": "4.1.2", | ||
"class-transformer": "0.5.1", | ||
"json-schema": "0.4.0", | ||
"lodash": "4.17.21", | ||
"reflect-metadata": "0.1.13", | ||
"rxjs": "6.6.7" | ||
}, | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts", | ||
"dependencies": {} | ||
"types": "./src/index.d.ts" | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KubeCostMetricSource = void 0; | ||
const tslib_1 = require("tslib"); | ||
const core_1 = require("@polaris-sloc/core"); | ||
@@ -21,32 +20,30 @@ const operators_1 = require("rxjs/operators"); | ||
} | ||
getCost() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const memoryHourlyCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'ram_hourly_cost'); | ||
const cpuHourlyCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'cpu_hourly_cost'); | ||
const memoryCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('container', 'memory_working_set_bytes') | ||
.filterOnLabel(core_1.LabelFilters.equal('namespace', this.params.namespace)) | ||
.divideBy(1024) | ||
.divideBy(1024) | ||
.divideBy(1024) | ||
.multiplyBy(memoryHourlyCostQuery, core_1.Join.onLabels('node').groupLeft()) | ||
.sumByGroup(core_1.LabelGrouping.by('pod')); | ||
const cpuCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'namespace_pod_container:container_cpu_usage_seconds_total:sum_rate') | ||
.filterOnLabel(core_1.LabelFilters.equal('namespace', this.params.namespace)) | ||
.multiplyBy(cpuHourlyCostQuery, core_1.Join.onLabels('node').groupLeft()) | ||
.sumByGroup(core_1.LabelGrouping.by('pod')); | ||
const totalCostQuery = memoryCostQuery.add(cpuCostQuery) | ||
.sumByGroup(); | ||
const totalCost = yield totalCostQuery.execute(); | ||
if (!totalCost.results || totalCost.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('total cost'); | ||
} | ||
return { | ||
currentCostPerHour: totalCost.results[0].samples[0].value, | ||
accumulatedCostInPeriod: totalCost.results[0].samples[0].value, | ||
}; | ||
}); | ||
async getCost() { | ||
const memoryHourlyCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'ram_hourly_cost'); | ||
const cpuHourlyCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'cpu_hourly_cost'); | ||
const memoryCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('container', 'memory_working_set_bytes') | ||
.filterOnLabel(core_1.LabelFilters.equal('namespace', this.params.namespace)) | ||
.divideBy(1024) | ||
.divideBy(1024) | ||
.divideBy(1024) | ||
.multiplyBy(memoryHourlyCostQuery, core_1.Join.onLabels('node').groupLeft()) | ||
.sumByGroup(core_1.LabelGrouping.by('pod')); | ||
const cpuCostQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('node', 'namespace_pod_container:container_cpu_usage_seconds_total:sum_rate') | ||
.filterOnLabel(core_1.LabelFilters.equal('namespace', this.params.namespace)) | ||
.multiplyBy(cpuHourlyCostQuery, core_1.Join.onLabels('node').groupLeft()) | ||
.sumByGroup(core_1.LabelGrouping.by('pod')); | ||
const totalCostQuery = memoryCostQuery.add(cpuCostQuery) | ||
.sumByGroup(); | ||
const totalCost = await totalCostQuery.execute(); | ||
if (!totalCost.results || totalCost.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('total cost'); | ||
} | ||
return { | ||
currentCostPerHour: totalCost.results[0].samples[0].value, | ||
accumulatedCostInPeriod: totalCost.results[0].samples[0].value, | ||
}; | ||
} | ||
@@ -53,0 +50,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RestApiCostEfficiencyMetricSource = void 0; | ||
const tslib_1 = require("tslib"); | ||
const common_mappings_1 = require("@polaris-sloc/common-mappings"); | ||
@@ -21,3 +20,3 @@ const core_1 = require("@polaris-sloc/core"); | ||
getValueStream() { | ||
const _a = this.params, { targetThreshold } = _a, costParams = tslib_1.__rest(_a, ["targetThreshold"]); | ||
const { targetThreshold, ...costParams } = this.params; | ||
const costSource = this.metricsSource.getComposedMetricSource(common_mappings_1.TotalCostMetric.instance, costParams); | ||
@@ -39,35 +38,33 @@ return this.getDefaultPollingInterval().pipe((0, operators_1.switchMap)(() => this.getPercentileFasterThanThreshold()), (0, operators_1.withLatestFrom)(costSource.getValueStream()), | ||
} | ||
getPercentileFasterThanThreshold() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const fasterThanBucketQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('nginx', 'ingress_controller_request_duration_seconds_bucket', core_1.TimeRange.fromDuration(core_1.Duration.fromMinutes(1))) | ||
.filterOnLabel(core_1.LabelFilters.regex('ingress', `${this.params.sloTarget.name}.*`)) | ||
.filterOnLabel(core_1.LabelFilters.equal('le', this.targetThresholdSecStr)) | ||
.rate() | ||
.sumByGroup(core_1.LabelGrouping.by('path')); | ||
const reqCountQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('nginx', 'ingress_controller_request_duration_seconds_count', core_1.TimeRange.fromDuration(core_1.Duration.fromMinutes(1))) | ||
.filterOnLabel(core_1.LabelFilters.regex('ingress', `${this.params.sloTarget.name}.*`)) | ||
.rate() | ||
.sumByGroup(core_1.LabelGrouping.by('path')); | ||
const [fasterThanBucketResult, reqCountResult] = yield Promise.all([fasterThanBucketQuery.execute(), reqCountQuery.execute()]); | ||
if (!fasterThanBucketResult.results || fasterThanBucketResult.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('ingress_controller_request_duration_seconds_bucket', fasterThanBucketQuery); | ||
} | ||
if (!reqCountResult.results || reqCountResult.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('ingress_controller_request_duration_seconds_count', reqCountQuery); | ||
} | ||
const totalReqFasterThanThreshold = this.sumResults(fasterThanBucketResult.results); | ||
const totalReqCount = this.sumResults(reqCountResult.results); | ||
if (totalReqCount === 0) { | ||
return { | ||
percentileFaster: 1, | ||
totalReqFaster: 0, | ||
}; | ||
} | ||
async getPercentileFasterThanThreshold() { | ||
const fasterThanBucketQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('nginx', 'ingress_controller_request_duration_seconds_bucket', core_1.TimeRange.fromDuration(core_1.Duration.fromMinutes(1))) | ||
.filterOnLabel(core_1.LabelFilters.regex('ingress', `${this.params.sloTarget.name}.*`)) | ||
.filterOnLabel(core_1.LabelFilters.equal('le', this.targetThresholdSecStr)) | ||
.rate() | ||
.sumByGroup(core_1.LabelGrouping.by('path')); | ||
const reqCountQuery = this.metricsSource.getTimeSeriesSource() | ||
.select('nginx', 'ingress_controller_request_duration_seconds_count', core_1.TimeRange.fromDuration(core_1.Duration.fromMinutes(1))) | ||
.filterOnLabel(core_1.LabelFilters.regex('ingress', `${this.params.sloTarget.name}.*`)) | ||
.rate() | ||
.sumByGroup(core_1.LabelGrouping.by('path')); | ||
const [fasterThanBucketResult, reqCountResult] = await Promise.all([fasterThanBucketQuery.execute(), reqCountQuery.execute()]); | ||
if (!fasterThanBucketResult.results || fasterThanBucketResult.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('ingress_controller_request_duration_seconds_bucket', fasterThanBucketQuery); | ||
} | ||
if (!reqCountResult.results || reqCountResult.results.length === 0) { | ||
throw new core_1.MetricUnavailableError('ingress_controller_request_duration_seconds_count', reqCountQuery); | ||
} | ||
const totalReqFasterThanThreshold = this.sumResults(fasterThanBucketResult.results); | ||
const totalReqCount = this.sumResults(reqCountResult.results); | ||
if (totalReqCount === 0) { | ||
return { | ||
percentileFaster: totalReqFasterThanThreshold / totalReqCount, | ||
totalReqFaster: totalReqFasterThanThreshold, | ||
percentileFaster: 1, | ||
totalReqFaster: 0, | ||
}; | ||
}); | ||
} | ||
return { | ||
percentileFaster: totalReqFasterThanThreshold / totalReqCount, | ||
totalReqFaster: totalReqFasterThanThreshold, | ||
}; | ||
} | ||
@@ -74,0 +71,0 @@ sumResults(results) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24642
9
313
+ Addedchange-case@4.1.2
+ Addedclass-transformer@0.5.1
+ Addedjson-schema@0.4.0
+ Addedlodash@4.17.21
+ Addedreflect-metadata@0.1.13
+ Addedrxjs@6.6.7
+ Added@polaris-sloc/common-mappings@0.6.0-beta.2(transitive)
+ Added@polaris-sloc/core@0.6.3(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedreflect-metadata@0.1.13(transitive)
+ Addedtslib@2.5.0(transitive)
- Removed@polaris-sloc/common-mappings@0.5.0(transitive)
- Removed@polaris-sloc/core@0.5.0(transitive)
- Removedreflect-metadata@0.1.14(transitive)