feat: rename historic sql setup threshold

This commit is contained in:
Andrey Avtomonov 2026-05-11 19:08:41 +02:00
parent d47826a234
commit c91331b57a
6 changed files with 21 additions and 14 deletions

View file

@ -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 <number>', 'Historic SQL query-history window', positiveInteger)
.option('--historic-sql-min-executions <number>', 'Minimum Historic SQL executions for a template', positiveInteger)
.option(
'--historic-sql-min-calls <number>',
'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 }
: {}),

View file

@ -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,

View file

@ -715,7 +715,7 @@ describe('runKtxIngest', () => {
' historicSql:',
' enabled: true',
' dialect: postgres',
' minCalls: 2',
' minExecutions: 2',
'ingest:',
' adapters:',
' - historic-sql',

View file

@ -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: [],
},
});

View file

@ -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,
},
};
}

View file

@ -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 }