mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-06 09:58:25 +00:00
Cleaning up logging and fixing endpoint discovery bug.
This commit is contained in:
parent
ae24590d03
commit
fa99c54efc
@ -107,10 +107,7 @@ export const tokenProvider = async (requestInfo: Cosmos.RequestInfo) => {
|
|||||||
|
|
||||||
export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, diagnosticNode, next) => {
|
export const requestPlugin: Cosmos.Plugin<any> = async (requestContext, diagnosticNode, next) => {
|
||||||
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
|
requestContext.endpoint = new URL(configContext.PROXY_PATH, window.location.href).href;
|
||||||
console.log(`REQUEST CONTEXT ENDPOINT: ${JSON.stringify(requestContext.endpoint)}`);
|
|
||||||
requestContext.headers["x-ms-proxy-target"] = endpoint();
|
requestContext.headers["x-ms-proxy-target"] = endpoint();
|
||||||
console.log(`REQUEST CONTEXT PROXY: ${JSON.stringify(requestContext.headers["x-ms-proxy-target"])}`);
|
|
||||||
console.log(`WRITE ENABLED ON ENDPOINT: ${userContext.writeEnabledInSelectedRegion}`);
|
|
||||||
return await next(requestContext);
|
return await next(requestContext);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -195,46 +192,14 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
_defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default;
|
_defaultHeaders["x-ms-cosmos-priority-level"] = PriorityLevel.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsing out endpoint from diagnostics. Used to find address I need to add to firewall rule.
|
|
||||||
function parseEndpointFromDiag(json: string): string {
|
|
||||||
const suffix: string = ".documents.azure.com";
|
|
||||||
const start: number = json.indexOf("//") + "//".length;
|
|
||||||
const end: number = json.indexOf(suffix) + suffix.length;
|
|
||||||
const endpoint: string = json.substring(start, end);
|
|
||||||
|
|
||||||
return endpoint;
|
|
||||||
}
|
|
||||||
// Used to check current client region configuration.
|
|
||||||
async function fetchConnectedRegions(client: Cosmos.CosmosClient) {
|
|
||||||
// Check currently connected regions.
|
|
||||||
try {
|
|
||||||
// const someMoreThings = await client.databases.readAll().fetchAll();
|
|
||||||
// console.log(`Current list of databases: ${JSON.stringify(someMoreThings)}`);
|
|
||||||
const currentReadRegion = await client.getReadEndpoint();
|
|
||||||
console.log(`Current read endpoint: ${JSON.stringify(currentReadRegion)}`);
|
|
||||||
const currentReadRegions = await client.getReadEndpoints();
|
|
||||||
console.log(`Current account endpoints: ${JSON.stringify(currentReadRegions)}`);
|
|
||||||
// Getting primary region IP that needs to be blocked.
|
|
||||||
// retrieve the regional endpoint of the account
|
|
||||||
const regionalWriteEndpoint = await client.getWriteEndpoint();
|
|
||||||
console.log(`Current write endpoint: ${JSON.stringify(regionalWriteEndpoint)}`);
|
|
||||||
const parsedWriteEndpoint = parseEndpointFromDiag(JSON.stringify(regionalWriteEndpoint));
|
|
||||||
console.log(`Current parsed write endpoint: ${JSON.stringify(parsedWriteEndpoint)}`);
|
|
||||||
// const writeHostAddress = await findHostAddress(parsedWriteEndpoint);
|
|
||||||
// console.log(`Current write host address: ${JSON.stringify(writeHostAddress)}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error getting read endpoints:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const options: Cosmos.CosmosClientOptions = {
|
const options: Cosmos.CosmosClientOptions = {
|
||||||
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
endpoint: endpoint() || "https://cosmos.azure.com", // CosmosClient gets upset if we pass a bad URL. This should never actually get called
|
||||||
key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey,
|
key: userContext.dataPlaneRbacEnabled ? "" : userContext.masterKey,
|
||||||
diagnosticLevel: Cosmos.CosmosDbDiagnosticLevel.debugUnsafe,
|
|
||||||
tokenProvider,
|
tokenProvider,
|
||||||
userAgentSuffix: "Azure Portal",
|
userAgentSuffix: "Azure Portal",
|
||||||
defaultHeaders: _defaultHeaders,
|
defaultHeaders: _defaultHeaders,
|
||||||
connectionPolicy: {
|
connectionPolicy: {
|
||||||
|
enableEndpointDiscovery: userContext.selectedRegionalEndpoint ? false : true,
|
||||||
retryOptions: {
|
retryOptions: {
|
||||||
maxRetryAttemptCount: LocalStorageUtility.getEntryNumber(StorageKey.RetryAttempts),
|
maxRetryAttemptCount: LocalStorageUtility.getEntryNumber(StorageKey.RetryAttempts),
|
||||||
fixedRetryIntervalInMilliseconds: LocalStorageUtility.getEntryNumber(StorageKey.RetryInterval),
|
fixedRetryIntervalInMilliseconds: LocalStorageUtility.getEntryNumber(StorageKey.RetryInterval),
|
||||||
@ -255,8 +220,5 @@ export function client(): Cosmos.CosmosClient {
|
|||||||
|
|
||||||
_client = new Cosmos.CosmosClient(options);
|
_client = new Cosmos.CosmosClient(options);
|
||||||
|
|
||||||
// Log debug vals
|
|
||||||
// fetchConnectedRegions(_client).catch((error) => console.error(error));
|
|
||||||
|
|
||||||
return _client;
|
return _client;
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,6 @@ const replaceKnownError = (errorMessage: string): string => {
|
|||||||
errorMessage === "signal is aborted without reason"
|
errorMessage === "signal is aborted without reason"
|
||||||
) {
|
) {
|
||||||
return "User aborted query.";
|
return "User aborted query.";
|
||||||
} else if (errorMessage?.indexOf("The requested operation cannot be performed at this region") >= 0) {
|
|
||||||
return "Please select another region for this operation.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
|
@ -32,10 +32,6 @@ export const updateDocument = async (
|
|||||||
logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`);
|
logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`);
|
||||||
return response?.resource;
|
return response?.resource;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// // If error has diagnostic information, log it.
|
|
||||||
// if (error && error.diagnostics) {
|
|
||||||
// console.error("Diagnostics:", error.diagnostics);
|
|
||||||
// }
|
|
||||||
handleError(error, "UpdateDocument", `Failed to update ${entityName} ${documentId.id()}`);
|
handleError(error, "UpdateDocument", `Failed to update ${entityName} ${documentId.id()}`);
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user