2025-01-04 20:47:32 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
"git.resf.org/infrastructure/process-fastly-logs/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LogEntry struct {
|
|
|
|
Priority int
|
|
|
|
Timestamp time.Time
|
|
|
|
RequestTime time.Time
|
|
|
|
CacheServer string
|
|
|
|
ServiceID string
|
|
|
|
ClientIP string
|
|
|
|
RequestMethod string
|
|
|
|
RequestURL string
|
|
|
|
Protocol string
|
|
|
|
ResponseStatus int
|
|
|
|
ResponseBodyBytes int
|
|
|
|
Host string
|
|
|
|
UserAgent string
|
|
|
|
Datacenter string
|
|
|
|
GeoCity string
|
|
|
|
GeoContinentCode string
|
|
|
|
GeoRegion string
|
|
|
|
StartTime time.Time
|
|
|
|
ElapsedTimeUsec int
|
|
|
|
IsHit bool
|
|
|
|
CacheResult string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *LogEntry) Save() error {
|
|
|
|
insertSQL := `INSERT INTO logs(
|
|
|
|
priority,
|
|
|
|
timestamp,
|
|
|
|
cache_server,
|
|
|
|
service_id,
|
|
|
|
client_ip,
|
|
|
|
request_method,
|
2025-01-04 22:56:51 +00:00
|
|
|
request_time,
|
2025-01-04 20:47:32 +00:00
|
|
|
request_url,
|
|
|
|
protocol,
|
|
|
|
response_status,
|
|
|
|
response_body_bytes,
|
|
|
|
host,
|
|
|
|
user_agent,
|
|
|
|
datacenter,
|
|
|
|
geo_city,
|
|
|
|
geo_continent_code,
|
|
|
|
geo_region,
|
|
|
|
start_time,
|
|
|
|
elapsed_time_usec,
|
|
|
|
is_hit,
|
|
|
|
cache_result
|
2025-01-04 22:56:51 +00:00
|
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
2025-01-04 20:47:32 +00:00
|
|
|
|
|
|
|
statement, err := db.DB.Prepare(insertSQL)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = statement.Exec(
|
|
|
|
entry.Priority,
|
|
|
|
entry.Timestamp,
|
|
|
|
entry.CacheServer,
|
|
|
|
entry.ServiceID,
|
|
|
|
entry.ClientIP,
|
|
|
|
entry.RequestMethod,
|
2025-01-04 22:56:51 +00:00
|
|
|
entry.RequestTime,
|
2025-01-04 20:47:32 +00:00
|
|
|
entry.RequestURL,
|
|
|
|
entry.Protocol,
|
|
|
|
entry.ResponseStatus,
|
|
|
|
entry.ResponseBodyBytes,
|
|
|
|
entry.Host,
|
|
|
|
entry.UserAgent,
|
|
|
|
entry.Datacenter,
|
|
|
|
entry.GeoCity,
|
|
|
|
entry.GeoContinentCode,
|
|
|
|
entry.GeoRegion,
|
|
|
|
entry.StartTime,
|
|
|
|
entry.ElapsedTimeUsec,
|
|
|
|
entry.IsHit,
|
|
|
|
entry.CacheResult,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|