From 4fcd77c560d31f3d5bf53edaae6b5ddca0183236 Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Thu, 27 Jul 2023 21:49:27 -0400 Subject: [PATCH] fix: sql query fix + logging cleanup --- common/db/anchor.go | 2 +- services/batch.go | 5 ++++- services/poll.go | 6 +++++- services/worker.go | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/db/anchor.go b/common/db/anchor.go index 1e7a8f0..4c679da 100644 --- a/common/db/anchor.go +++ b/common/db/anchor.go @@ -39,7 +39,7 @@ func NewAnchorDb(logger models.Logger) *AnchorDatabase { } func (adb *AnchorDatabase) GetRequests(ctx context.Context, status models.RequestStatus, newerThan time.Time, olderThan time.Time, limit int) ([]*models.AnchorRequest, error) { - query := "SELECT REQ.id, REQ.cid, REQ.stream_id, REQ.origin, REQ.timestamp, REQ.created_at, META.metadata FROM request AS REQ LEFT JOIN metadata AS META USING (stream_id) WHERE status = $1 AND REQ.created_at > $2 AND created_at < $3 ORDER BY REQ.created_at LIMIT $4" + query := "SELECT REQ.id, REQ.cid, REQ.stream_id, REQ.origin, REQ.timestamp, REQ.created_at, META.metadata FROM request AS REQ LEFT JOIN metadata AS META USING (stream_id) WHERE status = $1 AND REQ.created_at > $2 AND REQ.created_at < $3 ORDER BY REQ.created_at LIMIT $4" return adb.query( ctx, query, diff --git a/services/batch.go b/services/batch.go index 43a76af..1173537 100644 --- a/services/batch.go +++ b/services/batch.go @@ -77,7 +77,10 @@ func (b BatchingService) batch(ctx context.Context, anchorReqs []*models.AnchorR } b.metricService.Count(ctx, models.MetricName_BatchCreated, 1) b.metricService.Distribution(ctx, models.MetricName_BatchSize, batchSize) - b.logger.Infof("generated %v", anchorReqBatch) + b.logger.Debugw( + "batch generated", + "batch", anchorReqBatch, + ) return batchResults, nil } diff --git a/services/poll.go b/services/poll.go index 2c4fe88..421b1ff 100644 --- a/services/poll.go +++ b/services/poll.go @@ -96,7 +96,11 @@ func (p RequestPoller) Run(ctx context.Context) { // It's possible the checkpoint was updated even if a particular request in the batch failed to be // queued. if nextCheckpoint := p.sendRequestMessages(ctx, anchorReqMsgs); nextCheckpoint.After(startCheckpoint) { - p.logger.Debugf("old=%s, new=%s", startCheckpoint, nextCheckpoint) + p.logger.Debugw( + "checkpoints", + "start", startCheckpoint, + "next", nextCheckpoint, + ) if _, err = p.stateDb.UpdateCheckpoint(ctx, models.CheckpointType_RequestPoll, nextCheckpoint); err != nil { p.logger.Errorf("error updating checkpoint %s: %v", nextCheckpoint, err) } else { diff --git a/services/worker.go b/services/worker.go index 5e68078..2e8f8ee 100644 --- a/services/worker.go +++ b/services/worker.go @@ -95,7 +95,7 @@ func (w WorkerService) createJobs(ctx context.Context) error { } } w.logger.Debugw( - "counts", + "job counts", "numJobsRequired", numJobsRequired, "numExistingJobs", numExistingJobs, "numJobsAllowed", numJobsAllowed,