UNPKG

@himorishige/noren-devtools

Version:

Development and testing tools for Noren PII detection library

102 lines (101 loc) 3.28 kB
/** * P3-0: Metrics collection infrastructure for performance and accuracy monitoring * Web Standards only - no Node.js-specific APIs */ /** * Individual metric data point */ export interface MetricEntry { timestamp: number; name: string; value: number; labels?: Record<string, string>; metadata?: Record<string, unknown>; } /** * Metrics aggregation types */ export type AggregationType = 'sum' | 'average' | 'max' | 'min' | 'count' | 'histogram'; /** * Metric definition with aggregation rules */ export interface MetricDefinition { name: string; description: string; aggregation: AggregationType; buckets?: number[]; labels?: string[]; } /** * Performance measurement result */ export interface PerformanceMetric { duration_ms: number; memory_delta_bytes?: number; cpu_time_ms?: number; } /** * Accuracy measurement result */ export interface AccuracyMetric { hits_detected: number; false_positives?: number; false_negatives?: number; confidence_distribution?: number[]; } /** * Metrics collector interface - can be implemented for different backends */ export interface MetricsCollector { recordMetric(entry: MetricEntry): void; recordPerformance(operation: string, metric: PerformanceMetric, labels?: Record<string, string>): void; recordAccuracy(operation: string, metric: AccuracyMetric, labels?: Record<string, string>): void; flush(): Promise<void>; } /** * In-memory metrics collector for testing and development */ export declare class InMemoryMetricsCollector implements MetricsCollector { private metrics; private readonly maxEntries; constructor(maxEntries?: number); recordMetric(entry: MetricEntry): void; recordPerformance(operation: string, metric: PerformanceMetric, labels?: Record<string, string>): void; recordAccuracy(operation: string, metric: AccuracyMetric, labels?: Record<string, string>): void; flush(): Promise<void>; getMetrics(): MetricEntry[]; getMetricsByName(name: string): MetricEntry[]; getMetricsByOperation(operation: string): MetricEntry[]; clear(): void; getMetricsSummary(): Record<string, { count: number; avg: number; min: number; max: number; }>; } /** * No-op metrics collector for production when metrics are disabled */ export declare class NoOpMetricsCollector implements MetricsCollector { recordMetric(_entry: MetricEntry): void; recordPerformance(_operation: string, _metric: PerformanceMetric, _labels?: Record<string, string>): void; recordAccuracy(_operation: string, _metric: AccuracyMetric, _labels?: Record<string, string>): void; flush(): Promise<void>; } /** * Set the global metrics collector */ export declare function setMetricsCollector(collector: MetricsCollector): void; /** * Get the current metrics collector */ export declare function getMetricsCollector(): MetricsCollector; /** * Utility function to measure performance of an operation */ export declare function measurePerformance<T>(operation: string, fn: () => T | Promise<T>, labels?: Record<string, string>): Promise<T>; /** * Predefined metric definitions for Noren */ export declare const NOREN_METRICS: Record<string, MetricDefinition>;