Skip to content

Commit

Permalink
fix: remove trailing slash from metrics server endpoint (#401)
Browse files Browse the repository at this point in the history
Signed-off-by: vitaliy-guliy <[email protected]>
  • Loading branch information
vitaliy-guliy authored Aug 16, 2024
1 parent e9f72dc commit d1f811d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
9 changes: 4 additions & 5 deletions code/extensions/che-resource-monitor/src/resource-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class ResourceMonitor {
@inject(K8sHelper)
private k8sHelper!: K8sHelper;

private METRICS_SERVER_ENDPOINT = '/apis/metrics.k8s.io/v1beta1/';
private METRICS_REQUEST_URL = `${this.METRICS_SERVER_ENDPOINT}namespaces/`;
private METRICS_SERVER_ENDPOINT = '/apis/metrics.k8s.io/v1beta1';

private WARNING_COLOR = '#FFCC00';
private DEFAULT_COLOR = '#FFFFFF';
private DEFAULT_TOOLTIP = 'Workspace resources';
Expand Down Expand Up @@ -121,9 +121,8 @@ export class ResourceMonitor {
}

async getMetrics(): Promise<Container[]> {
const requestURL = `${this.METRICS_REQUEST_URL}${this.namespace}/pods/${this.podName}`;
const opts = { url: this.METRICS_SERVER_ENDPOINT };
const response = await this.k8sHelper.sendRawQuery(requestURL, opts);
const requestURL = `${this.METRICS_SERVER_ENDPOINT}/namespaces/${this.namespace}/pods/${this.podName}`;
const response = await this.k8sHelper.sendRawQuery(requestURL, { url: this.METRICS_SERVER_ENDPOINT });

if (response.statusCode !== 200) {
// wait when workspace pod's metrics will be available
Expand Down
33 changes: 19 additions & 14 deletions code/extensions/che-resource-monitor/src/units-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export function convertToBytes(unit: string | undefined): number {
if (!unit) {
return 0;
}
if (unit.substr(unit.length - 2).toUpperCase() === 'MI') {
return fromMebibytes(parseInt(unit.substr(0, unit.length - 2)));
} else if (unit.substr(unit.length - 2).toUpperCase() === 'KI') {
return fromKibibytes(parseInt(unit.substr(0, unit.length - 2)));
} else if (unit.substr(unit.length - 2).toUpperCase() === 'GI') {
return fromGibibytes(parseInt(unit.substr(0, unit.length - 2)));
} else if (unit.substr(unit.length - 1).toUpperCase() === 'M') {
return fromMegabytes(parseInt(unit.substr(0, unit.length - 1)));
} else if (unit.substr(unit.length - 1).toUpperCase() === 'K') {
return fromKilobytes(parseInt(unit.substr(0, unit.length - 1)));
} else if (unit.substr(unit.length - 1).toUpperCase() === 'G') {
return fromGigabytes(parseInt(unit.substr(0, unit.length - 1)));
if (unit.substring(unit.length - 2).toUpperCase() === 'MI') {
return fromMebibytes(parseInt(unit.substring(0, unit.length - 2)));
} else if (unit.substring(unit.length - 2).toUpperCase() === 'KI') {
return fromKibibytes(parseInt(unit.substring(0, unit.length - 2)));
} else if (unit.substring(unit.length - 2).toUpperCase() === 'GI') {
return fromGibibytes(parseInt(unit.substring(0, unit.length - 2)));
} else if (unit.substring(unit.length - 1).toUpperCase() === 'M') {
return fromMegabytes(parseInt(unit.substring(0, unit.length - 1)));
} else if (unit.substring(unit.length - 1).toUpperCase() === 'K') {
return fromKilobytes(parseInt(unit.substring(0, unit.length - 1)));
} else if (unit.substring(unit.length - 1).toUpperCase() === 'G') {
return fromGigabytes(parseInt(unit.substring(0, unit.length - 1)));
} else {
return parseInt(unit);
}
Expand Down Expand Up @@ -61,8 +61,13 @@ export function convertToMilliCPU(unit: string | undefined): number {
if (!unit) {
return 0;
}
if (unit.substr(unit.length - 1).toUpperCase() === 'M') {
return parseInt(unit.substr(0, unit.length - 1));

if (unit.substring(unit.length - 1).toUpperCase() === 'M') {
return parseInt(unit.substring(0, unit.length - 1));
} else if (unit.substring(unit.length - 1).toUpperCase() === 'N') {
const value = parseInt(unit.substring(0, unit.length - 1));
// convert nanoCPU to miliCPU
return Math.round(value / 1000 / 1000);
} else {
return parseInt(unit) * 1000;
}
Expand Down

0 comments on commit d1f811d

Please sign in to comment.