Skip to content

Commit

Permalink
chore: add more message details to sync health errors (#2325)
Browse files Browse the repository at this point in the history
It's useful to have more information about the original message in these
logs to understand if there are patterns in messages that result in
certain types of submit errors.

## Merge Checklist

_Choose all relevant options below by adding an `x` now or at any time
before submitting for review_

- [x] PR title adheres to the [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/) standard
- [x] PR has a
[changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets)
- [x] PR has been tagged with a change label(s) (i.e. documentation,
feature, bugfix, or chore)
- [ ] PR includes
[documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs)
if necessary.

<!-- start pr-codex -->

---

## PR-Codex overview
This PR enhances logging in the `syncHealthJob.ts` file by adding more
detailed message information for sync health errors.

### Detailed summary
- Added `unixTimestampFromMessage` method to extract Unix timestamp from
message data
- Updated `processSumbitResults` to include detailed message information
in logs for successful and failed submissions

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
aditiharini committed Sep 20, 2024
1 parent 7206e8c commit 3b1d12f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-squids-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/hubble": patch
---

chore: add more log tags to sync health errors with message details
29 changes: 26 additions & 3 deletions apps/hubble/src/network/sync/syncHealthJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SyncEngine from "./syncEngine.js";
import { RpcMetadataRetriever, SyncEngineMetadataRetriever, SyncHealthProbe } from "../../utils/syncHealth.js";
import { HubInterface } from "hubble.js";
import { peerIdFromString } from "@libp2p/peer-id";
import { bytesToHexString, Message, UserDataType } from "@farcaster/hub-nodejs";
import { bytesToHexString, fromFarcasterTime, Message, UserDataType } from "@farcaster/hub-nodejs";
import { Result } from "neverthrow";
import { SubmitError } from "../../utils/syncHealth.js";

Expand Down Expand Up @@ -62,6 +62,19 @@ export class MeasureSyncHealthJobScheduler {
return peers;
}

unixTimestampFromMessage(message: Message) {
const msgTimestamp = message.data?.timestamp;
if (msgTimestamp) {
const msgUnixTimestamp = fromFarcasterTime(msgTimestamp);
if (msgUnixTimestamp.isErr()) {
return undefined;
} else {
return msgUnixTimestamp.value;
}
}
return undefined;
}

processSumbitResults(results: Result<Message, SubmitError>[], peerId: string, startTime: number, stopTime: number) {
let numSuccesses = 0;
let numErrors = 0;
Expand All @@ -78,7 +91,7 @@ export class MeasureSyncHealthJobScheduler {
msgDetails: {
type,
fid: result.value.data?.fid,
timestamp: result.value.data?.timestamp,
timestamp: this.unixTimestampFromMessage(result.value),
hash,
peerId,
},
Expand All @@ -93,7 +106,17 @@ export class MeasureSyncHealthJobScheduler {
const hashString = bytesToHexString(result.error.originalMessage.hash);
const hash = hashString.isOk() ? hashString.value : "unable to show hash";
log.info(
{ errMessage: result.error.hubError.message, peerId, hash, startTime, stopTime },
{
errMessage: result.error.hubError.message,
peerId,
startTime,
stopTime,
msgDetails: {
fid: result.error.originalMessage.data?.fid,
timestamp: this.unixTimestampFromMessage(result.error.originalMessage),
hash,
},
},
"Failed to submit message via SyncHealth",
);

Expand Down

0 comments on commit 3b1d12f

Please sign in to comment.