Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
warning for V2 accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
scale-tone committed Mar 30, 2021
1 parent 7f61b05 commit 70b73aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class MonitorTreeDataProvider implements vscode.TreeDataProvider<vscode.T
}

this._subscriptions = new SubscriptionTreeItems(
context,
azureAccount,
this._storageAccounts,
() => this._onDidChangeTreeData.fire(),
Expand Down
34 changes: 32 additions & 2 deletions durablefunctionsmonitor-vscodeext/src/SubscriptionTreeItems.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as vscode from 'vscode';

import { StorageManagementClient } from "@azure/arm-storage";
import { StorageAccount } from "@azure/arm-storage/src/models";
Expand All @@ -15,7 +16,8 @@ type AzureSubscription = { session: { credentials2: any }, subscription: { subsc
// Represents the list of Azure Subscriptions in the TreeView
export class SubscriptionTreeItems {

constructor(private _azureAccount: any,
constructor(private _context: vscode.ExtensionContext,
private _azureAccount: any,
private _storageAccounts: StorageAccountTreeItems,
private _onStorageAccountsChanged: () => void,
private _resourcesFolderPath: string,
Expand Down Expand Up @@ -73,8 +75,29 @@ export class SubscriptionTreeItems {
return result;
}

private static HasAlreadyShownStorageV2Warning = false;

private showWarning4V2StorageAccounts(v2AccountNames: string[]): void {

const DfmDoNotShowStorageV2Warning = 'DfmDoNotShowStorageV2Warning';

if (!!SubscriptionTreeItems.HasAlreadyShownStorageV2Warning || !!this._context.globalState.get(DfmDoNotShowStorageV2Warning, false) || !v2AccountNames.length) {
return;
}
SubscriptionTreeItems.HasAlreadyShownStorageV2Warning = true;

const prompt = `Looks like your Durable Functions are using the following General-purpose V2 Storage accounts: ${v2AccountNames.join(', ')}. Combined with Durable Functions, V2 Storage accounts can be more expensive under high loads. Consider using General-purpose V1 Storage instead.`;
vscode.window.showWarningMessage(prompt, 'OK', `Don't Show Again`).then(answer => {

if (answer === `Don't Show Again`) {
this._context.globalState.update(DfmDoNotShowStorageV2Warning, true);
}
});
}

private async tryLoadingTaskHubsForSubscription(storageManagementClient: StorageManagementClient, storageAccounts: StorageAccount[]): Promise<boolean> {

const v2AccountNames: string[] = [];
var taskHubsAdded = false;
await Promise.all(storageAccounts.map(async storageAccount => {

Expand Down Expand Up @@ -105,10 +128,14 @@ export class SubscriptionTreeItems {
}

const hubNames = await getTaskHubNamesFromTableStorage(storageAccount.name!, storageKey.value!, tableEndpoint);
if (!hubNames) {
if (!hubNames || !hubNames.length) {
return;
}

if (storageAccount.kind === 'StorageV2') {
v2AccountNames.push(storageAccount.name!);
}

for (const hubName of hubNames) {

this._storageAccounts.addNodeForConnectionSettings(
Expand All @@ -120,6 +147,9 @@ export class SubscriptionTreeItems {
}
}));

// Notifying about potentially higher costs of V2 accounts
this.showWarning4V2StorageAccounts(v2AccountNames);

return taskHubsAdded;
}

Expand Down

0 comments on commit 70b73aa

Please sign in to comment.