Get collection usage size with ARM metrics call (#327)

- Removed `readCollectionQuotaInfo` call. The only data we need is the usage size which we can get via the ARM metrics call instead.
- Added `getCollectionUsageSize` which fetches the `DataUsage` and `IndexUsage` metrics, converts them to KB, and returns the sum as the total usage size
This commit is contained in:
victor-meng
2020-11-20 12:21:16 -08:00
committed by GitHub
parent 17fd2185dc
commit 9cbf632577
14 changed files with 124 additions and 92 deletions

View File

@@ -33,18 +33,36 @@ export class ARMError extends Error {
public code: string | number;
}
interface ARMQueryParams {
filter?: string;
metricNames?: string;
}
interface Options {
host: string;
path: string;
apiVersion: string;
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
body?: unknown;
queryParams?: ARMQueryParams;
}
// TODO: This is very similar to what is happening in ResourceProviderClient.ts. Should probably merge them.
export async function armRequest<T>({ host, path, apiVersion, method, body: requestBody }: Options): Promise<T> {
export async function armRequest<T>({
host,
path,
apiVersion,
method,
body: requestBody,
queryParams
}: Options): Promise<T> {
const url = new URL(path, host);
url.searchParams.append("api-version", configContext.armAPIVersion || apiVersion);
if (queryParams) {
queryParams.filter && url.searchParams.append("$filter", queryParams.filter);
queryParams.metricNames && url.searchParams.append("metricnames", queryParams.metricNames);
}
const response = await window.fetch(url.href, {
method,
headers: {