diff options
author | Jakob Borg <jakob@kastelo.net> | 2023-01-31 09:09:36 +0100 |
---|---|---|
committer | Jakob Borg <jakob@kastelo.net> | 2023-01-31 09:09:36 +0100 |
commit | 5a50de1154416408ba147444a3c0d0f50abe88d0 (patch) | |
tree | da9707dc344dc99dee36aeb1ac85522aa9772c16 | |
parent | dc6d695c00cb1c575af947142e4ca6bac083bd2e (diff) |
cmd/ursrv: Fix broken block transfer chart
-rw-r--r-- | cmd/uraggregate/main.go | 28 | ||||
-rw-r--r-- | cmd/ursrv/main.go | 4 |
2 files changed, 18 insertions, 14 deletions
diff --git a/cmd/uraggregate/main.go b/cmd/uraggregate/main.go index b2e3a1f325..29ba019099 100644 --- a/cmd/uraggregate/main.go +++ b/cmd/uraggregate/main.go @@ -119,13 +119,13 @@ func setupDB(db *sql.DB) error { _, err = db.Exec(`CREATE TABLE IF NOT EXISTS BlockStats ( Day TIMESTAMP NOT NULL, Reports INTEGER NOT NULL, - Total INTEGER NOT NULL, - Renamed INTEGER NOT NULL, - Reused INTEGER NOT NULL, - Pulled INTEGER NOT NULL, - CopyOrigin INTEGER NOT NULL, - CopyOriginShifted INTEGER NOT NULL, - CopyElsewhere INTEGER NOT NULL + Total BIGINT NOT NULL, + Renamed BIGINT NOT NULL, + Reused BIGINT NOT NULL, + Pulled BIGINT NOT NULL, + CopyOrigin BIGINT NOT NULL, + CopyOriginShifted BIGINT NOT NULL, + CopyElsewhere BIGINT NOT NULL )`) if err != nil { return err @@ -306,13 +306,13 @@ func aggregateBlockStats(db *sql.DB, since time.Time) (int64, error) { SELECT DATE_TRUNC('day', Received) AS Day, COUNT(1) As Reports, - SUM((Report->'blockStats'->>'total')::numeric) AS Total, - SUM((Report->'blockStats'->>'renamed')::numeric) AS Renamed, - SUM((Report->'blockStats'->>'reused')::numeric) AS Reused, - SUM((Report->'blockStats'->>'pulled')::numeric) AS Pulled, - SUM((Report->'blockStats'->>'copyOrigin')::numeric) AS CopyOrigin, - SUM((Report->'blockStats'->>'copyOriginShifted')::numeric) AS CopyOriginShifted, - SUM((Report->'blockStats'->>'copyElsewhere')::numeric) AS CopyElsewhere + SUM((Report->'blockStats'->>'total')::numeric)::bigint AS Total, + SUM((Report->'blockStats'->>'renamed')::numeric)::bigint AS Renamed, + SUM((Report->'blockStats'->>'reused')::numeric)::bigint AS Reused, + SUM((Report->'blockStats'->>'pulled')::numeric)::bigint AS Pulled, + SUM((Report->'blockStats'->>'copyOrigin')::numeric)::bigint AS CopyOrigin, + SUM((Report->'blockStats'->>'copyOriginShifted')::numeric)::bigint AS CopyOriginShifted, + SUM((Report->'blockStats'->>'copyElsewhere')::numeric)::bigint AS CopyElsewhere FROM ReportsJson WHERE Received > $1 diff --git a/cmd/ursrv/main.go b/cmd/ursrv/main.go index b2e1b0519d..91e56a6223 100644 --- a/cmd/ursrv/main.go +++ b/cmd/ursrv/main.go @@ -1133,6 +1133,10 @@ func getBlockStats(db *sql.DB) ([][]interface{}, error) { if err != nil { return nil, err } + // Legacy bad data on certain days + if reports <= 0 || pulled < 0 || renamed < 0 || reused < 0 || copyOrigin < 0 || copyOriginShifted < 0 || copyElsewhere < 0 { + continue + } row := []interface{}{ day.Format("2006-01-02"), reports, |