From b3db3b1ea37908b89f3f0b08a3790e84e4cb1188 Mon Sep 17 00:00:00 2001 From: codebender <167290009+codebender37@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:51:46 +0630 Subject: [PATCH] fix: fixed from PR feedback --- cmd/seed/fixtures/fixture_service.go | 2 +- cmd/seed/task_data.json | 15 +++++---------- pkg/api/utils.go | 4 ++-- pkg/cache/cache.go | 5 +++-- pkg/metric/metrics_service.go | 12 +++++++----- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cmd/seed/fixtures/fixture_service.go b/cmd/seed/fixtures/fixture_service.go index ba0c692..1c8cd32 100644 --- a/cmd/seed/fixtures/fixture_service.go +++ b/cmd/seed/fixtures/fixture_service.go @@ -109,7 +109,7 @@ func (o *FixtureService) CreateDefaultTask(ctx context.Context, title string, ex db.Task.Type.Set(db.TaskTypeCodeGeneration), db.Task.TaskData.Set(types.JSON(taskDataJSON)), db.Task.Status.Set(db.TaskStatusInProgress), - db.Task.MaxResults.Set(10), + db.Task.MaxResults.Set(1), db.Task.NumResults.Set(0), db.Task.NumCriteria.Set(0), db.Task.TotalReward.Set(101.0), diff --git a/cmd/seed/task_data.json b/cmd/seed/task_data.json index 5e79af1..914484d 100644 --- a/cmd/seed/task_data.json +++ b/cmd/seed/task_data.json @@ -6,17 +6,12 @@ "max": 100, "min": 1, "type": "multi-score", - "options": [ - "459520f8-b654-41a8-9f94-93e003c4ecb5", - "024ffca6-aac0-40d2-959b-1ab7b165b68e", - "4fa05b97-cd66-4df7-bb3a-298d2b04b148", - "1b26f82c-935f-432b-a60d-f21204e580f2" - ] + "options": ["1", "2", "3", "4"] } ], "responses": [ { - "model": "459520f8-b654-41a8-9f94-93e003c4ecb5", + "model": "1", "completion": { "files": [ { @@ -29,7 +24,7 @@ } }, { - "model": "024ffca6-aac0-40d2-959b-1ab7b165b68e", + "model": "2", "completion": { "files": [ { @@ -42,7 +37,7 @@ } }, { - "model": "4fa05b97-cd66-4df7-bb3a-298d2b04b148", + "model": "3", "completion": { "files": [ { @@ -55,7 +50,7 @@ } }, { - "model": "1b26f82c-935f-432b-a60d-f21204e580f2", + "model": "4", "completion": { "files": [ { diff --git a/pkg/api/utils.go b/pkg/api/utils.go index 8b30d64..a6d9d5b 100644 --- a/pkg/api/utils.go +++ b/pkg/api/utils.go @@ -117,11 +117,11 @@ func getCallerIP(c *gin.Context) string { // TODO - Need to check if this is the correct way without getting spoofing if runtimeEnv := utils.LoadDotEnv("RUNTIME_ENV"); runtimeEnv == "aws" { callerIp := c.Request.Header.Get("X-Original-Forwarded-For") - log.Trace().Msgf("Got caller IP from X-Original-Forwarded-For header: %s", callerIp) + log.Debug().Msgf("Got caller IP from X-Original-Forwarded-For header: %s", callerIp) return callerIp } callerIp := c.ClientIP() - log.Trace().Msgf("Got caller IP from ClientIP: %s", callerIp) + log.Debug().Msgf("Got caller IP from ClientIP: %s", callerIp) return callerIp } diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 928e3a1..6d4872a 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -41,8 +41,9 @@ const ( TasksByWorker CacheKey = "task:worker" // List of tasks by worker // Task Result cache keys - TaskResultByTaskAndWorker CacheKey = "tr:task:worker" // Task result by task ID and worker ID - TaskResultByWorker CacheKey = "tr:worker" // Task results by worker ID + TaskResultByTaskAndWorker CacheKey = "tr:task:worker" // Task result by task ID and worker ID + TaskResultByWorker CacheKey = "tr:worker" // Task results by worker ID + TaskResultsTotal CacheKey = "metrics:task_results:total" // Total task results count // Worker cache keys WorkerByWallet CacheKey = "worker:wallet" // Worker by wallet address diff --git a/pkg/metric/metrics_service.go b/pkg/metric/metrics_service.go index 7f8d517..2e1f5fa 100644 --- a/pkg/metric/metrics_service.go +++ b/pkg/metric/metrics_service.go @@ -56,16 +56,18 @@ func (metricService *MetricService) UpdateCompletedTaskCount(ctx context.Context } func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Context) error { - cache := cache.GetCacheInstance() + cacheInstance := cache.GetCacheInstance() metricORM := orm.NewMetricsORM() - cacheKey := "metrics:task_results:total" + cacheKey := string(cache.TaskResultsTotal) // Try to get current count from Redis - _, err := cache.Redis.Get(ctx, cacheKey).Int64() + currentCount, err := cacheInstance.Redis.Get(ctx, cacheKey).Int64() + log.Info().Int64("CurrentCount", currentCount).Msg("Current count") if err == redis.Nil { // Key doesn't exist (e.g., after Redis restart) // Get the last metric from database lastMetric, err := metricORM.GetMetricsDataByMetricType(ctx, db.MetricsTypeTotalNumTaskResults) + log.Info().Interface("LastMetric", lastMetric).Msg("Last metric") if err != nil && !db.IsErrNotFound(err) { return err } @@ -78,7 +80,7 @@ func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Cont } currentCount := int64(lastMetricData.TotalNumTasksResults) // Set the Redis counter to last known value - if err := cache.Redis.Set(ctx, cacheKey, currentCount, 0).Err(); err != nil { + if err := cacheInstance.Redis.Set(ctx, cacheKey, currentCount, 0).Err(); err != nil { return err } } @@ -87,7 +89,7 @@ func (metricService *MetricService) UpdateTotalTaskResultsCount(ctx context.Cont } // Increment the counter - count, err := cache.Redis.Incr(ctx, cacheKey).Result() + count, err := cacheInstance.Redis.Incr(ctx, cacheKey).Result() if err != nil { log.Error().Err(err).Msg("Failed to increment task results count") return err