From 01288227d30d5055a86376ca006a4ce0b04419c4 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Wed, 7 Aug 2024 18:54:42 +0100 Subject: [PATCH] fix_: log utc timestamp (#5672) * fix_: log zone-agnostic time * chore_: use time.Truncate --- cmd/ping-community/main.go | 2 +- protocol/messenger.go | 4 ++-- protocol/messenger_communities.go | 10 ++-------- rpc/chain/rpc_limiter.go | 7 ++++++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/ping-community/main.go b/cmd/ping-community/main.go index dd66548be..1b7b20593 100644 --- a/cmd/ping-community/main.go +++ b/cmd/ping-community/main.go @@ -202,7 +202,7 @@ func main() { select { case <-ticker.C: count++ - timestamp := time.Now().Format(time.RFC3339) + timestamp := time.Now().UTC().Format(time.RFC3339) logger.Info("Publishing", "id", id, "count", count, "time", timestamp) inputMessage := common.NewMessage() diff --git a/protocol/messenger.go b/protocol/messenger.go index b65fa4bfa..f857836ef 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1593,8 +1593,8 @@ func (m *Messenger) watchChatsAndCommunitiesToUnmute() { case <-time.After(1 * time.Minute): response := &MessengerResponse{} m.allChats.Range(func(chatID string, c *Chat) bool { - chatMuteTill, _ := time.Parse(time.RFC3339, c.MuteTill.Format(time.RFC3339)) - currTime, _ := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) + chatMuteTill := c.MuteTill.Truncate(time.Second) + currTime := time.Now().Truncate(time.Second) if currTime.After(chatMuteTill) && !chatMuteTill.Equal(time.Time{}) && c.Muted { err := m.persistence.UnmuteChat(c.ID) diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index b47ecac98..a64d2b1c8 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -856,14 +856,8 @@ func (m *Messenger) CheckCommunitiesToUnmute() (*MessengerResponse, error) { return nil, fmt.Errorf("couldn't get all communities: %v", err) } for _, community := range communities { - communityMuteTill, err := time.Parse(time.RFC3339, community.MuteTill().Format(time.RFC3339)) - if err != nil { - return nil, err - } - currTime, err := time.Parse(time.RFC3339, time.Now().Format(time.RFC3339)) - if err != nil { - return nil, err - } + communityMuteTill := community.MuteTill().Truncate(time.Second) + currTime := time.Now().Truncate(time.Second) if currTime.After(communityMuteTill) && !communityMuteTill.Equal(time.Time{}) && community.Muted() { err := m.communitiesManager.SetMuted(community.ID(), false) diff --git a/rpc/chain/rpc_limiter.go b/rpc/chain/rpc_limiter.go index 5e9469c68..caffbc340 100644 --- a/rpc/chain/rpc_limiter.go +++ b/rpc/chain/rpc_limiter.go @@ -201,7 +201,12 @@ func (rl *RPCRequestLimiter) Allow(tag string) (bool, error) { // Check if a number of requests is over the limit within the interval if time.Since(data.CreatedAt) < data.Period || data.Period.Milliseconds() == LimitInfinitely { if data.NumReqs >= data.MaxReqs { - log.Info("Number of requests over limit", "tag", tag, "numReqs", data.NumReqs, "maxReqs", data.MaxReqs, "period", data.Period, "createdAt", data.CreatedAt) + log.Info("Number of requests over limit", + "tag", tag, + "numReqs", data.NumReqs, + "maxReqs", data.MaxReqs, + "period", data.Period, + "createdAt", data.CreatedAt.UTC()) return false, ErrRequestsOverLimit }