Переглянути джерело

fix(syncing-server): add debug logs to redis metrics store

Karol Sójko 1 рік тому
батько
коміт
a4ad37f309

+ 5 - 1
packages/syncing-server/src/Bootstrap/Container.ts

@@ -585,7 +585,11 @@ export class ContainerConfigLoader {
       container
       container
         .bind<MetricsStoreInterface>(TYPES.Sync_MetricsStore)
         .bind<MetricsStoreInterface>(TYPES.Sync_MetricsStore)
         .toConstantValue(
         .toConstantValue(
-          new RedisMetricStore(container.get<Redis>(TYPES.Sync_Redis), container.get<TimerInterface>(TYPES.Sync_Timer)),
+          new RedisMetricStore(
+            container.get<Redis>(TYPES.Sync_Redis),
+            container.get<TimerInterface>(TYPES.Sync_Timer),
+            container.get<Logger>(TYPES.Sync_Logger),
+          ),
         )
         )
     }
     }
 
 

+ 19 - 0
packages/syncing-server/src/Infra/Redis/RedisMetricStore.ts

@@ -5,6 +5,7 @@ import { MetricsStoreInterface } from '../../Domain/Metrics/MetricsStoreInterfac
 import { Metric } from '../../Domain/Metrics/Metric'
 import { Metric } from '../../Domain/Metrics/Metric'
 import { Uuid } from '@standardnotes/domain-core'
 import { Uuid } from '@standardnotes/domain-core'
 import { MetricsSummary } from '../../Domain/Metrics/MetricsSummary'
 import { MetricsSummary } from '../../Domain/Metrics/MetricsSummary'
+import { Logger } from 'winston'
 
 
 export class RedisMetricStore implements MetricsStoreInterface {
 export class RedisMetricStore implements MetricsStoreInterface {
   private readonly METRIC_PREFIX = 'metric'
   private readonly METRIC_PREFIX = 'metric'
@@ -13,6 +14,7 @@ export class RedisMetricStore implements MetricsStoreInterface {
   constructor(
   constructor(
     private redisClient: IORedis.Redis,
     private redisClient: IORedis.Redis,
     private timer: TimerInterface,
     private timer: TimerInterface,
+    private logger: Logger,
   ) {}
   ) {}
 
 
   async getUserBasedMetricsSummaryWithinTimeRange(dto: {
   async getUserBasedMetricsSummaryWithinTimeRange(dto: {
@@ -21,8 +23,20 @@ export class RedisMetricStore implements MetricsStoreInterface {
     from: Date
     from: Date
     to: Date
     to: Date
   }): Promise<MetricsSummary> {
   }): Promise<MetricsSummary> {
+    this.logger.debug(`Fetching user based metrics summary for ${dto.metricName}.`, {
+      codeTag: 'RedisMetricStore',
+      userId: dto.userUuid.value,
+      from: dto.from.toISOString(),
+      to: dto.to.toISOString(),
+    })
+
     const keys = this.getKeysRepresentingMinutesBetweenFromAndTo(dto.from, dto.to)
     const keys = this.getKeysRepresentingMinutesBetweenFromAndTo(dto.from, dto.to)
 
 
+    this.logger.debug(`Fetching user based metrics summary for ${dto.metricName} - keys: ${keys.join(', ')}.`, {
+      codeTag: 'RedisMetricStore',
+      userId: dto.userUuid.value,
+    })
+
     let sum = 0
     let sum = 0
     let max = 0
     let max = 0
     let min = 0
     let min = 0
@@ -32,6 +46,11 @@ export class RedisMetricStore implements MetricsStoreInterface {
       keys.map((key) => `${this.METRIC_PER_USER_PREFIX}:${dto.userUuid.value}:${dto.metricName}:${key}`),
       keys.map((key) => `${this.METRIC_PER_USER_PREFIX}:${dto.userUuid.value}:${dto.metricName}:${key}`),
     )
     )
 
 
+    this.logger.debug(`Fetching user based metrics summary for ${dto.metricName} - values: ${values.join(', ')}.`, {
+      codeTag: 'RedisMetricStore',
+      userId: dto.userUuid.value,
+    })
+
     for (const value of values) {
     for (const value of values) {
       if (!value) {
       if (!value) {
         continue
         continue