@@ -205,9 +205,9 @@ export class MatanoLogSource extends Construct {
205
205
constructor ( scope : Construct , id : string , props : MatanoLogSourceProps ) {
206
206
super ( scope , id ) ;
207
207
208
- const logSourceConfig = props . config
209
- ? props . config
210
- : ( readConfig ( props . configPath ! , "log_source.yml" ) as LogSourceConfig ) ;
208
+ const configPath = props . configPath ! ;
209
+
210
+ const logSourceConfig = props . config ? props . config : ( readConfig ( configPath , "log_source.yml" ) as LogSourceConfig ) ;
211
211
this . logSourceConfig = logSourceConfig ;
212
212
213
213
if ( props . config ?. name === "matano_alerts" ) {
@@ -224,7 +224,6 @@ export class MatanoLogSource extends Construct {
224
224
this . name = logSourceName ;
225
225
226
226
if ( logSourceConfig ?. managed && logSourceConfig . name !== "matano_alerts" ) {
227
- const configPath = props . configPath ! ;
228
227
const managedLogSourceType = logSourceConfig ?. managed ?. type ?. toLowerCase ( ) ;
229
228
this . managedLogSourceType = managedLogSourceType ;
230
229
if ( ! managedLogSourceType ) {
@@ -371,6 +370,29 @@ export class MatanoLogSource extends Construct {
371
370
) ;
372
371
373
372
const logSourceConfigToMerge = diff ( this . logSourceConfig , logSourceLevelConfig ) ;
373
+
374
+ // if no table configs have been loaded during above managed log source traversal, load table configs now from user tables/ path
375
+ if ( Object . keys ( this . tablesConfig ) . length == 0 ) {
376
+ // tableConfig has path like tables/*.yml, where the * part is the table name that should be used as a fallback table name
377
+ const tableConfigFilePaths = walkdirSync ( configPath )
378
+ . map ( ( p ) => path . relative ( configPath , p ) )
379
+ . filter ( ( p ) => p . match ( / t a b l e s \/ .* .y m l / ) ) ;
380
+ for ( const tableConfigFilePath of tableConfigFilePaths ) {
381
+ const tableConfig = readConfig ( configPath , tableConfigFilePath ) ;
382
+ if ( tableConfig . name == null ) {
383
+ // fail
384
+ fail ( `Please specify a table name: ${ tableConfigFilePath } ` ) ;
385
+ }
386
+ // fail if table name is already defined
387
+ if ( tableConfig . name in this . tablesConfig ) {
388
+ fail ( `Table name ${ tableConfig . name } is already defined in log source: ${ logSourceName } ` ) ;
389
+ }
390
+
391
+ this . tablesConfig [ tableConfig . name ] = tableConfig ;
392
+ }
393
+ }
394
+
395
+ // if no still no tables/ added, assume a default table (from log_source.yml)
374
396
if ( Object . keys ( this . tablesConfig ) . length == 0 ) {
375
397
this . tablesConfig [ "default" ] = { } ;
376
398
}
0 commit comments