mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
b7d38590ba
- Introduced NodeAccessLog model and corresponding database migrations. - Implemented access log retrieval in the service layer. - Created API endpoint for accessing logs with appropriate security measures. - Developed frontend components for displaying access logs, including filtering and summary statistics. - Updated observability buffer to include access logs and ensure proper merging and retention. - Enhanced traffic report and observability tests to validate new access log features. - Updated documentation to reflect changes in access log handling and data retention policies.
31 lines
930 B
Go
31 lines
930 B
Go
package model
|
|
|
|
import "time"
|
|
|
|
type NodeAccessLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
NodeID string `json:"node_id" gorm:"index;size:64;not null"`
|
|
LoggedAt time.Time `json:"logged_at" gorm:"index"`
|
|
RemoteAddr string `json:"remote_addr" gorm:"size:128"`
|
|
Host string `json:"host" gorm:"size:255"`
|
|
Path string `json:"path" gorm:"size:2048"`
|
|
StatusCode int `json:"status_code"`
|
|
RawJSON string `json:"raw_json" gorm:"type:text"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func ListNodeAccessLogs(nodeID string, since time.Time, limit int) (logs []*NodeAccessLog, err error) {
|
|
query := DB.Order("logged_at desc, id desc")
|
|
if nodeID != "" {
|
|
query = query.Where("node_id = ?", nodeID)
|
|
}
|
|
if !since.IsZero() {
|
|
query = query.Where("logged_at >= ?", since)
|
|
}
|
|
if limit > 0 {
|
|
query = query.Limit(limit)
|
|
}
|
|
err = query.Find(&logs).Error
|
|
return logs, err
|
|
}
|