Skip to content

Commit

Permalink
revert: "chore: now primary masters do not request data from endpoind…
Browse files Browse the repository at this point in the history
…s which a…"

This reverts commit ffba1f4.
  • Loading branch information
vrozaev authored and ma-efremoff committed Nov 18, 2024
1 parent 7627af6 commit 99b6884
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions packages/ui/src/ui/store/actions/system/masters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {YTApiId, ytApiV3Id} from '../../../rum/rum-wrap-api';
import {USE_SUPRESS_SYNC} from '../../../../shared/constants';
import type {AxiosError} from 'axios';
import type {Dispatch} from 'redux';
import type {BatchResultsItem, BatchSubRequest, CypressNode} from '../../../../shared/yt-types';
import type {BatchSubRequest} from '../../../../shared/yt-types';
import {
MasterAlert,
MasterDataItemInfo,
Expand All @@ -29,7 +29,6 @@ import type {RootState} from '../../reducers';
import {MasterInstance} from '../../selectors/system/masters';
import {getMastersHostType} from '../../selectors/settings';
import {VisibleHostType} from '../../../constants/system/masters';
import {ValueOf} from '../../../../@types/types';

export const FETCH_MASTER_CONFIG = createActionTypes('MASTER_CONFIG');
export const FETCH_MASTER_DATA = createActionTypes('MASTER_DATA');
Expand All @@ -39,25 +38,6 @@ const toaster = new Toaster();

const {NODE_DOES_NOT_EXIST} = YTErrors;

function filterOutMaintananceHosts<T extends CypressNode<{maintenance?: boolean}, string>>(
value: BatchResultsItem<Record<string, T>>,
) {
const output = value.output;

if (output) {
value.output = Object.keys(output).reduce(
(acc, key) => {
if (output[key].$attributes?.maintenance) {
acc[key] = output[key];
}

return acc;
},
{} as Record<string, ValueOf<typeof output>>,
);
}
}

async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[]]> {
const requests = [
{
Expand Down Expand Up @@ -109,18 +89,14 @@ async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[
},
];

const results = await ytApiV3Id.executeBatch(YTApiId.systemMastersConfig, {requests});

results.forEach((item) => filterOutMaintananceHosts(item));

const [
primaryMasterResult,
secondaryMastersResult,
timestampProvidersResult,
discoveryServersResult,
queueAgentsResult,
alertsResult,
] = results;
] = await ytApiV3Id.executeBatch(YTApiId.systemMastersConfig, {requests});

const batchError = getBatchError(
[primaryMasterResult, secondaryMastersResult],
Expand All @@ -143,12 +119,9 @@ async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[
throw queueAgentsError;
}

const timestampProvidersResultOutput = ypath.getValue(timestampProvidersResult.output);
const primaryMasterResultOutput = ypath.getValue(primaryMasterResult.output);

const alerts = alertsResult.output ? (alertsResult.output as MasterAlert[]) : [];
const [timestamp_path] = Object.keys(timestampProvidersResultOutput);
const primaryMasterPaths = Object.keys(primaryMasterResultOutput);
const [timestamp_path] = [...Object.keys(ypath.getValue(timestampProvidersResult.output))];
const primaryMasterPaths = [...Object.keys(ypath.getValue(primaryMasterResult.output))];

const timestamp_tag_cell_requests = [
{
Expand Down Expand Up @@ -184,12 +157,13 @@ async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[
throw primaryMasterCellTagError;
}

const secondaryMastersOutput = secondaryMastersResult.output;
const primaryMaster = primaryMasterResult.output;
const secondaryMasters = secondaryMastersResult.output;

const timestampProviders = !timestampProvidersResultOutput
const timestampProviders = !timestampProvidersResult.output
? {}
: {
addresses: map_(timestampProvidersResultOutput, (value, address) => {
addresses: map_(ypath.getValue(timestampProvidersResult.output), (value, address) => {
return {
host: address,
physicalHost: ypath.getValue(value, '/@annotations/physical_host'),
Expand All @@ -202,8 +176,8 @@ async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[

const mainResult: MastersConfigResponse = {
primaryMaster: {
addresses: map_(keys_(primaryMasterResultOutput), (address) => {
const value = primaryMasterResultOutput[address];
addresses: map_(keys_(primaryMaster), (address) => {
const value = primaryMaster[address];

return {
host: address,
Expand All @@ -214,10 +188,10 @@ async function loadMastersConfig(): Promise<[MastersConfigResponse, MasterAlert[
cellId: masterCellId,
cellTag: getCellIdTag(masterCellId),
},
secondaryMasters: map_(secondaryMastersOutput, (addresses, cellTag) => {
secondaryMasters: map_(secondaryMasters, (addresses, cellTag) => {
return {
addresses: map_(keys_(addresses), (address) => {
const value = secondaryMastersOutput[cellTag][address];
const value = secondaryMasters[cellTag][address];
return {
host: address,
physicalHost: ypath.getValue(value, '/@annotations/physical_host'),
Expand Down

0 comments on commit 99b6884

Please sign in to comment.