@@ -21,13 +21,11 @@ import {
21
21
EuiTitle ,
22
22
} from '@elastic/eui' ;
23
23
import React , { Fragment , useEffect , useState } from 'react' ;
24
- import {
25
- TRACE_CUSTOM_SERVICE_INDEX_SETTING ,
26
- TRACE_CUSTOM_SPAN_INDEX_SETTING ,
27
- TRACE_CUSTOM_MODE_DEFAULT_SETTING ,
28
- } from '../../../../../common/constants/trace_analytics' ;
24
+ import { DEFAULT_CORRELATED_LOGS_FIELD_MAPPINGS } from '../../../../../common/constants/trace_analytics' ;
25
+ import { CorrelatedLogsFieldMappings } from '../../../../../common/types/trace_analytics' ;
29
26
import { uiSettingsService } from '../../../../../common/utils' ;
30
27
import { useToast } from '../../../common/toast' ;
28
+ import { TraceSettings } from './helper_functions' ;
31
29
32
30
interface CustomIndexFlyoutProps {
33
31
isFlyoutVisible : boolean ;
@@ -42,6 +40,10 @@ export const CustomIndexFlyout = ({
42
40
const [ spanIndices , setSpanIndices ] = useState ( '' ) ;
43
41
const [ serviceIndices , setServiceIndices ] = useState ( '' ) ;
44
42
const [ customModeDefault , setCustomModeDefault ] = useState ( false ) ;
43
+ const [ correlatedLogsIndices , setCorrelatedLogsIndices ] = useState ( '' ) ;
44
+ const [ correlatedLogsFieldMappings , setCorrelatedLogsFieldMappings ] = useState (
45
+ { } as CorrelatedLogsFieldMappings
46
+ ) ;
45
47
const [ isLoading , setIsLoading ] = useState ( false ) ;
46
48
47
49
const onChangeSpanIndices = ( e : { target : { value : React . SetStateAction < string > } } ) => {
@@ -52,22 +54,41 @@ export const CustomIndexFlyout = ({
52
54
setServiceIndices ( e . target . value ) ;
53
55
} ;
54
56
57
+ const onChangeCorrelatedLogsIndices = ( e : {
58
+ target : { value : React . SetStateAction < string > } ;
59
+ } ) => {
60
+ setCorrelatedLogsIndices ( e . target . value ) ;
61
+ } ;
62
+
63
+ const onChangeLogsFieldMappings = ( e : React . ChangeEvent < HTMLInputElement > ) => {
64
+ const { name, value } = e . target ;
65
+
66
+ setCorrelatedLogsFieldMappings ( ( prevMappings ) => ( {
67
+ ...prevMappings ,
68
+ [ name ] : value ,
69
+ } ) ) ;
70
+ } ;
71
+
55
72
const onToggleCustomModeDefault = ( e : { target : { checked : boolean } } ) => {
56
73
setCustomModeDefault ( e . target . checked ) ;
57
74
} ;
58
75
59
76
useEffect ( ( ) => {
60
- setSpanIndices ( uiSettingsService . get ( TRACE_CUSTOM_SPAN_INDEX_SETTING ) ) ;
61
- setServiceIndices ( uiSettingsService . get ( TRACE_CUSTOM_SERVICE_INDEX_SETTING ) ) ;
62
- setCustomModeDefault ( uiSettingsService . get ( TRACE_CUSTOM_MODE_DEFAULT_SETTING ) || false ) ;
77
+ setSpanIndices ( TraceSettings . getCustomSpanIndex ( ) ) ;
78
+ setServiceIndices ( TraceSettings . getCustomServiceIndex ( ) ) ;
79
+ setCorrelatedLogsIndices ( TraceSettings . getCorrelatedLogsIndex ( ) ) ;
80
+ setCorrelatedLogsFieldMappings ( TraceSettings . getCorrelatedLogsFieldMappings ( ) ) ;
81
+ setCustomModeDefault ( TraceSettings . getCustomModeSetting ( ) ) ;
63
82
} , [ uiSettingsService ] ) ;
64
83
65
84
const onSaveSettings = async ( ) => {
66
85
try {
67
86
setIsLoading ( true ) ;
68
- await uiSettingsService . set ( TRACE_CUSTOM_SPAN_INDEX_SETTING , spanIndices ) ;
69
- await uiSettingsService . set ( TRACE_CUSTOM_SERVICE_INDEX_SETTING , serviceIndices ) ;
70
- await uiSettingsService . set ( TRACE_CUSTOM_MODE_DEFAULT_SETTING , customModeDefault ) ;
87
+ await TraceSettings . setCustomSpanIndex ( spanIndices ) ;
88
+ await TraceSettings . setCustomServiceIndex ( serviceIndices ) ;
89
+ await TraceSettings . setCorrelatedLogsIndex ( correlatedLogsIndices ) ;
90
+ await TraceSettings . setCorrelatedLogsFieldMappings ( correlatedLogsFieldMappings ) ;
91
+ await TraceSettings . setCustomModeSetting ( customModeDefault ) ;
71
92
setIsLoading ( false ) ;
72
93
setToast ( 'Updated trace analytics settings successfully' , 'success' ) ;
73
94
} catch ( error ) {
@@ -77,6 +98,25 @@ export const CustomIndexFlyout = ({
77
98
setIsLoading ( false ) ;
78
99
} ;
79
100
101
+ const correlatedFieldsForm = ( ) => {
102
+ const correlatedFieldsFromSettings : CorrelatedLogsFieldMappings = TraceSettings . getCorrelatedLogsFieldMappings ( ) ;
103
+ return Object . keys ( correlatedFieldsFromSettings ) . map ( ( key ) => {
104
+ return (
105
+ < >
106
+ < EuiFormRow label = { key } >
107
+ < EuiCompressedFieldText
108
+ name = { key }
109
+ aria-label = { key }
110
+ placeholder = { JSON . parse ( DEFAULT_CORRELATED_LOGS_FIELD_MAPPINGS ) [ key ] }
111
+ value = { correlatedLogsFieldMappings [ key ] }
112
+ onChange = { onChangeLogsFieldMappings }
113
+ />
114
+ </ EuiFormRow >
115
+ </ >
116
+ ) ;
117
+ } ) ;
118
+ } ;
119
+
80
120
const callout = (
81
121
< EuiCallOut
82
122
title = "Custom source in trace analytics is an experimental feature"
@@ -143,6 +183,36 @@ export const CustomIndexFlyout = ({
143
183
/>
144
184
</ EuiFormRow >
145
185
</ EuiDescribedFormGroup >
186
+ < EuiDescribedFormGroup
187
+ title = { < h3 > Correlated logs indices</ h3 > }
188
+ description = {
189
+ < Fragment >
190
+ Configure custom logs indices to be used by the trace analytics plugin to correlate
191
+ spans and services
192
+ </ Fragment >
193
+ }
194
+ >
195
+ < EuiFormRow label = "Correlated logs indices" >
196
+ < EuiCompressedFieldText
197
+ name = "logsIndices"
198
+ aria-label = "logsIndices"
199
+ placeholder = "index1"
200
+ value = { correlatedLogsIndices }
201
+ onChange = { onChangeCorrelatedLogsIndices }
202
+ />
203
+ </ EuiFormRow >
204
+ </ EuiDescribedFormGroup >
205
+ < EuiDescribedFormGroup
206
+ title = { < h3 > Correlated logs fields</ h3 > }
207
+ description = {
208
+ < Fragment >
209
+ Configure correlated logs fields, to be used by the trace analytics plugin for
210
+ correlate spans and services to logs
211
+ </ Fragment >
212
+ }
213
+ >
214
+ { correlatedFieldsForm ( ) }
215
+ </ EuiDescribedFormGroup >
146
216
< EuiDescribedFormGroup
147
217
title = { < h3 > Set default mode</ h3 > }
148
218
description = {
0 commit comments