Conversation
Greptile OverviewGreptile SummaryThis PR adds Prometheus metrics support to expose live event stream counts via a new Key Changes:
Implementation: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Prometheus as Prometheus Server
participant Controller as PrometheusController
participant Service as PrometheusService
participant EventStream as EventStreamService
participant Cache as CacheStorageService
participant Redis as Redis
Note over Service: On Module Init
Service->>Service: collectDefaultMetrics()
EventStream->>Service: createGauge(config)
Service->>Service: Register gauge with collect callback
Note over Prometheus: Periodic Scrape
Prometheus->>Controller: GET /metrics
Controller->>Service: getMetrics()
Service->>Service: Trigger collect callbacks
Service->>EventStream: collect() callback executed
EventStream->>EventStream: getTotalActiveStreamCount()
EventStream->>Cache: scanAndCountSetMembers('workspace:*:activeStreams')
Cache->>Redis: SCAN with pattern matching
Redis-->>Cache: Return matching keys
Cache->>Redis: SCARD for each key
Redis-->>Cache: Return set member counts
Cache-->>EventStream: Return total count
EventStream->>Service: gauge.set(count)
Service-->>Controller: Return formatted metrics
Controller-->>Prometheus: 200 OK with metrics data
|
packages/twenty-server/src/engine/core-modules/metrics/prometheus.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/cache-storage/services/cache-storage.service.ts
Show resolved
Hide resolved
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:61555 This environment will automatically shut down when the PR is closed or after 5 hours. |
etiennejouan
left a comment
There was a problem hiding this comment.
Looks good but I wonder why we don't rely on OTEL API (for all metrics collection) ?
c899bb2 to
9861253
Compare
etiennejouan
left a comment
There was a problem hiding this comment.
Tested and it works great ! 👏
(Difference with previous implementation is that all metrics are exported on /metrics endpoint, not only the one you want)
|
|
||
| if (keys.length > 0) { | ||
| const counts = await Promise.all( | ||
| keys.map((key) => redisClient.sCard(key)), |
There was a problem hiding this comment.
This could be painful (N network calls), can we use Redis pipeline for that instead?
Create a metric endpoint and expose prometheus gauge for event stream count.
Create a metric endpoint and expose prometheus gauge for event stream count.