Skip to content

Commit

Permalink
using a single request for nonAggregatableDatasets
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn committed Aug 22, 2024
1 parent fbcec23 commit ae42b56
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const typesNoneMatching = i18n.translate('xpack.datasetQuality.selector.types.no
defaultMessage: 'No types found',
});

const typesNoneAvailable = i18n.translate('xpack.datasetQuality.selector.types.noneAvailable', {
defaultMessage: 'No types available',
});

// Allow for lazy loading
// eslint-disable-next-line import/no-default-export
export default function Filters() {
Expand Down Expand Up @@ -88,6 +92,7 @@ export default function Filters() {
label={typesLabel}
searchPlaceholder={typesSearchPlaceholder}
noneMatchingMessage={typesNoneMatching}
noneAvailableMessage={typesNoneAvailable}
options={types}
onOptionsChange={onTypesChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { FlyoutDataset } from '../state_machines/dataset_quality_controller';
import { useDatasetQualityContext } from '../components/dataset_quality/context';
import { useDatasetQualityFilters } from './use_dataset_quality_filters';
import { flattenStats } from '../utils/flatten_stats';
import { TimeRangeConfig } from '../../common/types';

export const useRedirectLinkTelemetry = ({
Expand Down Expand Up @@ -113,7 +112,7 @@ export const useDatasetTelemetry = () => {
foundDataset,
sort,
appliedFilters,
flattenStats(nonAggregatableDatasets).flat(),
nonAggregatableDatasets,
isIgnoredFilter,
canUserViewIntegrations
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DataStreamsStatsClient implements IDataStreamsStatsClient {
const response = await this.http
.get<GetDataStreamsStatsResponse>('/internal/dataset_quality/data_streams/stats', {
query: {
datasetQuery: params.datasetQuery,
...params,
types: rison.encodeArray(types),
},
})
Expand Down Expand Up @@ -89,6 +89,7 @@ export class DataStreamsStatsClient implements IDataStreamsStatsClient {
.get<NonAggregatableDatasets>('/internal/dataset_quality/data_streams/non_aggregatable', {
query: {
...params,
types: rison.encodeArray(params.types),
},
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const DEFAULT_CONTEXT: DefaultDatasetQualityControllerState = {
canMonitor: true,
canViewIntegrations: true,
},
dataStreamStats: DEFAULT_DICTIONARY_TYPE,
dataStreamStats: [],
degradedDocStats: DEFAULT_DICTIONARY_TYPE,
filters: {
inactive: true,
Expand Down Expand Up @@ -71,5 +71,5 @@ export const DEFAULT_CONTEXT: DefaultDatasetQualityControllerState = {
},
datasets: [],
isSizeStatsAvailable: true,
nonAggregatableDatasets: DEFAULT_DICTIONARY_TYPE,
nonAggregatableDatasets: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
DataStreamDetails,
DataStreamStatServiceResponse,
DataStreamDegradedDocsStatServiceResponse,
GetDataStreamsStatsQuery,
} from '../../../../common/data_streams_stats';
import { DataStreamType } from '../../../../common/types';
import { dataStreamPartsToIndexName } from '../../../../common/utils';
Expand Down Expand Up @@ -100,14 +99,6 @@ export const createPureDatasetQualityControllerStateMachine = (
loaded: {},
},
on: {
SAVE_DATASTREAM_STATS: {
target: 'datasets.loaded',
actions: ['storeDataStreamStats', 'storeDatasets'],
},
NOTIFY_DATASTREAM_STATS_FAILED: {
target: 'datasets.loaded',
actions: ['notifyFetchDatasetStatsFailed'],
},
UPDATE_TIME_RANGE: {
target: 'datasets.fetching',
actions: ['storeTimeRange'],
Expand Down Expand Up @@ -156,28 +147,28 @@ export const createPureDatasetQualityControllerStateMachine = (
initial: 'fetching',
states: {
fetching: {
...generateInvokePerType({
invoke: {
src: 'loadNonAggregatableDatasets',
}),
onDone: {
target: 'loaded',
actions: ['storeNonAggregatableDatasets'],
},
onError: [
{
target: 'unauthorized',
cond: 'checkIfActionForbidden',
},
{
target: 'loaded',
actions: ['notifyFetchNonAggregatableDatasetsFailed'],
},
],
},
},
loaded: {},
unauthorized: { type: 'final' },
},
on: {
SAVE_NON_AGGREGATABLE_DATASETS: {
target: 'nonAggregatableDatasets.loaded',
actions: ['storeNonAggregatableDatasets'],
},
NOTIFY_NON_AGGREGATABLE_DATASETS_FAILED: [
{
target: 'nonAggregatableDatasets.unauthorized',
cond: 'checkIfActionForbidden',
},
{
target: 'nonAggregatableDatasets.loaded',
actions: ['notifyFetchNonAggregatableDatasetsFailed'],
},
],
UPDATE_TIME_RANGE: {
target: 'nonAggregatableDatasets.fetching',
},
Expand Down Expand Up @@ -630,31 +621,18 @@ export const createPureDatasetQualityControllerStateMachine = (
}),
resetFlyoutOptions: assign(() => ({ flyout: DEFAULT_CONTEXT.flyout })),
storeDataStreamStats: assign(
(context, event: DoneInvokeEvent<DataStreamStatServiceResponse>, meta) => {
const type = meta._event.origin as DataStreamType;

(_context, event: DoneInvokeEvent<DataStreamStatServiceResponse>) => {
const dataStreamStats = event.data.dataStreamsStats as DataStreamStat[];
const datasetUserPrivileges = event.data.datasetUserPrivileges;

// Check if any DataStreamStat has null; to check for serverless
const isSizeStatsAvailable =
!dataStreamStats.length || dataStreamStats.some((stat) => stat.totalDocs !== null);

return {
dataStreamStats: {
...context.dataStreamStats,
[type]: dataStreamStats,
},
dataStreamStats,
isSizeStatsAvailable,
datasetUserPrivileges: {
canMonitor:
context.datasetUserPrivileges.canMonitor &&
event.data.datasetUserPrivileges.canMonitor,
canRead:
context.datasetUserPrivileges.canRead && event.data.datasetUserPrivileges.canRead,
canViewIntegrations:
context.datasetUserPrivileges.canViewIntegrations &&
event.data.datasetUserPrivileges.canViewIntegrations,
},
datasetUserPrivileges,
};
}
),
Expand Down Expand Up @@ -682,16 +660,9 @@ export const createPureDatasetQualityControllerStateMachine = (
};
}),
storeNonAggregatableDatasets: assign(
(context, event: DoneInvokeEvent<NonAggregatableDatasets>, meta) => {
const type = meta._event.origin as DataStreamType;

return {
nonAggregatableDatasets: {
...context.nonAggregatableDatasets,
[type]: event.data.datasets,
},
};
}
(_context, event: DoneInvokeEvent<NonAggregatableDatasets>) => ({
nonAggregatableDatasets: event.data.datasets,
})
),
storeDataStreamSettings: assign((context, event) => {
return 'data' in event
Expand Down Expand Up @@ -832,7 +803,7 @@ export const createDatasetQualityControllerStateMachine = ({
services: {
loadDataStreamStats: (context, _event) =>
dataStreamStatsClient.getDataStreamsStats({
types: context.filters.types as GetDataStreamsStatsQuery['types'],
types: context.filters.types as DataStreamType[],
datasetQuery: context.filters.query,
}),
loadDegradedDocs:
Expand Down Expand Up @@ -861,34 +832,15 @@ export const createDatasetQualityControllerStateMachine = ({
});
}
},
loadNonAggregatableDatasets:
(context, _event, { data: { type } }) =>
async (send) => {
try {
const { startDate: start, endDate: end } = getDateISORange(context.filters.timeRange);
loadNonAggregatableDatasets: (context) => {
const { startDate: start, endDate: end } = getDateISORange(context.filters.timeRange);

const nonAggregatableDatasets = await (isTypeSelected(type, context)
? dataStreamStatsClient.getNonAggregatableDatasets({
type,
start,
end,
})
: Promise.resolve({
aggregatable: true,
datasets: [],
}));

send({
type: 'SAVE_NON_AGGREGATABLE_DATASETS',
data: nonAggregatableDatasets,
});
} catch (e) {
send({
type: 'NOTIFY_NON_AGGREGATABLE_DATASETS_FAILED',
data: e,
});
}
},
return dataStreamStatsClient.getNonAggregatableDatasets({
types: context.filters.types as DataStreamType[],
start,
end,
});
},
loadDegradedFieldsPerDataStream: (context) => {
if (!context.flyout.dataset || !context.flyout.insightsTimeRange) {
return Promise.resolve({});
Expand Down Expand Up @@ -981,7 +933,7 @@ export const createDatasetQualityControllerStateMachine = ({
);

return dataStreamStatsClient.getNonAggregatableDatasets({
type: type as DataStreamType,
types: [type as DataStreamType],
start,
end,
dataStream: dataStreamPartsToIndexName({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ export type DictionaryType<T> = Record<DataStreamType, T[]>;

export interface WithDataStreamStats {
datasetUserPrivileges: DatasetUserPrivileges;
dataStreamStats: DictionaryType<DataStreamStatType>;
dataStreamStats: DataStreamStatType[];
}

export interface WithDegradedDocs {
degradedDocStats: DictionaryType<DegradedDocsStat>;
}

export interface WithNonAggregatableDatasets {
nonAggregatableDatasets: DictionaryType<string[]>;
nonAggregatableDatasets: string[];
}

export interface WithDatasets {
Expand Down
Loading

0 comments on commit ae42b56

Please sign in to comment.