mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-05-07 17:02:57 +01:00
Telemetry added for calculate cost function (#1018)
* Added telemetry for sql cost calculation
This commit is contained in:
parent
34c59b4872
commit
ddd2e63fe7
@ -139,6 +139,14 @@ const getGeneralPath = (subscriptionId: string, resourceGroup: string, name: str
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getRegions = async (): Promise<Array<string>> => {
|
export const getRegions = async (): Promise<Array<string>> => {
|
||||||
|
const telemetryData = {
|
||||||
|
feature: "Calculate approximate cost",
|
||||||
|
function: "getRegions",
|
||||||
|
description: "",
|
||||||
|
selfServeClassName: SqlX.name,
|
||||||
|
};
|
||||||
|
const getRegionsTimestamp = selfServeTraceStart(telemetryData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const regions = new Array<string>();
|
const regions = new Array<string>();
|
||||||
|
|
||||||
@ -156,8 +164,12 @@ export const getRegions = async (): Promise<Array<string>> => {
|
|||||||
regions.push(location.locationName.split(" ").join("").toLowerCase());
|
regions.push(location.locationName.split(" ").join("").toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selfServeTraceSuccess(telemetryData, getRegionsTimestamp);
|
||||||
return regions;
|
return regions;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
const failureTelemetry = { err, selfServeClassName: SqlX.name };
|
||||||
|
selfServeTraceFailure(failureTelemetry, getRegionsTimestamp);
|
||||||
return new Array<string>();
|
return new Array<string>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -167,6 +179,14 @@ const getFetchPricesPathForRegion = (subscriptionId: string): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getPriceMap = async (regions: Array<string>): Promise<Map<string, Map<string, number>>> => {
|
export const getPriceMap = async (regions: Array<string>): Promise<Map<string, Map<string, number>>> => {
|
||||||
|
const telemetryData = {
|
||||||
|
feature: "Calculate approximate cost",
|
||||||
|
function: "getPriceMap",
|
||||||
|
description: "fetch prices API call",
|
||||||
|
selfServeClassName: SqlX.name,
|
||||||
|
};
|
||||||
|
const getPriceMapTimestamp = selfServeTraceStart(telemetryData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const priceMap = new Map<string, Map<string, number>>();
|
const priceMap = new Map<string, Map<string, number>>();
|
||||||
|
|
||||||
@ -192,8 +212,12 @@ export const getPriceMap = async (regions: Array<string>): Promise<Map<string, M
|
|||||||
priceMap.set(region, regionPriceMap);
|
priceMap.set(region, regionPriceMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selfServeTraceSuccess(telemetryData, getPriceMapTimestamp);
|
||||||
return priceMap;
|
return priceMap;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
const failureTelemetry = { err, selfServeClassName: SqlX.name };
|
||||||
|
selfServeTraceFailure(failureTelemetry, getPriceMapTimestamp);
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
import { IsDisplayable, OnChange, PropertyInfo, RefreshOptions, Values } from "../Decorators";
|
import { IsDisplayable, OnChange, PropertyInfo, RefreshOptions, Values } from "../Decorators";
|
||||||
import { selfServeTrace } from "../SelfServeTelemetryProcessor";
|
import {
|
||||||
|
selfServeTrace,
|
||||||
|
selfServeTraceFailure,
|
||||||
|
selfServeTraceStart,
|
||||||
|
selfServeTraceSuccess,
|
||||||
|
} from "../SelfServeTelemetryProcessor";
|
||||||
import {
|
import {
|
||||||
ChoiceItem,
|
ChoiceItem,
|
||||||
Description,
|
Description,
|
||||||
@ -205,6 +210,14 @@ let priceMap: Map<string, Map<string, number>>;
|
|||||||
let regions: Array<string>;
|
let regions: Array<string>;
|
||||||
|
|
||||||
const calculateCost = (skuName: string, instanceCount: number): Description => {
|
const calculateCost = (skuName: string, instanceCount: number): Description => {
|
||||||
|
const telemetryData = {
|
||||||
|
feature: "Calculate approximate cost",
|
||||||
|
function: "calculateCost",
|
||||||
|
description: "performs final calculation",
|
||||||
|
selfServeClassName: SqlX.name,
|
||||||
|
};
|
||||||
|
const calculateCostTimestamp = selfServeTraceStart(telemetryData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let costPerHour = 0;
|
let costPerHour = 0;
|
||||||
for (const region of regions) {
|
for (const region of regions) {
|
||||||
@ -215,14 +228,22 @@ const calculateCost = (skuName: string, instanceCount: number): Description => {
|
|||||||
costPerHour += incrementalCost;
|
costPerHour += incrementalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (costPerHour === 0) {
|
||||||
|
throw new Error("Cost per hour = 0");
|
||||||
|
}
|
||||||
|
|
||||||
costPerHour *= instanceCount;
|
costPerHour *= instanceCount;
|
||||||
costPerHour = Math.round(costPerHour * 100) / 100;
|
costPerHour = Math.round(costPerHour * 100) / 100;
|
||||||
|
|
||||||
|
selfServeTraceSuccess(telemetryData, calculateCostTimestamp);
|
||||||
return {
|
return {
|
||||||
textTKey: `${costPerHour} USD`,
|
textTKey: `${costPerHour} USD`,
|
||||||
type: DescriptionType.Text,
|
type: DescriptionType.Text,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
const failureTelemetry = { err, regions, priceMap, selfServeClassName: SqlX.name };
|
||||||
|
selfServeTraceFailure(failureTelemetry, calculateCostTimestamp);
|
||||||
|
|
||||||
return costPerHourDefaultValue;
|
return costPerHourDefaultValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user