Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with fetching data for Tables account #1895

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e1430fd
Fix API endpoint for CassandraProxy query API
sindhuba Mar 18, 2024
5042f28
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba Mar 25, 2024
6bdc714
activate Mongo Proxy and Cassandra Proxy in Prod
Apr 8, 2024
d3a3033
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba Apr 8, 2024
2bc09a6
Add CP Prod endpoint
sindhuba Apr 8, 2024
c6ad538
Run npm format and tests
sindhuba Apr 8, 2024
78d9a0c
Revert code
sindhuba Apr 8, 2024
16c7b25
fix bug that blocked local mongo proxy and cassandra proxy development
Apr 9, 2024
5ee4116
Add prod endpoint
sindhuba Apr 9, 2024
a712193
fix pr check tests
Apr 9, 2024
b2d5f91
Remove prod
sindhuba Apr 9, 2024
2243ad8
Remove prod endpoint
sindhuba Apr 9, 2024
4c7aca9
Merge branch 'users/aisayas/mp-cp-activate-prod' of https://github.co…
sindhuba Apr 9, 2024
ef7c2fe
Remove dev endpoint
sindhuba Apr 10, 2024
10a8505
Support data plane RBAC
sindhuba Jun 14, 2024
4d8bb5c
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba Jun 14, 2024
be87173
Support data plane RBAC
sindhuba Jun 14, 2024
24af64a
Add additional changes for Portal RBAC functionality
sindhuba Jun 19, 2024
8849526
Merge branch 'add-dp-rbac' of https://github.com/Azure/cosmos-explorer
sindhuba Jun 19, 2024
4792e2d
Address errors and checks
sindhuba Jun 20, 2024
d3fb5ea
Cleanup DP RBAC code
sindhuba Jun 25, 2024
a50108c
Run format
sindhuba Jun 25, 2024
77ee359
Fix unit tests
sindhuba Jun 25, 2024
192a275
Remove unnecessary code
sindhuba Jun 25, 2024
713df18
Run npm format
sindhuba Jun 25, 2024
fd3a83d
Fix enableAadDataPlane feature flag behavior
sindhuba Jun 25, 2024
478467b
Fix enable AAD dataplane feature flag behavior
sindhuba Jun 25, 2024
eb7c737
Address feedback comments
sindhuba Jun 27, 2024
805d72c
Minor fix
sindhuba Jun 27, 2024
912688d
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba Jun 27, 2024
473a6d3
Add new fixes
sindhuba Jun 28, 2024
72eca5e
Fix Tables test
sindhuba Jun 28, 2024
6be8399
Run npm format
sindhuba Jul 1, 2024
3b9261e
Address Local storage default setting issue
sindhuba Jul 1, 2024
28d8216
Run npm format
sindhuba Jul 1, 2024
602a697
Address lint error
sindhuba Jul 1, 2024
0079a91
Resolved merge conflict
sindhuba Jul 1, 2024
2c78625
Merge branch 'users/sindhuba/rbac' into users/sindhuba/rbac-fix
sindhuba Jul 1, 2024
8b4d9bd
Run format
sindhuba Jul 1, 2024
9274f50
Address bug in fetching data for Tables Account
sindhuba Jul 3, 2024
3e48393
Merge branch 'master' of https://github.com/Azure/cosmos-explorer
sindhuba Jul 3, 2024
2214498
Merge branch 'users/sindhuba/rbac-fix' into users/sindhuba/fix-tables…
sindhuba Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Common/CosmosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
}
}

let retryAttempts: number = 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already do have a library "promiseRetry" that facilitates retry operations with retry options like number of retries, exponential backoff and etc. like here, maybe we should use it here as well

return promiseRetry(() => this.executeContainerAssignmentOperation(provisionData, "allocate"), {

while (retryAttempts > 0 && userContext.listKeysFetchInProgress) {
retryAttempts--;
await sleep(100);
}

if (userContext.masterKey) {
// TODO This SDK method mutates the headers object. Find a better one or fix the SDK.
await Cosmos.setAuthorizationTokenHeaderUsingMasterKey(
Expand Down Expand Up @@ -118,6 +124,10 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
return decodeURIComponent(result.PrimaryReadWriteToken);
};

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, diagnosticNode, next) => {
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
requestContext.headers["x-ms-proxy-target"] = endpoint();
Expand Down
1 change: 1 addition & 0 deletions src/UserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface UserContext {
readonly fabricContext?: FabricContext;
readonly authType?: AuthType;
readonly masterKey?: string;
readonly listKeysFetchInProgress?: boolean;
readonly subscriptionId?: string;
readonly resourceGroup?: string;
readonly databaseAccount?: DatabaseAccount;
Expand Down
20 changes: 16 additions & 4 deletions src/hooks/useKnockoutExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,9 @@ async function configurePortal(): Promise<Explorer> {
useDataPlaneRbac.setState({ dataPlaneRbacEnabled: dataPlaneRbacEnabled });
}
} else {
const keys: DatabaseAccountListKeysResult = await listKeys(subscriptionId, resourceGroup, account.name);
updateUserContext({
masterKey: keys.primaryMasterKey,
});
(async () => {
await fetchAndUpdateKeys(subscriptionId, resourceGroup, account.name);
})();
}

if (openAction) {
Expand Down Expand Up @@ -530,6 +529,18 @@ async function configurePortal(): Promise<Explorer> {
});
}

async function fetchAndUpdateKeys(subscriptionId: string, resourceGroup: string, account: string) {
try {
updateUserContext({ listKeysFetchInProgress: true });
const keys = await listKeys(subscriptionId, resourceGroup, account);

updateUserContext({ masterKey: keys.primaryMasterKey, listKeysFetchInProgress: false });
} catch (error) {
updateUserContext({ listKeysFetchInProgress: false });
console.error("Error during fetching keys or updating user context:", error);
}
}

function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {
// Only allow forwarding messages from the same origin
return messageOrigin === window.document.location.origin && message.type === MessageTypes.TelemetryInfo;
Expand Down Expand Up @@ -567,6 +578,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) {
collectionCreationDefaults: inputs.defaultCollectionThroughput,
isTryCosmosDBSubscription: inputs.isTryCosmosDBSubscription,
feedbackPolicies: inputs.feedbackPolicies,
listKeysFetchInProgress: false,
});

if (inputs.isPostgresAccount) {
Expand Down
Loading