/** * Logging domain types for structured log ingestion into Elasticsearch */ import type { LogLevel } from '../../core/observability/logger.js'; /** * Log level as string literal or enum value */ export type LogLevelValue = LogLevel | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'debug' | 'info' | 'warn' | 'error'; /** * Log entry structure */ export interface LogEntry { /** ISO timestamp */ timestamp: string; /** Log level */ level: LogLevelValue; /** Log message */ message: string; /** Optional correlation ID for request tracing */ correlationId?: string; /** Service name */ service?: string; /** Service version */ version?: string; /** Hostname or container ID */ host?: string; /** Environment (production, staging, development) */ environment?: string; /** Additional structured data */ metadata?: Record; /** Error details if log is error level */ error?: { name: string; message: string; stack?: string; code?: string; }; /** Performance metrics */ metrics?: { duration?: number; memory?: number; cpu?: number; }; /** Tags for categorization */ tags?: string[]; } /** * Log enrichment function */ export type LogEnricher = (entry: LogEntry) => LogEntry | Promise; /** * Log sampling strategy */ export type SamplingStrategy = 'all' | 'errors-only' | 'percentage' | 'rate-limit'; /** * Sampling configuration */ export interface SamplingConfig { /** Sampling strategy */ strategy: SamplingStrategy; /** For percentage strategy: 0-100 */ percentage?: number; /** For rate-limit strategy: logs per second */ maxLogsPerSecond?: number; /** Always sample errors regardless of strategy */ alwaysSampleErrors?: boolean; } /** * ILM (Index Lifecycle Management) policy configuration */ export interface ILMPolicyConfig { /** Policy name */ name: string; /** Hot phase: how long to keep in hot tier */ hotDuration?: string; /** Warm phase: move to warm tier after */ warmDuration?: string; /** Cold phase: move to cold tier after */ coldDuration?: string; /** Delete phase: delete after */ deleteDuration?: string; /** Rollover settings */ rollover?: { maxSize?: string; maxAge?: string; maxDocs?: number; }; } /** * Metric extraction pattern */ export interface MetricExtraction { /** Metric name */ name: string; /** Field path to extract (dot notation) */ field: string; /** Metric type */ type: 'counter' | 'gauge' | 'histogram'; /** Optional labels to extract */ labels?: string[]; } /** * Log destination configuration */ export interface LogDestinationConfig { /** Index name pattern (supports date math) */ indexPattern: string; /** Batch size for bulk operations */ batchSize?: number; /** Flush interval in milliseconds */ flushIntervalMs?: number; /** Maximum queue size before dropping logs */ maxQueueSize?: number; /** Enrichers to apply */ enrichers?: LogEnricher[]; /** Sampling configuration */ sampling?: SamplingConfig; /** ILM policy */ ilm?: ILMPolicyConfig; /** Metric extractions */ metrics?: MetricExtraction[]; /** Auto-create index template */ autoCreateTemplate?: boolean; /** Custom index template settings */ templateSettings?: { numberOfShards?: number; numberOfReplicas?: number; refreshInterval?: string; codec?: 'default' | 'best_compression'; }; /** Custom index mappings */ templateMappings?: Record; } /** * Batch result for log ingestion */ export interface LogBatchResult { /** Number of successfully indexed logs */ successful: number; /** Number of failed logs */ failed: number; /** Total logs in batch */ total: number; /** Errors encountered */ errors?: Array<{ log: LogEntry; error: string; }>; /** Time taken in milliseconds */ durationMs: number; } /** * Log destination statistics */ export interface LogDestinationStats { /** Total logs sent */ totalLogs: number; /** Total logs successfully indexed */ totalSuccessful: number; /** Total logs failed */ totalFailed: number; /** Total logs sampled out */ totalSampled: number; /** Total logs dropped due to queue overflow */ totalDropped: number; /** Current queue size */ queueSize: number; /** Average batch duration */ avgBatchDurationMs: number; /** Last flush timestamp */ lastFlushAt?: Date; }