diff --git a/frontend/public/locales/en/pipeline.json b/frontend/public/locales/en/pipeline.json index 77989fdfc5..3b0f7d8bda 100644 --- a/frontend/public/locales/en/pipeline.json +++ b/frontend/public/locales/en/pipeline.json @@ -37,9 +37,9 @@ "processor_field_placeholder": "Field", "processor_value_placeholder": "Value", "processor_description_placeholder": "example rule: %{word:first}", - "processor_trace_id_placeholder": "Trace Id Parce From", - "processor_span_id_placeholder": "Span id Parse From", - "processor_trace_flags_placeholder": "Trace flags parse from", + "processor_trace_id_placeholder": "Parse Trace ID from", + "processor_span_id_placeholder": "Parse Span ID from", + "processor_trace_flags_placeholder": "Parse Trace flags from", "processor_from_placeholder": "From", "processor_to_placeholder": "To" } diff --git a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/FormFields/NameInput.tsx b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/FormFields/NameInput.tsx index bcc41e9677..ccf388e1d1 100644 --- a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/FormFields/NameInput.tsx +++ b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/FormFields/NameInput.tsx @@ -22,6 +22,7 @@ function NameInput({ fieldData }: NameInputProps): JSX.Element { name={fieldData.name} initialValue={fieldData.initialValue} rules={fieldData.rules ? fieldData.rules : formValidationRules} + dependencies={fieldData.dependencies || []} > diff --git a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/config.ts b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/config.ts index 46171c030a..d6337e2b5c 100644 --- a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/config.ts +++ b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/config.ts @@ -1,3 +1,6 @@ +import { Rule, RuleRender } from 'antd/es/form'; +import { NamePath } from 'antd/es/form/interface'; + type ProcessorType = { key: string; value: string; @@ -8,11 +11,11 @@ type ProcessorType = { export const processorTypes: Array = [ { key: 'grok_parser', value: 'grok_parser', label: 'Grok' }, - { key: 'json_parser', value: 'json_parser', label: 'Json Parser' }, { key: 'regex_parser', value: 'regex_parser', label: 'Regex' }, + { key: 'json_parser', value: 'json_parser', label: 'Json Parser' }, + { key: 'trace_parser', value: 'trace_parser', label: 'Trace Parser' }, { key: 'add', value: 'add', label: 'Add' }, { key: 'remove', value: 'remove', label: 'Remove' }, - { key: 'trace_parser', value: 'trace_parser', label: 'Trace Parser' }, // { key: 'retain', value: 'retain', label: 'Retain' }, @Chintan - Commented as per Nitya's suggestion { key: 'move', value: 'move', label: 'Move' }, { key: 'copy', value: 'copy', label: 'Copy' }, @@ -24,11 +27,30 @@ export type ProcessorFormField = { id: number; fieldName: string; placeholder: string; - name: string | Array; - rules?: Array<{ [key: string]: boolean }>; + name: string | NamePath; + rules?: Array; initialValue?: string; + dependencies?: Array; }; +const traceParserFieldValidator: RuleRender = (form) => ({ + validator: (): Promise => { + const parseFromValues = [ + ['trace_id', 'parse_from'], + ['span_id', 'parse_from'], + ['trace_flags', 'parse_from'], + ].map((np) => form.getFieldValue(np)); + + if (!parseFromValues.some((v) => v?.length > 0)) { + return Promise.reject( + new Error('At least one of the trace parser fields must be specified.'), + ); + } + + return Promise.resolve(); + }, +}); + const commonFields = [ { id: 3, @@ -155,18 +177,33 @@ export const processorFields: { [key: string]: Array } = { fieldName: 'Parse Trace Id From', placeholder: 'processor_trace_id_placeholder', name: ['trace_id', 'parse_from'], + rules: [traceParserFieldValidator], + dependencies: [ + ['span_id', 'parse_from'], + ['trace_flags', 'parse_from'], + ], }, { id: 3, fieldName: 'Parse Span Id From', placeholder: 'processor_span_id_placeholder', name: ['span_id', 'parse_from'], + rules: [traceParserFieldValidator], + dependencies: [ + ['trace_id', 'parse_from'], + ['trace_flags', 'parse_from'], + ], }, { id: 4, fieldName: 'Parse Trace flags From', placeholder: 'processor_trace_flags_placeholder', name: ['trace_flags', 'parse_from'], + rules: [traceParserFieldValidator], + dependencies: [ + ['trace_id', 'parse_from'], + ['span_id', 'parse_from'], + ], }, ], retain: [ diff --git a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/utils.tsx b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/utils.tsx index b0de303157..1534b704ea 100644 --- a/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/utils.tsx +++ b/frontend/src/container/PipelinePage/PipelineListsView/AddNewProcessor/utils.tsx @@ -4,6 +4,6 @@ import NameInput from './FormFields/NameInput'; export const renderProcessorForm = ( processorType: string, ): Array => - processorFields[processorType]?.map((fieldName: ProcessorFormField) => ( - + processorFields[processorType]?.map((fieldData: ProcessorFormField) => ( + ));