Skip to content

Commit 0701d32

Browse files
authored
šŸ› Fix for allowing custom log source with all custom table configurations (#135)
Fix for #134 ### Testing Verified test locally with the customsource configuration provided by user, it is picked up properly after this change.
1 parent 682376e commit 0701d32

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

ā€Žinfra/lib/log-source.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ export class MatanoLogSource extends Construct {
205205
constructor(scope: Construct, id: string, props: MatanoLogSourceProps) {
206206
super(scope, id);
207207

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);
211211
this.logSourceConfig = logSourceConfig;
212212

213213
if (props.config?.name === "matano_alerts") {
@@ -224,7 +224,6 @@ export class MatanoLogSource extends Construct {
224224
this.name = logSourceName;
225225

226226
if (logSourceConfig?.managed && logSourceConfig.name !== "matano_alerts") {
227-
const configPath = props.configPath!;
228227
const managedLogSourceType = logSourceConfig?.managed?.type?.toLowerCase();
229228
this.managedLogSourceType = managedLogSourceType;
230229
if (!managedLogSourceType) {
@@ -371,6 +370,29 @@ export class MatanoLogSource extends Construct {
371370
);
372371

373372
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(/tables\/.*.yml/));
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)
374396
if (Object.keys(this.tablesConfig).length == 0) {
375397
this.tablesConfig["default"] = {};
376398
}

0 commit comments

Comments
Ā (0)