[domain sharding] Freeup main domain when domain sharding is enabled (#9060)

* [domain sharding] Freeup main domain when domain sharding is enabled

* add change per comment + extra cleanup
This commit is contained in:
Grace Guo 2020-02-03 11:28:39 -08:00 committed by GitHub
parent 848c565c8c
commit bee913bbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -163,13 +163,8 @@ describe('exploreUtils', () => {
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[0]);
url = getExploreUrlAndPayload({
formData,
endpointType: 'json',
allowDomainSharding: true,
}).url;
// skip main domain for fetching chart if domain sharding is enabled
// to leave main domain free for other calls like fav star, save change, etc.
expect(url).toMatch(availableDomains[1]);
url = getExploreUrlAndPayload({
@ -192,7 +187,7 @@ describe('exploreUtils', () => {
endpointType: 'json',
allowDomainSharding: true,
}).url;
expect(url).toMatch(availableDomains[0]);
expect(url).toMatch(availableDomains[1]);
});
it('not generate url to different domains without flag', () => {
let csvURL = getExploreUrlAndPayload({

View File

@ -33,7 +33,7 @@ import { addDangerToast } from '../messageToasts/actions';
import { logEvent } from '../logger/actions';
import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger/LogUtils';
import getClientErrorObject from '../utils/getClientErrorObject';
import { allowCrossDomain } from '../utils/hostNamesConfig';
import { allowCrossDomain as allowDomainSharding } from '../utils/hostNamesConfig';
export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED';
export function chartUpdateStarted(queryController, latestQueryFormData, key) {
@ -212,7 +212,7 @@ export function exploreJSON(
formData,
endpointType: 'json',
force,
allowDomainSharding: true,
allowDomainSharding,
method,
});
const logStart = Logger.getTimestamp();
@ -227,7 +227,7 @@ export function exploreJSON(
signal,
timeout: timeout * 1000,
};
if (allowCrossDomain) {
if (allowDomainSharding) {
querySettings = {
...querySettings,
mode: 'cors',

View File

@ -34,6 +34,14 @@ function getHostName(allowDomainSharding = false) {
if (allowDomainSharding) {
currentIndex = requestCounter % availableDomains.length;
requestCounter += 1;
// if domain sharding is enabled, skip main domain for fetching chart API
// leave main domain free for other calls like fav star, save change, etc.
// to make dashboard be responsive when it's loading large number of charts
if (currentIndex === 0) {
currentIndex += 1;
requestCounter += 1;
}
}
return availableDomains[currentIndex];