Skip to content

Commit

Permalink
[Dataset quality] Rename malformed docs to degraded docs (#172586)
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrdyn authored Dec 11, 2023
1 parent 4e6f2cd commit f5dec20
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
const CLOUD_PROVIDERS = ['gcp', 'aws', 'azure'];
const CLOUD_REGION = ['eu-central-1', 'us-east-1', 'area-51'];

// "ignore_above": 1024 in mapping
const MALFORMED_LOG_LEVEL = MORE_THAN_1024_CHARS;

// "ignore_above": 1024 in mapping
const MALFORMED_CLOUD_REGION = MORE_THAN_1024_CHARS;

const CLUSTER = [
{ clusterId: generateShortId(), clusterName: 'synth-cluster-1' },
{ clusterId: generateShortId(), clusterName: 'synth-cluster-2' },
Expand Down Expand Up @@ -76,7 +70,7 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
.create()
.dataset('synth.2')
.message(MESSAGE_LOG_LEVELS[index].message as string)
.logLevel(isMalformed ? MALFORMED_LOG_LEVEL : MESSAGE_LOG_LEVELS[index].level)
.logLevel(isMalformed ? MORE_THAN_1024_CHARS : MESSAGE_LOG_LEVELS[index].level) // "ignore_above": 1024 in mapping
.service(SERVICE_NAMES[index])
.defaults({
'trace.id': generateShortId(),
Expand All @@ -101,7 +95,7 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
.create()
.dataset('synth.3')
.message(MESSAGE_LOG_LEVELS[index].message as string)
.logLevel(isMalformed ? MALFORMED_LOG_LEVEL : MESSAGE_LOG_LEVELS[index].level)
.logLevel(isMalformed ? MORE_THAN_1024_CHARS : MESSAGE_LOG_LEVELS[index].level) // "ignore_above": 1024 in mapping
.service(SERVICE_NAMES[index])
.defaults({
'trace.id': generateShortId(),
Expand All @@ -112,7 +106,7 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
'cloud.provider': CLOUD_PROVIDERS[Math.floor(Math.random() * 3)],
'cloud.region': CLOUD_REGION[index],
'cloud.availability_zone': isMalformed
? MALFORMED_CLOUD_REGION
? MORE_THAN_1024_CHARS // "ignore_above": 1024 in mapping
: `${CLOUD_REGION[index]}a`,
'cloud.project.id': generateShortId(),
'cloud.instance.id': generateShortId(),
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/dataset_quality/common/api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export const integrationRt = rt.intersection([
}),
]);

export const malformedDocsRt = rt.type({
export const degradedDocsRt = rt.type({
dataset: rt.string,
percentage: rt.number,
});

export type MalformedDocs = rt.TypeOf<typeof malformedDocsRt>;
export type DegradedDocs = rt.TypeOf<typeof degradedDocsRt>;

export const getDataStreamsStatsResponseRt = rt.exact(
rt.intersection([
Expand All @@ -60,8 +60,8 @@ export const getDataStreamsStatsResponseRt = rt.exact(
])
);

export const getDataStreamsMalformedDocsStatsResponseRt = rt.exact(
export const getDataStreamsDegradedDocsStatsResponseRt = rt.exact(
rt.type({
malformedDocs: rt.array(malformedDocsRt),
degradedDocs: rt.array(degradedDocsRt),
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DataStreamStat {
sizeBytes?: DataStreamStatType['size_bytes'];
lastActivity?: DataStreamStatType['last_activity'];
integration?: IntegrationType;
malformedDocs?: number;
degradedDocs?: number;

private constructor(dataStreamStat: DataStreamStat) {
this.name = dataStreamStat.name;
Expand All @@ -24,7 +24,7 @@ export class DataStreamStat {
this.sizeBytes = dataStreamStat.sizeBytes;
this.lastActivity = dataStreamStat.lastActivity;
this.integration = dataStreamStat.integration;
this.malformedDocs = dataStreamStat.malformedDocs;
this.degradedDocs = dataStreamStat.degradedDocs;
}

public static create(dataStreamStat: DataStreamStatType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* 2.0.
*/

import { MalformedDocsStatType } from './types';
import { DegradedDocsStatType } from './types';

export class MalformedDocsStat {
dataset: MalformedDocsStatType['dataset'];
percentage: MalformedDocsStatType['percentage'];
export class DegradedDocsStat {
dataset: DegradedDocsStatType['dataset'];
percentage: DegradedDocsStatType['percentage'];

private constructor(malformedDocsStat: MalformedDocsStat) {
this.dataset = malformedDocsStat.dataset;
this.percentage = malformedDocsStat.percentage;
private constructor(degradedDocsStat: DegradedDocsStat) {
this.dataset = degradedDocsStat.dataset;
this.percentage = degradedDocsStat.percentage;
}

public static create(malformedDocsStat: MalformedDocsStatType) {
return new MalformedDocsStat(malformedDocsStat);
public static create(degradedDocsStat: DegradedDocsStatType) {
return new DegradedDocsStat(degradedDocsStat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export type DataStreamStatType = GetDataStreamsStatsResponse['dataStreamsStats']
integration?: IntegrationType;
};

export type GetDataStreamsMalformedDocsStatsParams =
APIClientRequestParamsOf<`GET /internal/dataset_quality/data_streams/malformed_docs`>['params'];
export type GetDataStreamsMalformedDocsStatsQuery = GetDataStreamsMalformedDocsStatsParams['query'];
export type GetDataStreamsMalformedDocsStatsResponse =
APIReturnType<`GET /internal/dataset_quality/data_streams/malformed_docs`>;
export type DataStreamMalformedDocsStatServiceResponse = MalformedDocsStatType[];
export type MalformedDocsStatType = GetDataStreamsMalformedDocsStatsResponse['malformedDocs'][0];
export type GetDataStreamsDegradedDocsStatsParams =
APIClientRequestParamsOf<`GET /internal/dataset_quality/data_streams/degraded_docs`>['params'];
export type GetDataStreamsDegradedDocsStatsQuery = GetDataStreamsDegradedDocsStatsParams['query'];
export type GetDataStreamsDegradedDocsStatsResponse =
APIReturnType<`GET /internal/dataset_quality/data_streams/degraded_docs`>;
export type DataStreamDegradedDocsStatServiceResponse = DegradedDocsStatType[];
export type DegradedDocsStatType = GetDataStreamsDegradedDocsStatsResponse['degradedDocs'][0];
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ const sizeColumnName = i18n.translate('xpack.datasetQuality.sizeColumnName', {
defaultMessage: 'Size',
});

const malformedDocsColumnName = i18n.translate('xpack.datasetQuality.malformedDocsColumnName', {
defaultMessage: 'Malformed Docs',
const degradedDocsColumnName = i18n.translate('xpack.datasetQuality.degradedDocsColumnName', {
defaultMessage: 'Degraded Docs',
});

const malformedDocsDescription = (minimimPercentage: number) =>
i18n.translate('xpack.datasetQuality.malformedDocsQualityDescription', {
const degradedDocsDescription = (minimimPercentage: number) =>
i18n.translate('xpack.datasetQuality.degradedDocsQualityDescription', {
defaultMessage: 'greater than {minimimPercentage}%',
values: { minimimPercentage },
});

const malformedDocsColumnTooltip = (
const degradedDocsColumnTooltip = (
<FormattedMessage
id="xpack.datasetQuality.malformedDocsColumnTooltip"
defaultMessage="The percentage of malformed documents -documents with the {ignoredProperty} property- in your dataset. {visualQueue}"
id="xpack.datasetQuality.degradedDocsColumnTooltip"
defaultMessage="The percentage of degraded documents documents with the {ignoredProperty} property in your dataset. {visualQueue}"
values={{
ignoredProperty: (
<EuiCode language="json" transparentBackground>
Expand All @@ -62,13 +62,13 @@ const malformedDocsColumnTooltip = (
<EuiFlexItem>
<EuiText>
<QualityIndicator quality="poor" />
{` ${malformedDocsDescription(POOR_QUALITY_MINIMUM_PERCENTAGE)}`}
{` ${degradedDocsDescription(POOR_QUALITY_MINIMUM_PERCENTAGE)}`}
</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<EuiText>
<QualityIndicator quality="degraded" />
{` ${malformedDocsDescription(DEGRADED_QUALITY_MINIMUM_PERCENTAGE)}`}
{` ${degradedDocsDescription(DEGRADED_QUALITY_MINIMUM_PERCENTAGE)}`}
</EuiText>
</EuiFlexItem>
<EuiFlexItem>
Expand All @@ -89,10 +89,10 @@ const lastActivityColumnName = i18n.translate('xpack.datasetQuality.lastActivity

export const getDatasetQualitTableColumns = ({
fieldFormats,
loadingMalformedStats,
loadingDegradedStats,
}: {
fieldFormats: FieldFormatsStart;
loadingMalformedStats?: boolean;
loadingDegradedStats?: boolean;
}): Array<EuiBasicTableColumn<DataStreamStat>> => {
return [
{
Expand Down Expand Up @@ -129,28 +129,28 @@ export const getDatasetQualitTableColumns = ({
},
{
name: (
<EuiToolTip content={malformedDocsColumnTooltip}>
<EuiToolTip content={degradedDocsColumnTooltip}>
<span>
{`${malformedDocsColumnName} `}
{`${degradedDocsColumnName} `}
<EuiIcon size="s" color="subdued" type="questionInCircle" className="eui-alignTop" />
</span>
</EuiToolTip>
),
field: 'malformedDocs',
field: 'degradedDocs',
sortable: true,
render: (_, dataStreamStat: DataStreamStat) => (
<EuiSkeletonRectangle
width="50px"
height="20px"
borderRadius="m"
isLoading={loadingMalformedStats}
isLoading={loadingDegradedStats}
contentAriaLabel="Example description"
>
<EuiFlexGroup alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>
<QualityPercentageIndicator percentage={dataStreamStat.malformedDocs} />
<QualityPercentageIndicator percentage={dataStreamStat.degradedDocs} />
</EuiFlexItem>
<EuiFlexItem grow={false}>{`${dataStreamStat.malformedDocs}%`}</EuiFlexItem>
<EuiFlexItem grow={false}>{`${dataStreamStat.degradedDocs ?? 0}%`}</EuiFlexItem>
</EuiFlexGroup>
</EuiSkeletonRectangle>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
* 2.0.
*/

import { isNil } from 'lodash';
import React from 'react';
import {
DEGRADED_QUALITY_MINIMUM_PERCENTAGE,
POOR_QUALITY_MINIMUM_PERCENTAGE,
} from '../../../common/constants';
import { QualityIndicator } from './indicator';

export function QualityPercentageIndicator({ percentage }: { percentage?: number }) {
if (isNil(percentage)) {
return <></>;
}

export function QualityPercentageIndicator({ percentage = 0 }: { percentage?: number }) {
const quality =
percentage > POOR_QUALITY_MINIMUM_PERCENTAGE
? 'poor'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ export const useDatasetQualityTable = () => {

const { dataStreamsStatsServiceClient: client } = useDatasetQualityContext();
const { data = [], loading } = useFetcher(async () => client.getDataStreamsStats(), []);
const { data: malformedStats = [], loading: loadingMalformedStats } = useFetcher(
const { data: degradedStats = [], loading: loadingDegradedStats } = useFetcher(
async () =>
client.getDataStreamsMalformedStats({
client.getDataStreamsDegradedStats({
start: defaultTimeRange.from,
end: defaultTimeRange.to,
}),
[]
);

const columns = useMemo(
() => getDatasetQualitTableColumns({ fieldFormats, loadingMalformedStats }),
[fieldFormats, loadingMalformedStats]
() => getDatasetQualitTableColumns({ fieldFormats, loadingDegradedStats }),
[fieldFormats, loadingDegradedStats]
);

const pagination = {
Expand Down Expand Up @@ -77,18 +77,18 @@ export const useDatasetQualityTable = () => {
const renderedItems = useMemo(() => {
const overridenSortingField = sortingOverrides[sortField] || sortField;
const mergedData = data.map((dataStream) => {
const malformedDocs = find(malformedStats, { dataset: dataStream.name });
const degradedDocs = find(degradedStats, { dataset: dataStream.name });

return {
...dataStream,
malformedDocs: malformedDocs?.percentage,
degradedDocs: degradedDocs?.percentage,
};
});

const sortedItems = orderBy(mergedData, overridenSortingField, sortDirection);

return sortedItems.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize);
}, [data, malformedStats, sortField, sortDirection, pageIndex, pageSize]);
}, [data, degradedStats, sortField, sortDirection, pageIndex, pageSize]);

const resultsCount = useMemo(() => {
const startNumberItemsOnPage = pageSize * pageIndex + (renderedItems.length ? 1 : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { HttpStart } from '@kbn/core/public';
import { decodeOrThrow } from '@kbn/io-ts-utils';
import { find, merge } from 'lodash';
import {
getDataStreamsMalformedDocsStatsResponseRt,
getDataStreamsDegradedDocsStatsResponseRt,
getDataStreamsStatsResponseRt,
} from '../../../common/api_types';
import {
DataStreamStatServiceResponse,
GetDataStreamsMalformedDocsStatsQuery,
GetDataStreamsMalformedDocsStatsResponse,
GetDataStreamsDegradedDocsStatsQuery,
GetDataStreamsDegradedDocsStatsResponse,
GetDataStreamsStatsError,
GetDataStreamsStatsQuery,
GetDataStreamsStatsResponse,
Expand Down Expand Up @@ -52,10 +52,10 @@ export class DataStreamsStatsClient implements IDataStreamsStatsClient {
return mergedDataStreamsStats.map(DataStreamStat.create);
}

public async getDataStreamsMalformedStats(params: GetDataStreamsMalformedDocsStatsQuery) {
public async getDataStreamsDegradedStats(params: GetDataStreamsDegradedDocsStatsQuery) {
const response = await this.http
.get<GetDataStreamsMalformedDocsStatsResponse>(
'/internal/dataset_quality/data_streams/malformed_docs',
.get<GetDataStreamsDegradedDocsStatsResponse>(
'/internal/dataset_quality/data_streams/degraded_docs',
{
query: {
...params,
Expand All @@ -65,18 +65,18 @@ export class DataStreamsStatsClient implements IDataStreamsStatsClient {
)
.catch((error) => {
throw new GetDataStreamsStatsError(
`Failed to fetch data streams malformed stats": ${error}`
`Failed to fetch data streams degraded stats": ${error}`
);
});

const { malformedDocs } = decodeOrThrow(
getDataStreamsMalformedDocsStatsResponseRt,
const { degradedDocs } = decodeOrThrow(
getDataStreamsDegradedDocsStatsResponseRt,
(message: string) =>
new GetDataStreamsStatsError(
`Failed to decode data streams malformed docs stats response: ${message}"`
`Failed to decode data streams degraded docs stats response: ${message}"`
)
)(response);

return malformedDocs;
return degradedDocs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import { HttpStart } from '@kbn/core/public';
import {
DataStreamMalformedDocsStatServiceResponse,
DataStreamDegradedDocsStatServiceResponse,
DataStreamStatServiceResponse,
GetDataStreamsMalformedDocsStatsQuery,
GetDataStreamsDegradedDocsStatsQuery,
GetDataStreamsStatsQuery,
} from '../../../common/data_streams_stats';

Expand All @@ -25,7 +25,7 @@ export interface DataStreamsStatsServiceStartDeps {

export interface IDataStreamsStatsClient {
getDataStreamsStats(params?: GetDataStreamsStatsQuery): Promise<DataStreamStatServiceResponse>;
getDataStreamsMalformedStats(
params?: GetDataStreamsMalformedDocsStatsQuery
): Promise<DataStreamMalformedDocsStatServiceResponse>;
getDataStreamsDegradedStats(
params?: GetDataStreamsDegradedDocsStatsQuery
): Promise<DataStreamDegradedDocsStatServiceResponse>;
}
Loading

0 comments on commit f5dec20

Please sign in to comment.