Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/dbagent/src/components/monitoring/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
updateSchedule,
updateScheduleRunData
} from '~/lib/db/schedules';
import { utcToLocalDate } from '~/lib/monitoring/scheduler';
import { listPlaybooks } from '~/lib/tools/playbooks';

export async function generateCronExpression(description: string): Promise<string> {
Expand Down Expand Up @@ -43,10 +44,10 @@ export async function actionGetSchedules(): Promise<Schedule[]> {
// Ensure last_run is serialized as string
schedules.forEach((schedule) => {
if (schedule.lastRun) {
schedule.lastRun = schedule.lastRun.toString();
schedule.lastRun = utcToLocalDate(schedule.lastRun).toString();
}
if (schedule.nextRun) {
schedule.nextRun = schedule.nextRun.toString();
schedule.nextRun = utcToLocalDate(schedule.nextRun).toString();
}
});
return schedules;
Expand Down
1 change: 0 additions & 1 deletion apps/dbagent/src/components/onboarding/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getIntegration } from '~/lib/db/integrations';
// Server action to get completed tasks
export async function getCompletedTasks(): Promise<string[]> {
const completedTasks: string[] = [];
// TODO: Implement getting completed tasks from database
const connection = await getDefaultConnection();
if (!connection) {
return [];
Expand Down
8 changes: 7 additions & 1 deletion apps/dbagent/src/lib/monitoring/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import {
import { env } from '../env/server';
import { runSchedule } from './runner';

export function utcToLocalDate(utcString: string): Date {
const date = new Date(utcString);
const offset = date.getTimezoneOffset() * 60000; // Convert offset to milliseconds
return new Date(date.getTime() - offset);
}

export function shouldRunSchedule(schedule: Schedule, now: Date): boolean {
if (schedule.enabled === false || !schedule.nextRun) return false;
const nextRun = new Date(schedule.nextRun);
const nextRun = utcToLocalDate(schedule.nextRun);

if (schedule.status !== 'scheduled') {
if (
Expand Down
4 changes: 3 additions & 1 deletion apps/dbagent/src/lib/targetdb/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export async function getPerformanceSettings(connString: string): Promise<Perfor
'maintenance_work_mem',
'lock_timeout',
'idle_in_transaction_session_timeout',
'checkpoint_completion_target',
'idle_session_timeout',
'default_transaction_isolation',
'max_wal_size',
Expand All @@ -139,7 +140,8 @@ export async function getPerformanceSettings(connString: string): Promise<Perfor
'wal_buffers',
'effective_io_concurrency',
'random_page_cost',
'seq_page_cost'
'seq_page_cost',
'huge_pages'
)
`);
return result.rows;
Expand Down
5 changes: 3 additions & 2 deletions apps/dbagent/src/lib/tools/dbinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getClusterByConnection } from '../db/clusters';

import { DbConnection } from '../db/connections';
import { getDbInfo } from '../db/dbinfo';
import { getPerformanceSettings, getVacuumSettings } from '../targetdb/db';

export async function getTablesAndInstanceInfo(connection: DbConnection): Promise<string> {
try {
Expand All @@ -24,8 +25,8 @@ ${JSON.stringify(cluster)}
}

export async function getPerformanceAndVacuumSettings(connection: DbConnection): Promise<string> {
const performanceSettings = await getDbInfo(connection.id, 'performance_settings');
const vacuumSettings = await getDbInfo(connection.id, 'vacuum_settings');
const performanceSettings = await getPerformanceSettings(connection.connstring);
const vacuumSettings = await getVacuumSettings(connection.connstring);

return `
Performance settings: ${JSON.stringify(performanceSettings)}
Expand Down
37 changes: 37 additions & 0 deletions apps/dbagent/src/lib/tools/playbooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,49 @@ Record any issues found and actions taken.
Note any recurring patterns or areas for improvement.
`;

const TUNING_PLAYBOOK = `
Objective: Recommend performance and vacuum settings for the database.

Step 1:
Use the getTablesAndInstanceInfo tool to gather what you know about the database and the cluster/instance type

Step 2:
Think about what CPU/memory does that AWS instance class have?

Step 3:
Given the information you collected above, think about the ideal settings for the following parameters:
- max_connections
- shared_buffers
- effective_cache_size
- maintenance_work_mem
- checkpoint_completion_target
- wal_buffers
- default_statistics_target
- random_page_cost
- effective_io_concurrency
- work_mem
- huge_pages
- min_wal_size
- max_wal_size
- max_worker_processes
- max_parallel_workers_per_gather
- max_parallel_workers
- max_parallel_maintenance_workers.

Step 4:
Now compare with the value you read via the tool getPerformanceAndVacuumSettings and see if there's anything you'd change.

Report your findings in a structured way, with the settings you'd change, and the reason for the change. Highlight the most important changes first.
`;

export function getPlaybook(name: string): string {
switch (name) {
case 'investigateSlowQueries':
return SLOW_QUERIES_PLAYBOOK;
case 'generalMonitoring':
return GENERAL_MONITORING_PLAYBOOK;
case 'tuneSettings':
return TUNING_PLAYBOOK;
default:
return `Error:Playbook ${name} not found`;
}
Expand Down
Loading