Skip to content

add online filter #51

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

Closed
wants to merge 3 commits into from
Closed

Conversation

xmonader
Copy link
Contributor

Continuation of #46


// Create a response with the node data plus online status
response := gin.H{
"node": node,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like this return.

lastSeenFormatted = node.LastSeen.Format(time.RFC3339)
}

response[i] = gin.H{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like this return too

Copy link
Member

@sameh-farouk sameh-farouk left a comment

Choose a reason for hiding this comment

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

This appears to reintroduce the changes proposed in PR #46, adding the online filter. It’s also based directly on the development branch, so I assume it completely replaces the earlier PR. That said, it’s worth noting that a few aspects handled in the original PR are now missing, most notably:

  • The migration for the last_seen field, which should be stored in the DB.
  • The timestamp hint validation, which I believe is important.

This is an initial look, I'll go through the code now

@@ -78,7 +100,27 @@ func (db *Database) GetUptimeReports(nodeID uint64, start, end time.Time) ([]Upt
}

func (db *Database) CreateUptimeReport(report *UptimeReport) error {
return db.gormDB.Create(report).Error
// Start a transaction
tx := db.gormDB.Begin()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of controlling the transaction manually, Gorm offers a simple flow https://gorm.io/docs/transactions.html#Transaction


// Update the node's LastSeen field
now := time.Now()
if err := tx.Model(&Node{}).Where("node_id = ?", report.NodeID).Update("last_seen", now).Error; err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

The uptime report submitted by the node includes the timestamp at which the uptime was recorded. Shouldn't we validate that this timestamp falls within an acceptable range and use it instead? While it will typically align with the current time, edge cases may occur, which is likely why the node includes the timestamp in the report in the first place.

return tx.Error
}

// Create the uptime report
Copy link
Member

Choose a reason for hiding this comment

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

To correctly bind the expected JSON data from Zos nodes to the UptimeReportRequest struct in Go, we should adjust the struct fields to match the actual data format being sent. Specifically:

The Uptime field should be defined as int64 instead of time.Duration, and then converted to a time.Duration (by multiplying it by time.Second) inside the handler.

The Timestamp field should also be defined as int64 to represent a Unix timestamp in seconds.

This is necessary because Zos sends Uptime as the number of seconds and Timestamp as a Unix timestamp in seconds. However, Go expects time.Duration in nanoseconds and parses time.Time from ISO 8601 or RFC3339 formatted strings by default. This mismatch would lead to incorrect or failed binding unless explicitly handled.

@xmonader
Copy link
Contributor Author

It was meant to be from your branch indeed. closed.

@xmonader xmonader closed this Apr 30, 2025
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.

2 participants