Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve heartbeat log #108

Merged
merged 1 commit into from
Nov 6, 2023
Merged

Improve heartbeat log #108

merged 1 commit into from
Nov 6, 2023

Conversation

Siegrift
Copy link
Collaborator

@Siegrift Siegrift commented Nov 4, 2023

Closes #107

Rationale

Rework the log message into a more machine-parseable format. Note, that I've slightly updated how the signing works (we now sign the heartbeat payload object instead of array).

The JSON log message would be:

{"context":{"airnode":"0xbF3137b0a7574563a23a8fC8badC6537F98197CC","configHash":"0x126e768ba244efdb790d63a76821047e163dfc502ace09b2546a93075594c286","currentTimestamp":"1674172803","deploymentTimestamp":"1674172800","nodeVersion":"0.1.0","signature":"0x180b77067b4c319f97fd9b0ff5d6dcbaa02647d0a41497a2256a3b8a42d5f5b16301d1b10fd899c5cba40ea165b4a8fcde7c6e486b21141f5289c0d288c2436f1c","stage":"test"},"level":"info","message":"Sending heartbeat log","ms":"+0ms","timestamp":"2023-01-20T00:00:03.000Z"}

You can identify the heartbeat log by the message field. The payload will be inside context field.

(You can verify this by changing jest.spyOn(heartbeatLogger, 'info').mockImplementation(); to jest.spyOn(heartbeatLogger, 'info') and running LOG_FORMAT=json pnpm run test heart in the heartbeat test)

@Siegrift Siegrift requested review from andreogle and bdrhn9 November 4, 2023 11:24
@Siegrift Siegrift self-assigned this Nov 4, 2023

export const signHeartbeat = async (airnodeWallet: ethers.Wallet, heartbeatPayload: unknown[]) => {
// We need to make sure the object is stringified in the same way every time, so we sort the keys alphabetically.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, winston logger sort the context keys alphabetically when formatting the log message. However, objects are unordered so we should not assume any convention and sort these explicitly.

Copy link
Contributor

@bdrhn9 bdrhn9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥 thank you for the changes, it'll make my life easy.

@Siegrift Siegrift merged commit 94bea08 into main Nov 6, 2023
4 checks passed
@Siegrift Siegrift deleted the heartbeat-log-improvement branch November 6, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve heartbeat log
3 participants