mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Fix throughput cost estimate in add collection panel (#1070)
This commit is contained in:
@@ -150,7 +150,7 @@ describe("PricingUtils Tests", () => {
|
||||
expect(value).toBe(0.00012);
|
||||
});
|
||||
|
||||
it("should return 0.00048 for default cloud, 1RU, 2 region, multimaster enabled", () => {
|
||||
it("should return 0.00032 for default cloud, 1RU, 2 region, multimaster enabled", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly({
|
||||
serverId: "default",
|
||||
requestUnits: 1,
|
||||
@@ -158,9 +158,9 @@ describe("PricingUtils Tests", () => {
|
||||
multimasterEnabled: true,
|
||||
isAutoscale: false,
|
||||
});
|
||||
expect(value).toBe(0.00048);
|
||||
expect(value).toBe(0.00032);
|
||||
});
|
||||
it("should return 0.00048 for default cloud, 1RU, 2 region, multimaster enabled, autoscale", () => {
|
||||
it("should return 0.00032 for default cloud, 1RU, 2 region, multimaster enabled, autoscale", () => {
|
||||
const value = PricingUtils.computeRUUsagePriceHourly({
|
||||
serverId: "default",
|
||||
requestUnits: 1,
|
||||
@@ -168,7 +168,7 @@ describe("PricingUtils Tests", () => {
|
||||
multimasterEnabled: true,
|
||||
isAutoscale: true,
|
||||
});
|
||||
expect(value).toBe(0.00096);
|
||||
expect(value).toBe(0.00032);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -251,70 +251,47 @@ describe("PricingUtils Tests", () => {
|
||||
});
|
||||
|
||||
describe("getPricePerRu()", () => {
|
||||
it("should return 0.00008 for default clouds", () => {
|
||||
const value = PricingUtils.getPricePerRu("default");
|
||||
it("should return 0.00008 for single master default clouds", () => {
|
||||
const value = PricingUtils.getPricePerRu("default", 1);
|
||||
expect(value).toBe(0.00008);
|
||||
});
|
||||
|
||||
it("should return 0.00051 for mooncake", () => {
|
||||
const value = PricingUtils.getPricePerRu("mooncake");
|
||||
it("should return 0.00016 for multi master default clouds", () => {
|
||||
const value = PricingUtils.getPricePerRu("default", 2);
|
||||
expect(value).toBe(0.00016);
|
||||
});
|
||||
|
||||
it("should return 0.00051 for single master mooncake", () => {
|
||||
const value = PricingUtils.getPricePerRu("mooncake", 1);
|
||||
expect(value).toBe(0.00051);
|
||||
});
|
||||
|
||||
it("should return 0.00102 for multi master mooncake", () => {
|
||||
const value = PricingUtils.getPricePerRu("mooncake", 2);
|
||||
expect(value).toBe(0.00102);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getRegionMultiplier()", () => {
|
||||
describe("without multimaster", () => {
|
||||
it("should return 0 for undefined", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(undefined, false);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0 for -1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(-1, false);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0 for 0", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(0, false);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 1 for 1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(1, false);
|
||||
expect(value).toBe(1);
|
||||
});
|
||||
|
||||
it("should return 2 for 2", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(2, false);
|
||||
expect(value).toBe(2);
|
||||
});
|
||||
it("should return 0 for undefined", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(undefined);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
describe("with multimaster", () => {
|
||||
it("should return 0 for undefined", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(undefined, true);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0 for -1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(-1, true);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 0 for 0", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(0, true);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
|
||||
it("should return 1 for 1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(1, true);
|
||||
expect(value).toBe(1);
|
||||
});
|
||||
|
||||
it("should return 3 for 2", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(2, true);
|
||||
expect(value).toBe(3);
|
||||
});
|
||||
it("should return 0 for -1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(-1);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
it("should return 0 for 0", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(0);
|
||||
expect(value).toBe(0);
|
||||
});
|
||||
it("should return 1 for 1", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(1);
|
||||
expect(value).toBe(1);
|
||||
});
|
||||
it("should return 2 for 2", () => {
|
||||
const value = PricingUtils.getRegionMultiplier(2);
|
||||
expect(value).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -376,7 +353,7 @@ describe("PricingUtils Tests", () => {
|
||||
true /* multimaster */
|
||||
);
|
||||
expect(value).toBe(
|
||||
"Cost (USD): <b>$0.19 hourly / $4.61 daily / $140.16 monthly </b> (2 regions, 400RU/s, $0.00016/RU)<p style='padding: 10px 0px 0px 0px;'><em>*This cost is an estimate and may vary based on the regions where your account is deployed and potential discounts applied to your account</em></p>"
|
||||
"Cost (USD): <b>$0.13 hourly / $3.07 daily / $93.44 monthly </b> (2 regions, 400RU/s, $0.00016/RU)<p style='padding: 10px 0px 0px 0px;'><em>*This cost is an estimate and may vary based on the regions where your account is deployed and potential discounts applied to your account</em></p>"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -424,7 +401,7 @@ describe("PricingUtils Tests", () => {
|
||||
true /* multimaster */,
|
||||
false
|
||||
);
|
||||
expect(value).toBe("I acknowledge the estimated $4.61 daily cost for the throughput above.");
|
||||
expect(value).toBe("I acknowledge the estimated $3.07 daily cost for the throughput above.");
|
||||
});
|
||||
|
||||
it("should return 'I acknowledge the estimated $1.54 daily cost for the throughput above.' for 400RU/s on default cloud, 2 region, without multimaster", () => {
|
||||
|
||||
@@ -34,26 +34,18 @@ export function getRuToolTipText(): string {
|
||||
* Otherwise, return numberOfRegions
|
||||
* @param numberOfRegions
|
||||
*/
|
||||
export function getRegionMultiplier(numberOfRegions: number, multimasterEnabled: boolean): number {
|
||||
export function getRegionMultiplier(numberOfRegions: number): number {
|
||||
const normalizedNumberOfRegions: number = normalizeNumber(numberOfRegions);
|
||||
|
||||
if (normalizedNumberOfRegions <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (numberOfRegions === 1) {
|
||||
return numberOfRegions;
|
||||
}
|
||||
|
||||
if (multimasterEnabled) {
|
||||
return numberOfRegions + 1;
|
||||
}
|
||||
|
||||
return numberOfRegions;
|
||||
}
|
||||
|
||||
export function getMultimasterMultiplier(numberOfRegions: number, multimasterEnabled: boolean): number {
|
||||
const regionMultiplier: number = getRegionMultiplier(numberOfRegions, multimasterEnabled);
|
||||
const regionMultiplier: number = getRegionMultiplier(numberOfRegions);
|
||||
const multimasterMultiplier: number = !multimasterEnabled ? 1 : regionMultiplier > 1 ? 2 : 1;
|
||||
|
||||
return multimasterMultiplier;
|
||||
@@ -66,10 +58,12 @@ export function computeRUUsagePriceHourly({
|
||||
multimasterEnabled,
|
||||
isAutoscale,
|
||||
}: ComputeRUUsagePriceHourlyArgs): number {
|
||||
const regionMultiplier: number = getRegionMultiplier(numberOfRegions, multimasterEnabled);
|
||||
const regionMultiplier: number = getRegionMultiplier(numberOfRegions);
|
||||
const multimasterMultiplier: number = getMultimasterMultiplier(numberOfRegions, multimasterEnabled);
|
||||
const pricePerRu = isAutoscale ? getAutoscalePricePerRu(serverId, multimasterMultiplier) : getPricePerRu(serverId);
|
||||
const ruCharge = requestUnits * pricePerRu * multimasterMultiplier * regionMultiplier;
|
||||
const pricePerRu = isAutoscale
|
||||
? getAutoscalePricePerRu(serverId, multimasterMultiplier)
|
||||
: getPricePerRu(serverId, multimasterMultiplier);
|
||||
const ruCharge = requestUnits * pricePerRu * regionMultiplier;
|
||||
|
||||
return Number(ruCharge.toFixed(5));
|
||||
}
|
||||
@@ -149,12 +143,16 @@ export function getAutoscalePricePerRu(serverId: string, mmMultiplier: number):
|
||||
}
|
||||
}
|
||||
|
||||
export function getPricePerRu(serverId: string): number {
|
||||
export function getPricePerRu(serverId: string, mmMultiplier: number): number {
|
||||
if (serverId === "mooncake") {
|
||||
return Constants.OfferPricing.HourlyPricing.mooncake.Standard.PricePerRU;
|
||||
return mmMultiplier > 1
|
||||
? Constants.OfferPricing.HourlyPricing.mooncake.Standard.MultiMasterPricePerRU
|
||||
: Constants.OfferPricing.HourlyPricing.mooncake.Standard.SingleMasterPricePerRU;
|
||||
}
|
||||
|
||||
return Constants.OfferPricing.HourlyPricing.default.Standard.PricePerRU;
|
||||
return mmMultiplier > 1
|
||||
? Constants.OfferPricing.HourlyPricing.default.Standard.MultiMasterPricePerRU
|
||||
: Constants.OfferPricing.HourlyPricing.default.Standard.SingleMasterPricePerRU;
|
||||
}
|
||||
|
||||
export function getAutoPilotV3SpendHtml(maxAutoPilotThroughputSet: number, isDatabaseThroughput: boolean): string {
|
||||
@@ -188,9 +186,7 @@ export function getEstimatedAutoscaleSpendHtml(
|
||||
const monthlyPrice: number = hourlyPrice * Constants.hoursInAMonth;
|
||||
const currency: string = getPriceCurrency(serverId);
|
||||
const currencySign: string = getCurrencySign(serverId);
|
||||
const pricePerRu =
|
||||
getAutoscalePricePerRu(serverId, getMultimasterMultiplier(regions, multimaster)) *
|
||||
getMultimasterMultiplier(regions, multimaster);
|
||||
const pricePerRu = getAutoscalePricePerRu(serverId, getMultimasterMultiplier(regions, multimaster));
|
||||
|
||||
return (
|
||||
`Estimated monthly cost (${currency}): <b>` +
|
||||
@@ -219,7 +215,7 @@ export function getEstimatedSpendHtml(
|
||||
const monthlyPrice: number = hourlyPrice * Constants.hoursInAMonth;
|
||||
const currency: string = getPriceCurrency(serverId);
|
||||
const currencySign: string = getCurrencySign(serverId);
|
||||
const pricePerRu = getPricePerRu(serverId) * getMultimasterMultiplier(regions, multimaster);
|
||||
const pricePerRu = getPricePerRu(serverId, getMultimasterMultiplier(regions, multimaster));
|
||||
|
||||
return (
|
||||
`Cost (${currency}): <b>` +
|
||||
|
||||
Reference in New Issue
Block a user