From c91331b57ad60961cb07b66dff82b982aa9a522e Mon Sep 17 00:00:00 2001 From: Andrey Avtomonov <7889985+andreybavt@users.noreply.github.com> Date: Mon, 11 May 2026 19:08:41 +0200 Subject: [PATCH] feat: rename historic sql setup threshold --- packages/cli/src/commands/setup-commands.ts | 8 ++++++-- packages/cli/src/index.test.ts | 4 ++-- packages/cli/src/ingest.test.ts | 2 +- packages/cli/src/setup-databases.test.ts | 13 ++++++------- packages/cli/src/setup-databases.ts | 4 ++-- packages/cli/src/setup.ts | 4 ++++ 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/commands/setup-commands.ts b/packages/cli/src/commands/setup-commands.ts index 16e3cc28..f15b6680 100644 --- a/packages/cli/src/commands/setup-commands.ts +++ b/packages/cli/src/commands/setup-commands.ts @@ -117,6 +117,7 @@ function shouldShowSetupEntryMenu( enableHistoricSql?: boolean; disableHistoricSql?: boolean; historicSqlWindowDays?: number; + historicSqlMinExecutions?: number; historicSqlMinCalls?: number; historicSqlServiceAccountPattern?: string[]; historicSqlRedactionPattern?: string[]; @@ -186,6 +187,7 @@ function shouldShowSetupEntryMenu( 'enableHistoricSql', 'disableHistoricSql', 'historicSqlWindowDays', + 'historicSqlMinExecutions', 'historicSqlMinCalls', 'skipDatabases', 'source', @@ -274,9 +276,10 @@ export function registerSetupCommands(program: Command, context: KtxCliCommandCo .option('--enable-historic-sql', 'Enable Historic SQL when the selected database supports it', false) .option('--disable-historic-sql', 'Disable Historic SQL for the selected database', false) .option('--historic-sql-window-days ', 'Historic SQL query-history window', positiveInteger) + .option('--historic-sql-min-executions ', 'Minimum Historic SQL executions for a template', positiveInteger) .option( '--historic-sql-min-calls ', - 'Postgres Historic SQL pg_stat_statements minimum calls floor', + 'Alias for --historic-sql-min-executions', positiveInteger, ) .option( @@ -360,6 +363,7 @@ export function registerSetupCommands(program: Command, context: KtxCliCommandCo const mode = options.new ? 'new' : options.existing ? 'existing' : 'auto'; const resolvedAgentScope = options.global ? 'global' : options.agentScope; + const historicSqlMinExecutions = options.historicSqlMinExecutions ?? options.historicSqlMinCalls; await runSetupArgs(context, { command: 'run', projectDir: resolveCommandProjectDir(command), @@ -388,7 +392,7 @@ export function registerSetupCommands(program: Command, context: KtxCliCommandCo ...(options.enableHistoricSql ? { enableHistoricSql: true } : {}), ...(options.disableHistoricSql ? { disableHistoricSql: true } : {}), ...(options.historicSqlWindowDays !== undefined ? { historicSqlWindowDays: options.historicSqlWindowDays } : {}), - ...(options.historicSqlMinCalls !== undefined ? { historicSqlMinCalls: options.historicSqlMinCalls } : {}), + ...(historicSqlMinExecutions !== undefined ? { historicSqlMinExecutions } : {}), ...(options.historicSqlServiceAccountPattern.length > 0 ? { historicSqlServiceAccountPatterns: options.historicSqlServiceAccountPattern } : {}), diff --git a/packages/cli/src/index.test.ts b/packages/cli/src/index.test.ts index f26215d1..def47cd8 100644 --- a/packages/cli/src/index.test.ts +++ b/packages/cli/src/index.test.ts @@ -1182,7 +1182,7 @@ describe('runKtxCli', () => { '--enable-historic-sql', '--historic-sql-window-days', '30', - '--historic-sql-min-calls', + '--historic-sql-min-executions', '12', ], setupIo.io, @@ -1205,7 +1205,7 @@ describe('runKtxCli', () => { databaseSchemas: ['public'], enableHistoricSql: true, historicSqlWindowDays: 30, - historicSqlMinCalls: 12, + historicSqlMinExecutions: 12, skipDatabases: false, }), setupIo.io, diff --git a/packages/cli/src/ingest.test.ts b/packages/cli/src/ingest.test.ts index a2784266..f6907895 100644 --- a/packages/cli/src/ingest.test.ts +++ b/packages/cli/src/ingest.test.ts @@ -715,7 +715,7 @@ describe('runKtxIngest', () => { ' historicSql:', ' enabled: true', ' dialect: postgres', - ' minCalls: 2', + ' minExecutions: 2', 'ingest:', ' adapters:', ' - historic-sql', diff --git a/packages/cli/src/setup-databases.test.ts b/packages/cli/src/setup-databases.test.ts index 3f268ce8..97cf58e7 100644 --- a/packages/cli/src/setup-databases.test.ts +++ b/packages/cli/src/setup-databases.test.ts @@ -1237,7 +1237,7 @@ describe('setup databases step', () => { expect(config.ingest.adapters).toContain('historic-sql'); }); - it('writes Postgres Historic SQL config with minCalls and ignores window/redaction output', async () => { + it('writes Postgres Historic SQL config with minExecutions and ignores window/redaction output', async () => { const io = makeIo(); const result = await runKtxSetupDatabasesStep( { @@ -1249,7 +1249,7 @@ describe('setup databases step', () => { databaseSchemas: ['public'], enableHistoricSql: true, historicSqlWindowDays: 30, - historicSqlMinCalls: 12, + historicSqlMinExecutions: 12, historicSqlServiceAccountPatterns: ['^svc_'], historicSqlRedactionPatterns: ['(?i)secret'], skipDatabases: false, @@ -1271,11 +1271,11 @@ describe('setup databases step', () => { historicSql: { enabled: true, dialect: 'postgres', - minCalls: 12, - maxTemplatesPerRun: 5000, + minExecutions: 12, serviceAccountUserPatterns: ['^svc_'], }, }); + expect(config.connections.warehouse.historicSql).not.toHaveProperty('minCalls'); expect(config.connections.warehouse.historicSql).not.toHaveProperty('windowDays'); expect(config.connections.warehouse.historicSql).not.toHaveProperty('redactionPatterns'); expect(config.ingest.adapters).toContain('historic-sql'); @@ -1354,7 +1354,7 @@ describe('setup databases step', () => { databaseConnectionIds: ['warehouse'], databaseSchemas: [], enableHistoricSql: true, - historicSqlMinCalls: 8, + historicSqlMinExecutions: 8, skipDatabases: false, }, io.io, @@ -1371,8 +1371,7 @@ describe('setup databases step', () => { historicSql: { enabled: true, dialect: 'postgres', - minCalls: 8, - maxTemplatesPerRun: 5000, + minExecutions: 8, serviceAccountUserPatterns: [], }, }); diff --git a/packages/cli/src/setup-databases.ts b/packages/cli/src/setup-databases.ts index 2a16e086..79543c93 100644 --- a/packages/cli/src/setup-databases.ts +++ b/packages/cli/src/setup-databases.ts @@ -34,6 +34,7 @@ export interface KtxSetupDatabasesArgs { enableHistoricSql?: boolean; disableHistoricSql?: boolean; historicSqlWindowDays?: number; + historicSqlMinExecutions?: number; historicSqlMinCalls?: number; historicSqlServiceAccountPatterns?: string[]; historicSqlRedactionPatterns?: string[]; @@ -676,8 +677,7 @@ async function maybeApplyHistoricSqlConfig(input: { ...input.connection, historicSql: { ...common, - minCalls: input.args.historicSqlMinCalls ?? 5, - maxTemplatesPerRun: 5000, + minExecutions: input.args.historicSqlMinExecutions ?? input.args.historicSqlMinCalls ?? 5, }, }; } diff --git a/packages/cli/src/setup.ts b/packages/cli/src/setup.ts index 5eac2e27..89c5dcdc 100644 --- a/packages/cli/src/setup.ts +++ b/packages/cli/src/setup.ts @@ -82,6 +82,7 @@ export type KtxSetupArgs = enableHistoricSql?: boolean; disableHistoricSql?: boolean; historicSqlWindowDays?: number; + historicSqlMinExecutions?: number; historicSqlMinCalls?: number; historicSqlServiceAccountPatterns?: string[]; historicSqlRedactionPatterns?: string[]; @@ -644,6 +645,9 @@ async function runKtxSetupInner(args: KtxSetupArgs, io: KtxCliIo, deps: KtxSetup ...(args.enableHistoricSql !== undefined ? { enableHistoricSql: args.enableHistoricSql } : {}), ...(args.disableHistoricSql !== undefined ? { disableHistoricSql: args.disableHistoricSql } : {}), ...(args.historicSqlWindowDays !== undefined ? { historicSqlWindowDays: args.historicSqlWindowDays } : {}), + ...(args.historicSqlMinExecutions !== undefined + ? { historicSqlMinExecutions: args.historicSqlMinExecutions } + : {}), ...(args.historicSqlMinCalls !== undefined ? { historicSqlMinCalls: args.historicSqlMinCalls } : {}), ...(args.historicSqlServiceAccountPatterns ? { historicSqlServiceAccountPatterns: args.historicSqlServiceAccountPatterns }