From 5a50de1154416408ba147444a3c0d0f50abe88d0 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 31 Jan 2023 09:09:36 +0100 Subject: [PATCH] cmd/ursrv: Fix broken block transfer chart --- cmd/uraggregate/main.go | 28 ++++++++++++++-------------- 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 b2e3a1f32..29ba01909 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 b2e1b0519..91e56a622 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,