• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14622981460

23 Apr 2025 04:14PM UTC coverage: 75.182% (-3.2%) from 78.42%
14622981460

Pull #87

github

blva
address comment for category and update emit tool to get tool result object
Pull Request #87: feat: core telemetry functionality

100 of 188 branches covered (53.19%)

Branch coverage included in aggregate %.

53 of 92 new or added lines in 8 files covered. (57.61%)

18 existing lines in 4 files now uncovered.

624 of 775 relevant lines covered (80.52%)

39.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/src/telemetry/eventCache.ts
1
import { BaseEvent } from "./types.js";
2
import { LRUCache } from "lru-cache";
18✔
3

4
/**
5
 * Singleton class for in-memory telemetry event caching
6
 * Provides a central storage for telemetry events that couldn't be sent
7
 * Uses LRU cache to automatically drop oldest events when limit is exceeded
8
 */
9
export class EventCache {
18✔
10
    private static instance: EventCache;
11
    private static readonly MAX_EVENTS = 1000;
18✔
12

13
    private cache: LRUCache<number, BaseEvent>;
14
    private nextId = 0;
18✔
15

16
    private constructor() {
17
        this.cache = new LRUCache({
18✔
18
            max: EventCache.MAX_EVENTS,
19
            // Using FIFO eviction strategy for events
20
            allowStale: false,
21
            updateAgeOnGet: false,
22
        });
23
    }
24

25
    /**
26
     * Gets the singleton instance of EventCache
27
     * @returns The EventCache instance
28
     */
29
    public static getInstance(): EventCache {
30
        if (!EventCache.instance) {
522✔
31
            EventCache.instance = new EventCache();
18✔
32
        }
33
        return EventCache.instance;
522✔
34
    }
35

36
    /**
37
     * Gets a copy of the currently cached events
38
     * @returns Array of cached BaseEvent objects
39
     */
40
    public getEvents(): BaseEvent[] {
NEW
41
        return Array.from(this.cache.values());
×
42
    }
43

44
    /**
45
     * Appends new events to the cached events
46
     * LRU cache automatically handles dropping oldest events when limit is exceeded
47
     * @param events - The events to append
48
     */
49
    public appendEvents(events: BaseEvent[]): void {
NEW
50
        for (const event of events) {
×
NEW
51
            this.cache.set(this.nextId++, event);
×
52
        }
53
    }
54

55
    /**
56
     * Clears all cached events
57
     */
58
    public clearEvents(): void {
NEW
59
        this.cache.clear();
×
NEW
60
        this.nextId = 0;
×
61
    }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc