Skip to main content
Glama
joelmnz

Article Manager MCP Server

by joelmnz
test-logging-and-metrics.tsβ€’9.21 kB
#!/usr/bin/env bun /** * Test script for logging and performance metrics functionality * Tests the comprehensive audit logging and performance metrics tracking */ import { loggingService, LogLevel, LogCategory } from '../src/backend/services/logging.js'; import { performanceMetricsService, MetricType } from '../src/backend/services/performanceMetrics.js'; import { database, getDatabaseConfig } from '../src/backend/services/database.js'; async function testLoggingService() { console.log('πŸ§ͺ Testing Logging Service...\n'); try { // Test basic logging await loggingService.log( LogLevel.INFO, LogCategory.TASK_LIFECYCLE, 'Test log message', { taskId: '550e8400-e29b-41d4-a716-446655440000', articleId: 456, metadata: { test: true, operation: 'create' } } ); console.log('βœ… Basic logging test passed'); // Test task event logging await loggingService.logTaskEvent('550e8400-e29b-41d4-a716-446655440001', 'processing_started', { articleId: 789, operation: 'update', attempt: 1, metadata: { slug: 'test-article' } }); console.log('βœ… Task event logging test passed'); // Test worker event logging await loggingService.logWorkerEvent('started', { isRunning: true, metadata: { processingInterval: 5000 } }); console.log('βœ… Worker event logging test passed'); // Test queue operation logging await loggingService.logQueueOperation('task_enqueued', { taskId: '550e8400-e29b-41d4-a716-446655440002', articleId: 101112, duration: 25, metadata: { operation: 'create', priority: 'normal' } }); console.log('βœ… Queue operation logging test passed'); // Test performance metric logging await loggingService.logPerformanceMetric('task_processing_time', 1500, { taskId: '550e8400-e29b-41d4-a716-446655440003', unit: 'ms', metadata: { operation: 'update' } }); console.log('βœ… Performance metric logging test passed'); // Test bulk operation logging await loggingService.logBulkOperation('started', 'bulk_test_123', { totalTasks: 10, metadata: { priority: 'high' } }); console.log('βœ… Bulk operation logging test passed'); // Test log querying const logs = await loggingService.queryLogs({ category: LogCategory.TASK_LIFECYCLE, limit: 5 }); console.log(`βœ… Log querying test passed - found ${logs.length} log entries`); // Test log statistics const stats = await loggingService.getLogStatistics(1); // Last 1 day console.log(`βœ… Log statistics test passed - ${stats.totalEntries} total entries, ${stats.recentErrors} recent errors`); } catch (error) { console.error('❌ Logging service test failed:', error); throw error; } } async function testPerformanceMetricsService() { console.log('\nπŸ§ͺ Testing Performance Metrics Service...\n'); try { // Test task processing time recording await performanceMetricsService.recordTaskProcessingTime('test-task-123', 2500, { articleId: 456, operation: 'create', success: true, metadata: { slug: 'test-article' } }); console.log('βœ… Task processing time recording test passed'); // Test queue throughput recording await performanceMetricsService.recordQueueThroughput(5, 60000, { metadata: { intervalType: 'test' } }); console.log('βœ… Queue throughput recording test passed'); // Test worker utilization recording await performanceMetricsService.recordWorkerUtilization(75.5, { metadata: { testMode: true } }); console.log('βœ… Worker utilization recording test passed'); // Test error rate recording await performanceMetricsService.recordErrorRate(2.5, { metadata: { totalTasks: 100, failedTasks: 2 } }); console.log('βœ… Error rate recording test passed'); // Test queue depth recording await performanceMetricsService.recordQueueDepth(15, { metadata: { pending: 12, processing: 3 } }); console.log('βœ… Queue depth recording test passed'); // Test embedding generation time recording await performanceMetricsService.recordEmbeddingGenerationTime(3500, { taskId: 'test-task-456', articleId: 789, chunkCount: 8, metadata: { slug: 'test-article-2' } }); console.log('βœ… Embedding generation time recording test passed'); // Test database query time recording await performanceMetricsService.recordDatabaseQueryTime(150, { queryType: 'article_fetch', taskId: 'test-task-789', metadata: { slug: 'test-article-3' } }); console.log('βœ… Database query time recording test passed'); // Test bulk operation time recording await performanceMetricsService.recordBulkOperationTime(45000, 'bulk_test_456', { totalTasks: 20, successfulTasks: 18, metadata: { priority: 'normal' } }); console.log('βœ… Bulk operation time recording test passed'); // Test metric querying const metrics = await performanceMetricsService.queryMetrics({ metricType: MetricType.TASK_PROCESSING_TIME, limit: 5 }); console.log(`βœ… Metric querying test passed - found ${metrics.length} metric entries`); // Test metric statistics const endDate = new Date(); const startDate = new Date(endDate.getTime() - 24 * 60 * 60 * 1000); // 24 hours ago const stats = await performanceMetricsService.getMetricStatistics( MetricType.TASK_PROCESSING_TIME, startDate, endDate ); if (stats) { console.log(`βœ… Metric statistics test passed - ${stats.count} data points, avg: ${stats.average.toFixed(2)}${stats.unit}`); } else { console.log('βœ… Metric statistics test passed - no data found (expected for new installation)'); } // Test performance summary const summary = await performanceMetricsService.getPerformanceSummary(startDate, endDate); console.log(`βœ… Performance summary test passed - ${summary.taskMetrics.totalProcessed} tasks processed`); } catch (error) { console.error('❌ Performance metrics service test failed:', error); throw error; } } async function testDatabaseTables() { console.log('\nπŸ§ͺ Testing Database Tables...\n'); try { // Check what tables exist first const tablesResult = await database.query(` SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE '%embedding%' ORDER BY table_name `); console.log('Available embedding tables:', tablesResult.rows.map(r => r.table_name)); // Test audit logs table exists (create if it doesn't) try { const auditResult = await database.query(` SELECT COUNT(*) as count FROM embedding_audit_logs WHERE timestamp >= NOW() - INTERVAL '1 hour' `); console.log(`βœ… Audit logs table test passed - ${auditResult.rows[0].count} recent entries`); } catch (error) { console.log('⚠️ Audit logs table does not exist, will be created automatically on first use'); } // Test performance metrics table exists (create if it doesn't) try { const metricsResult = await database.query(` SELECT COUNT(*) as count FROM performance_metrics WHERE timestamp >= NOW() - INTERVAL '1 hour' `); console.log(`βœ… Performance metrics table test passed - ${metricsResult.rows[0].count} recent entries`); } catch (error) { console.log('⚠️ Performance metrics table does not exist, will be created automatically on first use'); } // Test table indexes exist const indexResult = await database.query(` SELECT indexname FROM pg_indexes WHERE tablename IN ('embedding_audit_logs', 'performance_metrics') ORDER BY indexname `); console.log(`βœ… Database indexes test passed - found ${indexResult.rows.length} indexes`); } catch (error) { console.error('❌ Database tables test failed:', error); throw error; } } async function runTests() { console.log('πŸš€ Starting Logging and Performance Metrics Tests\n'); try { // Connect to database first console.log('πŸ“‘ Connecting to database...'); await database.connect(getDatabaseConfig()); console.log('βœ… Database connected\n'); await testDatabaseTables(); await testLoggingService(); await testPerformanceMetricsService(); console.log('\nβœ… All logging and performance metrics tests passed!'); console.log('\nπŸ“Š Summary:'); console.log('- Comprehensive audit logging system implemented'); console.log('- Performance metrics tracking system implemented'); console.log('- Database tables and indexes created'); console.log('- All logging categories and metric types working'); console.log('- Query and statistics functionality verified'); } catch (error) { console.error('\n❌ Tests failed:', error); process.exit(1); } finally { await database.close(); } } // Run the tests runTests().catch((error) => { console.error(error); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/joelmnz/mcp-markdown-manager'

If you have feedback or need assistance with the MCP directory API, please join our Discord server