mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-12-01 18:07:00 +00:00
Sqlx currency code fix (#1149)
* using currency code from fetch prices api * formatting & linting fixes * Update SqlX.rp.ts
This commit is contained in:
parent
a3d88af175
commit
2dfabf3c69
@ -6,6 +6,7 @@ import { RefreshResult } from "../SelfServeTypes";
|
|||||||
import SqlX from "./SqlX";
|
import SqlX from "./SqlX";
|
||||||
import {
|
import {
|
||||||
FetchPricesResponse,
|
FetchPricesResponse,
|
||||||
|
PriceMapAndCurrencyCode,
|
||||||
RegionsResponse,
|
RegionsResponse,
|
||||||
SqlxServiceResource,
|
SqlxServiceResource,
|
||||||
UpdateDedicatedGatewayRequestParameters,
|
UpdateDedicatedGatewayRequestParameters,
|
||||||
@ -178,18 +179,18 @@ const getFetchPricesPathForRegion = (subscriptionId: string): string => {
|
|||||||
return `/subscriptions/${subscriptionId}/providers/Microsoft.CostManagement/fetchPrices`;
|
return `/subscriptions/${subscriptionId}/providers/Microsoft.CostManagement/fetchPrices`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPriceMap = async (regions: Array<string>): Promise<Map<string, Map<string, number>>> => {
|
export const getPriceMapAndCurrencyCode = async (regions: Array<string>): Promise<PriceMapAndCurrencyCode> => {
|
||||||
const telemetryData = {
|
const telemetryData = {
|
||||||
feature: "Calculate approximate cost",
|
feature: "Calculate approximate cost",
|
||||||
function: "getPriceMap",
|
function: "getPriceMapAndCurrencyCode",
|
||||||
description: "fetch prices API call",
|
description: "fetch prices API call",
|
||||||
selfServeClassName: SqlX.name,
|
selfServeClassName: SqlX.name,
|
||||||
};
|
};
|
||||||
const getPriceMapTimestamp = selfServeTraceStart(telemetryData);
|
const getPriceMapAndCurrencyCodeTimestamp = selfServeTraceStart(telemetryData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const priceMap = new Map<string, Map<string, number>>();
|
const priceMap = new Map<string, Map<string, number>>();
|
||||||
|
let currencyCode;
|
||||||
for (const region of regions) {
|
for (const region of regions) {
|
||||||
const regionPriceMap = new Map<string, number>();
|
const regionPriceMap = new Map<string, number>();
|
||||||
|
|
||||||
@ -207,17 +208,21 @@ export const getPriceMap = async (regions: Array<string>): Promise<Map<string, M
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const item of response.result.Items) {
|
for (const item of response.result.Items) {
|
||||||
|
if (currencyCode === undefined) {
|
||||||
|
currencyCode = item.currencyCode;
|
||||||
|
} else if (item.currencyCode !== currencyCode) {
|
||||||
|
throw Error("Currency Code Mismatch: Currency code not same for all regions / skus.");
|
||||||
|
}
|
||||||
regionPriceMap.set(item.skuName, item.retailPrice);
|
regionPriceMap.set(item.skuName, item.retailPrice);
|
||||||
}
|
}
|
||||||
priceMap.set(region, regionPriceMap);
|
priceMap.set(region, regionPriceMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
selfServeTraceSuccess(telemetryData, getPriceMapTimestamp);
|
selfServeTraceSuccess(telemetryData, getPriceMapAndCurrencyCodeTimestamp);
|
||||||
return priceMap;
|
return { priceMap: priceMap, currencyCode: currencyCode };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const failureTelemetry = { err, selfServeClassName: SqlX.name };
|
const failureTelemetry = { err, selfServeClassName: SqlX.name };
|
||||||
selfServeTraceFailure(failureTelemetry, getPriceMapTimestamp);
|
selfServeTraceFailure(failureTelemetry, getPriceMapAndCurrencyCodeTimestamp);
|
||||||
|
return { priceMap: undefined, currencyCode: undefined };
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ import { BladeType, generateBladeLink } from "../SelfServeUtils";
|
|||||||
import {
|
import {
|
||||||
deleteDedicatedGatewayResource,
|
deleteDedicatedGatewayResource,
|
||||||
getCurrentProvisioningState,
|
getCurrentProvisioningState,
|
||||||
getPriceMap,
|
getPriceMapAndCurrencyCode,
|
||||||
getRegions,
|
getRegions,
|
||||||
refreshDedicatedGatewayProvisioning,
|
refreshDedicatedGatewayProvisioning,
|
||||||
updateDedicatedGatewayResource,
|
updateDedicatedGatewayResource,
|
||||||
@ -207,6 +207,7 @@ const ApproximateCostDropDownInfo: Info = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let priceMap: Map<string, Map<string, number>>;
|
let priceMap: Map<string, Map<string, number>>;
|
||||||
|
let currencyCode: string;
|
||||||
let regions: Array<string>;
|
let regions: Array<string>;
|
||||||
|
|
||||||
const calculateCost = (skuName: string, instanceCount: number): Description => {
|
const calculateCost = (skuName: string, instanceCount: number): Description => {
|
||||||
@ -237,7 +238,7 @@ const calculateCost = (skuName: string, instanceCount: number): Description => {
|
|||||||
|
|
||||||
selfServeTraceSuccess(telemetryData, calculateCostTimestamp);
|
selfServeTraceSuccess(telemetryData, calculateCostTimestamp);
|
||||||
return {
|
return {
|
||||||
textTKey: `${costPerHour} USD`,
|
textTKey: `${costPerHour} ${currencyCode}`,
|
||||||
type: DescriptionType.Text,
|
type: DescriptionType.Text,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -346,7 +347,9 @@ export default class SqlX extends SelfServeBaseClass {
|
|||||||
});
|
});
|
||||||
|
|
||||||
regions = await getRegions();
|
regions = await getRegions();
|
||||||
priceMap = await getPriceMap(regions);
|
const priceMapAndCurrencyCode = await getPriceMapAndCurrencyCode(regions);
|
||||||
|
priceMap = priceMapAndCurrencyCode.priceMap;
|
||||||
|
currencyCode = priceMapAndCurrencyCode.currencyCode;
|
||||||
|
|
||||||
const response = await getCurrentProvisioningState();
|
const response = await getCurrentProvisioningState();
|
||||||
if (response.status && response.status !== "Deleting") {
|
if (response.status && response.status !== "Deleting") {
|
||||||
|
@ -36,9 +36,15 @@ export type FetchPricesResponse = {
|
|||||||
Count: number;
|
Count: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type PriceMapAndCurrencyCode = {
|
||||||
|
priceMap: Map<string, Map<string, number>>;
|
||||||
|
currencyCode: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type PriceItem = {
|
export type PriceItem = {
|
||||||
retailPrice: number;
|
retailPrice: number;
|
||||||
skuName: string;
|
skuName: string;
|
||||||
|
currencyCode: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RegionsResponse = {
|
export type RegionsResponse = {
|
||||||
|
Loading…
Reference in New Issue
Block a user