Skip to content

Commit

Permalink
Merge branch 'main' into fix-cypress-runner-issue-with-memory
Browse files Browse the repository at this point in the history
  • Loading branch information
achyutjhunjhunwala authored Sep 29, 2023
2 parents 06de23b + f7095d5 commit 3653da7
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 121 deletions.
107 changes: 93 additions & 14 deletions packages/kbn-search-connectors/types/native_connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ const MAX_CONCURRENT_DOWNLOADS_LABEL = i18n.translate(
}
);

const USE_TEXT_EXTRACTION_SERVICE_LABEL = i18n.translate(
'searchConnectors.nativeConnectors.textExtractionService.label',
{
defaultMessage: 'Use text extraction service',
}
);

const USE_TEXT_EXTRACTION_SERVICE_TOOLTIP = i18n.translate(
'searchConnectors.nativeConnectors.textExtractionService.tooltip',
{
defaultMessage:
'Requires a separate deployment of the Elastic Data Extraction Service. ' +
'Also requires that pipeline settings disable text extraction.',
}
);

const DATABASE_LABEL = i18n.translate('searchConnectors.nativeConnectors.databaseLabel', {
defaultMessage: 'Database',
});
Expand Down Expand Up @@ -157,6 +173,21 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
],
value: 100,
},
use_text_extraction_service: {
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 6,
required: true,
sensitive: false,
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
value: false,
},
},
features: {
[FeatureName.SYNC_RULES]: {
Expand Down Expand Up @@ -398,6 +429,21 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
],
value: 50,
},
use_text_extraction_service: {
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 12,
required: true,
sensitive: false,
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
value: false,
},
},
features: {
[FeatureName.SYNC_RULES]: {
Expand Down Expand Up @@ -503,6 +549,21 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
validations: [],
value: 100,
},
use_text_extraction_service: {
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 7,
required: true,
sensitive: false,
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
value: false,
},
},
features: {
[FeatureName.SYNC_RULES]: {
Expand Down Expand Up @@ -741,6 +802,21 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
],
value: 100,
},
use_text_extraction_service: {
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 12,
required: true,
sensitive: false,
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
value: false,
},
},
features: {
[FeatureName.SYNC_RULES]: {
Expand Down Expand Up @@ -1655,6 +1731,21 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
validations: [],
value: 10,
},
use_text_extraction_service: {
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 7,
required: true,
sensitive: false,
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
value: false,
},
},
features: {
[FeatureName.SYNC_RULES]: {
Expand Down Expand Up @@ -1780,24 +1871,12 @@ export const NATIVE_CONNECTOR_DEFINITIONS: Record<string, NativeConnector | unde
default_value: false,
depends_on: [],
display: DisplayType.TOGGLE,
label: i18n.translate(
'searchConnectors.nativeConnectors.sharepoint_online.configuration.textExtractionServiceLabel',
{
defaultMessage: 'Use text extraction service',
}
),
label: USE_TEXT_EXTRACTION_SERVICE_LABEL,
options: [],
order: 6,
required: true,
sensitive: false,
tooltip: i18n.translate(
'searchConnectors.nativeConnectors.sharepoint_online.configuration.textExtractionServiceTooltip',
{
defaultMessage:
'Requires a separate deployment of the Elastic Data Extraction Service. ' +
'Also requires that pipeline settings disable text extraction.',
}
),
tooltip: USE_TEXT_EXTRACTION_SERVICE_TOOLTIP,
type: FieldType.BOOLEAN,
ui_restrictions: ['advanced'],
validations: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { EuiComboBox, EuiComboBoxOptionOption, EuiFlexItem, EuiFormRow } from '@elastic/eui';
import { ALL_VALUE } from '@kbn/slo-schema';
import React, { useEffect, useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { Field } from '../../../../hooks/slo/use_fetch_index_pattern_fields';
Expand Down Expand Up @@ -42,7 +41,7 @@ export function IndexFieldSelector({
<EuiFlexItem>
<EuiFormRow label={label} isInvalid={getFieldState(name).invalid}>
<Controller
defaultValue={ALL_VALUE}
defaultValue=""
name={name}
control={control}
rules={{ required: isRequired }}
Expand All @@ -61,7 +60,7 @@ export function IndexFieldSelector({
return field.onChange(selected[0].value);
}

field.onChange(ALL_VALUE);
field.onChange('');
}}
options={options}
onSearchChange={(searchValue: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ import { MetricIndicator } from './metric_indicator';

export { NEW_CUSTOM_METRIC } from './metric_indicator';

const SUPPORTED_METRIC_FIELD_TYPES = ['number', 'histogram'];

export function CustomMetricIndicatorTypeForm() {
const { watch } = useFormContext<CreateSLOForm>();
const index = watch('indicator.params.index');
const { isLoading: isIndexFieldsLoading, data: indexFields = [] } =
useFetchIndexPatternFields(index);
const timestampFields = indexFields.filter((field) => field.type === 'date');
const partitionByFields = indexFields.filter((field) => field.aggregatable);
const metricFields = indexFields.filter((field) =>
SUPPORTED_METRIC_FIELD_TYPES.includes(field.type)
);

return (
<>
Expand Down Expand Up @@ -115,7 +120,7 @@ export function CustomMetricIndicatorTypeForm() {
<EuiSpacer size="s" />
<MetricIndicator
type="good"
indexFields={indexFields}
metricFields={metricFields}
isLoadingIndex={isIndexFieldsLoading}
/>
</EuiFlexItem>
Expand All @@ -136,7 +141,7 @@ export function CustomMetricIndicatorTypeForm() {
<EuiSpacer size="s" />
<MetricIndicator
type="total"
indexFields={indexFields}
metricFields={metricFields}
isLoadingIndex={isIndexFieldsLoading}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { first, range, xor } from 'lodash';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { Controller, useFieldArray, useFormContext } from 'react-hook-form';
import { Field } from '../../../../hooks/slo/use_fetch_index_pattern_fields';
import { createOptionsFromFields } from '../../helpers/create_options';
import { createOptionsFromFields, Option } from '../../helpers/create_options';
import { CreateSLOForm } from '../../types';
import { QueryBuilder } from '../common/query_builder';

interface MetricIndicatorProps {
type: 'good' | 'total';
indexFields: Field[];
metricFields: Field[];
isLoadingIndex: boolean;
}

Expand All @@ -47,51 +47,52 @@ function createEquationFromMetric(names: string[]) {
return names.join(' + ');
}

const SUPPORTED_FIELD_TYPES = ['number', 'histogram'];
const metricLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.metricLabel',
{ defaultMessage: 'Metric' }
);

export function MetricIndicator({ type, indexFields, isLoadingIndex }: MetricIndicatorProps) {
const metricLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.metricLabel',
{ defaultMessage: 'Metric' }
);
const filterLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.filterLabel',
{ defaultMessage: 'Filter' }
);

const filterLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.filterLabel',
{ defaultMessage: 'Filter' }
);
const metricTooltip = (
<EuiIconTip
content={i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.totalMetric.tooltip',
{
defaultMessage: 'This data from this field will be aggregated with the "sum" aggregation.',
}
)}
position="top"
/>
);

const metricTooltip = (
<EuiIconTip
content={i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.totalMetric.tooltip',
{
defaultMessage:
'This data from this field will be aggregated with the "sum" aggregation.',
}
)}
position="top"
/>
);
const equationLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.equationLabel',
{ defaultMessage: 'Equation' }
);

const equationLabel = i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.equationLabel',
{ defaultMessage: 'Equation' }
);
const equationTooltip = (
<EuiIconTip
content={i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.totalEquation.tooltip',
{
defaultMessage: 'This supports basic math (A + B / C) and boolean logic (A < B ? A : B).',
}
)}
position="top"
/>
);

const equationTooltip = (
<EuiIconTip
content={i18n.translate(
'xpack.observability.slo.sloEdit.sliType.customMetric.totalEquation.tooltip',
{
defaultMessage: 'This supports basic math (A + B / C) and boolean logic (A < B ? A : B).',
}
)}
position="top"
/>
);
export function MetricIndicator({ type, metricFields, isLoadingIndex }: MetricIndicatorProps) {
const { control, watch, setValue, register, getFieldState } = useFormContext<CreateSLOForm>();
const [options, setOptions] = useState<Option[]>(createOptionsFromFields(metricFields));

const { control, watch, setValue, register } = useFormContext<CreateSLOForm>();
const metricFields = indexFields.filter((field) => SUPPORTED_FIELD_TYPES.includes(field.type));
useEffect(() => {
setOptions(createOptionsFromFields(metricFields));
}, [metricFields]);

const { fields, append, remove } = useFieldArray({
control,
Expand Down Expand Up @@ -134,6 +135,7 @@ export function MetricIndicator({ type, indexFields, isLoadingIndex }: MetricInd
<EuiFlexItem>
<EuiFormRow
fullWidth
isInvalid={getFieldState(`indicator.params.${type}.metrics.${index}.field`).invalid}
label={
<span>
{metricLabel} {metric.name} {metricTooltip}
Expand Down Expand Up @@ -163,8 +165,9 @@ export function MetricIndicator({ type, indexFields, isLoadingIndex }: MetricInd
'xpack.observability.slo.sloEdit.sliType.customMetric.metricField.placeholder',
{ defaultMessage: 'Select a metric field' }
)}
isClearable
isInvalid={fieldState.invalid}
isDisabled={!indexPattern}
isDisabled={isLoadingIndex || !indexPattern}
isLoading={!!indexPattern && isLoadingIndex}
onChange={(selected: EuiComboBoxOptionOption[]) => {
if (selected.length) {
Expand All @@ -184,7 +187,14 @@ export function MetricIndicator({ type, indexFields, isLoadingIndex }: MetricInd
]
: []
}
options={createOptionsFromFields(metricFields)}
onSearchChange={(searchValue: string) => {
setOptions(
createOptionsFromFields(metricFields, ({ value }) =>
value.includes(searchValue)
)
);
}}
options={options}
/>
)}
/>
Expand Down
Loading

0 comments on commit 3653da7

Please sign in to comment.