@@ -84,180 +84,174 @@ function createConfigManager(configPath: string) {
8484}
8585
8686describe ( 'Server logging configuration' , function ( ) {
87- let child : Child . ChildProcess ;
87+ let child : undefined | Child . ChildProcess ;
88+
8889 beforeEach ( ( ) => {
8990 Fs . mkdirSync ( tempDir , { recursive : true } ) ;
9091 } ) ;
9192
9293 afterEach ( async ( ) => {
9394 if ( child !== undefined ) {
94- child . kill ( ) ;
95- // wait for child to be killed otherwise jest complains that process not finished
96- await new Promise ( res => setTimeout ( res , 1000 ) ) ;
95+ const exitPromise = new Promise ( resolve => child ?. once ( 'exit' , resolve ) ) ;
96+ child . kill ( 'SIGKILL' ) ;
97+ await exitPromise ;
9798 }
99+
98100 Del . sync ( tempDir , { force : true } ) ;
99101 } ) ;
100102
101- const isWindows = / ^ w i n / . test ( process . platform ) ;
102- if ( isWindows ) {
103+ if ( process . platform . startsWith ( 'win' ) ) {
103104 it ( 'SIGHUP is not a feature of Windows.' , ( ) => {
104105 // nothing to do for Windows
105106 } ) ;
106- } else {
107- describe ( 'legacy logging' , ( ) => {
108- it (
109- 'should be reloadable via SIGHUP process signaling' ,
110- async function ( ) {
111- const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
112- Fs . copyFileSync ( legacyConfig , configFilePath ) ;
113-
114- child = Child . spawn ( process . execPath , [
115- kibanaPath ,
116- '--oss' ,
117- '--config' ,
118- configFilePath ,
119- '--verbose' ,
120- ] ) ;
121-
122- const message$ = Rx . fromEvent ( child . stdout , 'data' ) . pipe (
123- map ( messages =>
124- String ( messages )
125- . split ( '\n' )
126- . filter ( Boolean )
127- )
128- ) ;
129-
130- await message$
131- . pipe (
132- // We know the sighup handler will be registered before this message logged
133- filter ( messages => messages . some ( m => m . includes ( 'setting up root' ) ) ) ,
134- take ( 1 )
135- )
136- . toPromise ( ) ;
137-
138- const lastMessage = await message$ . pipe ( take ( 1 ) ) . toPromise ( ) ;
139- expect ( containsJsonOnly ( lastMessage ) ) . toBe ( true ) ;
140-
141- createConfigManager ( configFilePath ) . modify ( oldConfig => {
142- oldConfig . logging . json = false ;
143- return oldConfig ;
144- } ) ;
145-
146- child . kill ( 'SIGHUP' ) ;
147-
148- await message$
149- . pipe (
150- filter ( messages => ! containsJsonOnly ( messages ) ) ,
151- take ( 1 )
152- )
153- . toPromise ( ) ;
154- } ,
155- minute
156- ) ;
157-
158- it (
159- 'should recreate file handle on SIGHUP' ,
160- async function ( ) {
161- const logPath = Path . resolve ( tempDir , 'kibana.log' ) ;
162- const logPathArchived = Path . resolve ( tempDir , 'kibana_archive.log' ) ;
163-
164- child = Child . spawn ( process . execPath , [
165- kibanaPath ,
166- '--oss' ,
167- '--config' ,
168- legacyConfig ,
169- '--logging.dest' ,
170- logPath ,
171- '--verbose' ,
172- ] ) ;
173-
174- await watchFileUntil ( logPath , / s e t t i n g u p r o o t / , 30 * second ) ;
175- // once the server is running, archive the log file and issue SIGHUP
176- Fs . renameSync ( logPath , logPathArchived ) ;
177- child . kill ( 'SIGHUP' ) ;
178-
179- await watchFileUntil (
180- logPath ,
181- / R e l o a d e d l o g g i n g c o n f i g u r a t i o n d u e t o S I G H U P / ,
182- 30 * second
183- ) ;
184- } ,
185- minute
186- ) ;
187- } ) ;
188-
189- describe ( 'platform logging' , ( ) => {
190- it (
191- 'should be reloadable via SIGHUP process signaling' ,
192- async function ( ) {
193- const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
194- Fs . copyFileSync ( configFileLogConsole , configFilePath ) ;
195-
196- child = Child . spawn ( process . execPath , [ kibanaPath , '--oss' , '--config' , configFilePath ] ) ;
197-
198- const message$ = Rx . fromEvent ( child . stdout , 'data' ) . pipe (
199- map ( messages =>
200- String ( messages )
201- . split ( '\n' )
202- . filter ( Boolean )
203- )
204- ) ;
205-
206- await message$
207- . pipe (
208- // We know the sighup handler will be registered before this message logged
209- filter ( messages => messages . some ( m => m . includes ( 'setting up root' ) ) ) ,
210- take ( 1 )
211- )
212- . toPromise ( ) ;
213-
214- const lastMessage = await message$ . pipe ( take ( 1 ) ) . toPromise ( ) ;
215- expect ( containsJsonOnly ( lastMessage ) ) . toBe ( true ) ;
216-
217- createConfigManager ( configFilePath ) . modify ( oldConfig => {
218- oldConfig . logging . appenders . console . layout . kind = 'pattern' ;
219- return oldConfig ;
220- } ) ;
221- child . kill ( 'SIGHUP' ) ;
222-
223- await message$
224- . pipe (
225- filter ( messages => ! containsJsonOnly ( messages ) ) ,
226- take ( 1 )
227- )
228- . toPromise ( ) ;
229- } ,
230- 30 * second
231- ) ;
232- it (
233- 'should recreate file handle on SIGHUP' ,
234- async function ( ) {
235- const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
236- Fs . copyFileSync ( configFileLogFile , configFilePath ) ;
237-
238- const logPath = Path . resolve ( tempDir , 'kibana.log' ) ;
239- const logPathArchived = Path . resolve ( tempDir , 'kibana_archive.log' ) ;
240-
241- createConfigManager ( configFilePath ) . modify ( oldConfig => {
242- oldConfig . logging . appenders . file . path = logPath ;
243- return oldConfig ;
244- } ) ;
245-
246- child = Child . spawn ( process . execPath , [ kibanaPath , '--oss' , '--config' , configFilePath ] ) ;
247-
248- await watchFileUntil ( logPath , / s e t t i n g u p r o o t / , 30 * second ) ;
249- // once the server is running, archive the log file and issue SIGHUP
250- Fs . renameSync ( logPath , logPathArchived ) ;
251- child . kill ( 'SIGHUP' ) ;
252-
253- await watchFileUntil (
254- logPath ,
255- / R e l o a d e d l o g g i n g c o n f i g u r a t i o n d u e t o S I G H U P / ,
256- 30 * second
257- ) ;
258- } ,
259- minute
260- ) ;
261- } ) ;
107+ return ;
262108 }
109+
110+ describe ( 'legacy logging' , ( ) => {
111+ it (
112+ 'should be reloadable via SIGHUP process signaling' ,
113+ async function ( ) {
114+ const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
115+ Fs . copyFileSync ( legacyConfig , configFilePath ) ;
116+
117+ child = Child . spawn ( process . execPath , [
118+ kibanaPath ,
119+ '--oss' ,
120+ '--config' ,
121+ configFilePath ,
122+ '--verbose' ,
123+ ] ) ;
124+
125+ const message$ = Rx . fromEvent ( child . stdout , 'data' ) . pipe (
126+ map ( messages =>
127+ String ( messages )
128+ . split ( '\n' )
129+ . filter ( Boolean )
130+ )
131+ ) ;
132+
133+ await message$
134+ . pipe (
135+ // We know the sighup handler will be registered before this message logged
136+ filter ( messages => messages . some ( m => m . includes ( 'setting up root' ) ) ) ,
137+ take ( 1 )
138+ )
139+ . toPromise ( ) ;
140+
141+ const lastMessage = await message$ . pipe ( take ( 1 ) ) . toPromise ( ) ;
142+ expect ( containsJsonOnly ( lastMessage ) ) . toBe ( true ) ;
143+
144+ createConfigManager ( configFilePath ) . modify ( oldConfig => {
145+ oldConfig . logging . json = false ;
146+ return oldConfig ;
147+ } ) ;
148+
149+ child . kill ( 'SIGHUP' ) ;
150+
151+ await message$
152+ . pipe (
153+ filter ( messages => ! containsJsonOnly ( messages ) ) ,
154+ take ( 1 )
155+ )
156+ . toPromise ( ) ;
157+ } ,
158+ minute
159+ ) ;
160+
161+ it (
162+ 'should recreate file handle on SIGHUP' ,
163+ async function ( ) {
164+ const logPath = Path . resolve ( tempDir , 'kibana.log' ) ;
165+ const logPathArchived = Path . resolve ( tempDir , 'kibana_archive.log' ) ;
166+
167+ child = Child . spawn ( process . execPath , [
168+ kibanaPath ,
169+ '--oss' ,
170+ '--config' ,
171+ legacyConfig ,
172+ '--logging.dest' ,
173+ logPath ,
174+ '--verbose' ,
175+ ] ) ;
176+
177+ await watchFileUntil ( logPath , / s e t t i n g u p r o o t / , 30 * second ) ;
178+ // once the server is running, archive the log file and issue SIGHUP
179+ Fs . renameSync ( logPath , logPathArchived ) ;
180+ child . kill ( 'SIGHUP' ) ;
181+
182+ await watchFileUntil ( logPath , / R e l o a d e d l o g g i n g c o n f i g u r a t i o n d u e t o S I G H U P / , 30 * second ) ;
183+ } ,
184+ minute
185+ ) ;
186+ } ) ;
187+
188+ describe ( 'platform logging' , ( ) => {
189+ it (
190+ 'should be reloadable via SIGHUP process signaling' ,
191+ async function ( ) {
192+ const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
193+ Fs . copyFileSync ( configFileLogConsole , configFilePath ) ;
194+
195+ child = Child . spawn ( process . execPath , [ kibanaPath , '--oss' , '--config' , configFilePath ] ) ;
196+
197+ const message$ = Rx . fromEvent ( child . stdout , 'data' ) . pipe (
198+ map ( messages =>
199+ String ( messages )
200+ . split ( '\n' )
201+ . filter ( Boolean )
202+ )
203+ ) ;
204+
205+ await message$
206+ . pipe (
207+ // We know the sighup handler will be registered before this message logged
208+ filter ( messages => messages . some ( m => m . includes ( 'setting up root' ) ) ) ,
209+ take ( 1 )
210+ )
211+ . toPromise ( ) ;
212+
213+ const lastMessage = await message$ . pipe ( take ( 1 ) ) . toPromise ( ) ;
214+ expect ( containsJsonOnly ( lastMessage ) ) . toBe ( true ) ;
215+
216+ createConfigManager ( configFilePath ) . modify ( oldConfig => {
217+ oldConfig . logging . appenders . console . layout . kind = 'pattern' ;
218+ return oldConfig ;
219+ } ) ;
220+ child . kill ( 'SIGHUP' ) ;
221+
222+ await message$
223+ . pipe (
224+ filter ( messages => ! containsJsonOnly ( messages ) ) ,
225+ take ( 1 )
226+ )
227+ . toPromise ( ) ;
228+ } ,
229+ 30 * second
230+ ) ;
231+ it (
232+ 'should recreate file handle on SIGHUP' ,
233+ async function ( ) {
234+ const configFilePath = Path . resolve ( tempDir , 'kibana.yml' ) ;
235+ Fs . copyFileSync ( configFileLogFile , configFilePath ) ;
236+
237+ const logPath = Path . resolve ( tempDir , 'kibana.log' ) ;
238+ const logPathArchived = Path . resolve ( tempDir , 'kibana_archive.log' ) ;
239+
240+ createConfigManager ( configFilePath ) . modify ( oldConfig => {
241+ oldConfig . logging . appenders . file . path = logPath ;
242+ return oldConfig ;
243+ } ) ;
244+
245+ child = Child . spawn ( process . execPath , [ kibanaPath , '--oss' , '--config' , configFilePath ] ) ;
246+
247+ await watchFileUntil ( logPath , / s e t t i n g u p r o o t / , 30 * second ) ;
248+ // once the server is running, archive the log file and issue SIGHUP
249+ Fs . renameSync ( logPath , logPathArchived ) ;
250+ child . kill ( 'SIGHUP' ) ;
251+
252+ await watchFileUntil ( logPath , / R e l o a d e d l o g g i n g c o n f i g u r a t i o n d u e t o S I G H U P / , 30 * second ) ;
253+ } ,
254+ minute
255+ ) ;
256+ } ) ;
263257} ) ;
0 commit comments