diff --git a/pkg/types/types.go b/pkg/types/types.go index e7c841c..a8faf32 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -21,7 +21,7 @@ type TelemetryRequest struct { TelemetryData *json.RawMessage `json:"telemetry_data"` } -type CommonFields struct { +type TelemetryRecord struct { NodeName string `json:"nodeName"` PeerID string `json:"peerId"` StatusVersion string `json:"statusVersion"` @@ -29,7 +29,7 @@ type CommonFields struct { } type PeerCount struct { - CommonFields + TelemetryRecord ID int `json:"id"` NodeKeyUID string `json:"nodeKeyUID"` PeerCount int `json:"peerCount"` @@ -37,7 +37,7 @@ type PeerCount struct { } type PeerConnFailure struct { - CommonFields + TelemetryRecord ID int `json:"id"` NodeKeyUID string `json:"nodeKeyUID"` FailedPeerId string `json:"failedPeerId"` @@ -46,7 +46,7 @@ type PeerConnFailure struct { } type SentEnvelope struct { - CommonFields + TelemetryRecord ID int `json:"id"` MessageHash string `json:"messageHash"` SentAt int64 `json:"sentAt"` @@ -64,7 +64,7 @@ type ErrorSendingEnvelope struct { } type ReceivedEnvelope struct { - CommonFields + TelemetryRecord ID int `json:"id"` SentAt int64 `json:"sentAt"` MessageHash string `json:"messageHash"` @@ -91,7 +91,7 @@ type ProtocolStats struct { } type ReceivedMessage struct { - CommonFields + TelemetryRecord ID int `json:"id"` ChatID string `json:"chatId"` MessageHash string `json:"messageHash"` diff --git a/telemetry/aggregator_test.go b/telemetry/aggregator_test.go index 723593f..45a0df4 100644 --- a/telemetry/aggregator_test.go +++ b/telemetry/aggregator_test.go @@ -80,7 +80,7 @@ func dropTables(db *sql.DB) { log.Fatalf("an error '%s' was not expected when dropping the index", err) } - _, err = db.Exec("DROP TABLE IF EXISTS commonFields") + _, err = db.Exec("DROP TABLE IF EXISTS telemetryRecord") if err != nil { log.Fatalf("an error '%s' was not expected when dropping the table", err) } @@ -93,10 +93,10 @@ func dropTables(db *sql.DB) { func updateCreatedAt(db *sql.DB, m *ReceivedMessage, createdAt int64) error { _, err := db.Exec(` - UPDATE commonFields + UPDATE telemetryRecord SET createdAt = $1 WHERE id = ( - SELECT commonFieldsId + SELECT recordId FROM receivedMessages WHERE id = $2 ) diff --git a/telemetry/bindata.go b/telemetry/bindata.go index 733a24f..7981d83 100644 --- a/telemetry/bindata.go +++ b/telemetry/bindata.go @@ -15,7 +15,7 @@ // 000013_peer_conn_failure.up.sql (445B) // 000014_bandwidth_column.up.sql (101B) // 000015_device_type.up.sql (383B) -// 000016_common_fields.up.sql (5.09kB) +// 000016_common_fields.up.sql (5.054kB) // doc.go (73B) package telemetry @@ -384,7 +384,7 @@ func _000015_device_typeUpSql() (*asset, error) { return a, nil } -var __000016_common_fieldsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x58\x4d\x73\xe2\x38\x10\xbd\xfb\x57\xf4\x21\x14\x50\x45\xe6\xb0\x55\x73\x19\x6a\x0f\x1e\x23\x40\x35\x60\x33\xb2\x48\x32\x27\xca\x63\x0b\xe2\x0d\x96\x19\x5b\x64\x96\x7f\xbf\x25\xc9\x1f\x18\xdb\x98\x4c\x36\xb9\xd9\xbc\xfe\xd0\xeb\xee\xd7\x72\xee\xef\xc1\x4a\x98\x27\x18\xf8\x71\x14\xc5\x7c\x1a\xb2\x7d\x90\x82\xf0\x7e\xee\x99\x61\x11\x64\x52\x04\xd4\xfc\xba\x40\x80\xa7\x60\x3b\x14\xd0\x13\x76\xa9\x5b\x45\x0f\x0c\x00\x80\x30\x00\x17\x11\x6c\x2e\x60\x45\xf0\xd2\x24\x3f\xe0\x1b\xfa\x31\x52\x3f\xf1\x38\x60\xb6\x17\x31\x78\x30\x89\x35\x37\xc9\xe0\xaf\xcf\x9f\x87\xca\x9d\xbd\x5e\x2c\x34\xe6\xc0\x58\x82\x83\x6b\x88\x54\x78\xe2\x98\x3e\xb0\x24\x0d\x63\x7e\x0d\x18\xb0\xd7\xd0\x67\xf4\x74\xb8\x1a\xd0\x57\xe7\x0e\x4c\x01\xd8\xa6\x68\x86\x08\x4c\xd0\xd4\x5c\x2f\xe4\x19\x29\x31\x2d\x3a\x40\x2b\xc7\x9a\xc3\x94\x38\x4b\xb0\x9d\xc7\xc1\x70\xf8\xe5\x4b\x06\x35\x86\x63\xc3\xb8\xbf\x87\xe9\x91\xfb\x42\x66\x23\x62\xf0\x82\xa0\x42\x0b\x96\x8f\xfb\x63\xc4\x73\x1e\x1d\x02\x04\xad\x16\xa6\x85\x60\xba\xb6\x2d\x8a\x1d\x5b\x1a\x6d\xb4\xd1\x56\x19\x6d\xb4\xc9\x40\x15\x60\xc3\x25\x67\x14\x3d\xd1\x21\x10\x44\xd7\xc4\x76\xe1\xc1\xc1\x13\x30\x5d\xb8\xbb\x33\xbe\xa2\x19\xb6\xd5\x51\xd0\x13\xb2\xd6\x14\xc1\x36\x4e\x22\x4f\x0c\xfa\xe6\x82\x22\x92\xd5\xad\x87\xc1\x9c\x4c\xc0\x72\x16\xeb\xa5\x7d\xa5\x8a\x38\xc8\x79\xe8\x8f\xa0\x0c\x3f\x1c\xab\x08\xc4\xc4\x2e\x92\xa6\xd8\x42\xd0\x37\x83\x80\xb5\x1c\x56\x32\xa1\xac\xbf\x40\xaf\xe2\x68\x6c\xa0\x27\x0b\xad\xe4\xa9\x95\xc7\xc7\x39\xb2\xc1\xa1\x73\x44\x5c\xa0\x73\xa4\x5f\x96\xa1\x0a\x30\xf4\x51\x92\xc4\x89\x64\x2a\xe4\xbb\x8e\xa0\xd0\xbb\x0c\x3b\x02\xf7\xfb\x02\x11\xb2\x1c\x1b\xc8\x9e\x8c\x8d\xbb\x3b\x58\x98\xf6\x6c\x6d\xce\x10\x1c\xf6\x87\x5d\xfa\x6b\xaf\x4b\xb9\x0c\x77\x89\xa7\x6a\xb9\xcd\x8b\xba\x8d\x13\x60\xff\x86\xa9\x90\x81\x13\xe6\xc7\x49\x90\x5e\x2b\x66\xa4\x5c\xb0\x4d\x6e\xb3\xc9\x6c\xde\x59\xcd\x82\x99\x47\x4c\xe7\x10\xf2\x94\x25\x82\xe5\x6d\xb3\xd1\x7d\x23\x9d\x0c\x0a\xa0\xfc\xc3\xb6\x8b\x08\x95\x35\x75\x2e\xa6\x35\x9f\xc6\x51\x36\x73\xa3\xea\x64\x8d\xce\xe6\x67\x54\x4e\xc9\xb0\xe2\xdd\x45\x0b\x64\x51\x98\x60\x97\x62\xdb\xa2\xf0\x67\x3e\x2b\x2e\xd5\x9c\xf5\x70\xe5\x9d\xe6\x09\xdb\x33\x08\x83\xd1\x7b\x83\x94\x27\x58\xaf\x26\xb2\x86\x3d\x0c\xe5\xaf\x2e\xa2\x97\xcd\xf5\x37\x84\xfe\xf6\x53\x18\x18\x95\x14\x5b\x0a\x10\xfa\xdb\xb2\x50\x73\x44\x10\x88\x4f\x85\xee\x69\x4f\xf9\xe3\xd9\x11\x4d\x7b\x02\xe2\x53\xa6\x7d\x1a\xa5\x1f\x6a\x98\xaa\xfa\x69\x68\xe5\x5d\xcd\xe2\x4c\x06\x35\xbc\x7c\x51\xc3\x96\x62\xa8\xa1\xc5\xb3\x1e\xff\x8b\x91\xaa\xc8\x43\x83\x3e\x58\x71\x74\xd8\x33\xc1\x82\x6c\x24\xf2\x61\xfa\x10\x61\xc8\x42\xf0\x1d\x04\x9e\xf0\xca\x38\xef\xd0\x82\x73\x59\x8f\xe2\x20\xdc\x9e\xb4\x97\xeb\xd3\xaf\x80\x1b\x05\x7c\xe3\xc4\x97\x5b\x58\x3c\x33\x79\x02\x16\xee\x38\xbc\xb0\x13\xf8\x31\x4f\x45\xe2\x85\x5c\x37\x6a\x69\x72\xb3\xec\xdb\x2e\x25\x26\xb6\x29\x6c\x5f\x36\x3d\xbc\x39\x6f\xf1\xea\xf8\x39\x04\xe1\x99\x2d\x97\x36\x0c\xaa\x83\x20\xb3\x9f\x22\x82\x6c\x0b\x55\x77\xc6\x20\x0c\x86\xd7\x5a\x43\x27\x79\x5e\xdc\xa2\xc0\xc1\xf1\xb0\x0f\x7d\xa9\x96\xf1\xcf\x7f\x98\x2f\xaa\xa5\xae\xb7\xd4\xb4\x91\x14\xf0\xf6\x09\xf3\x82\x93\x96\xe9\x14\x62\x5e\x6b\x2e\x95\x83\xac\x76\xce\x34\x61\x51\xfc\xca\xb2\xcd\x91\x82\x78\xf6\x04\x78\x09\x03\x1e\xff\x86\x90\x43\x8d\xa0\xeb\x2c\x17\x29\x4f\x88\xb3\x3a\xdb\xb2\xf9\x86\xcd\xe7\x68\xd4\x01\x2c\xb4\xad\x03\x57\x55\xbc\x0e\x70\x26\x93\x1d\xa8\x52\x16\x2e\x37\x7f\x4e\xd9\x24\x89\x0f\xaa\x35\x8f\x3c\xfc\x75\x64\x97\x5d\xd9\xd1\x87\x59\xd4\xa2\x11\xcb\xc8\x3d\xbc\xd1\x1e\x3b\xf5\x45\x2e\x68\xef\x45\xcf\x07\x67\xbf\xf3\xbd\x9f\xdf\xe8\x6e\xba\x05\xa9\xc7\xec\xf4\x17\x4a\x2f\xc5\x3f\xf7\xd5\x48\x42\xab\xbe\xc9\xa1\x97\x7d\x1c\xc6\x3c\xfd\x40\x8d\x53\xda\x22\x35\xee\xbd\xd2\x66\xb6\xdd\x52\xa5\xd6\x31\xcf\x7f\xce\xee\xfe\xd9\x82\x6f\xbb\x9f\xf6\x65\x6b\xf9\xf1\x91\x8b\xfe\x70\xdc\x09\x4e\x98\xcf\xc2\x57\x16\x44\x2c\x4d\xbd\x1d\x4b\xdf\x62\xc3\xf8\x2b\xdb\xc7\x87\xdb\x8c\x52\xc6\xc5\x9b\x0c\x98\xa4\x37\x65\x5c\xde\x2d\x73\xc3\x5b\xec\xf4\xf1\x39\xdf\x7a\xe1\xfe\x98\x28\x13\xc5\xee\xe1\xb0\x3f\x9d\x2d\xbd\x46\x4e\x5b\xaf\x89\x8d\xa4\xb6\xa3\xaf\xb0\xda\x6d\xd4\xc4\x52\xbb\x55\x1b\xaf\xed\x16\x1d\xc4\x76\x71\xd0\xc6\x6c\x65\xdc\x9a\xd9\x3d\x5f\xc3\xcd\x8c\x56\x10\xd7\x58\x6c\x04\x36\xf2\x50\x41\xb6\xb2\x55\x41\x75\x31\xd4\x70\x8e\x1a\x2b\x85\x30\xe7\xdf\x2c\x29\x78\x5b\xc1\x12\x38\xa6\xcc\x50\xba\xdb\xf5\xa5\x39\xbe\x80\xb5\x15\xa6\x86\x3b\x4b\x4f\xe7\x42\x98\x5e\x76\xf5\x25\x91\x1a\xe7\x52\x9c\xf3\xb8\xcc\x08\x07\xe3\xe2\xa2\x72\x09\xc8\x76\x04\x18\x6b\x1b\x7f\x5f\xa3\xec\x3b\xa7\x2a\x62\xd9\x27\xfd\xb3\x27\xe4\x67\x81\x7a\xc8\x0a\x3a\xf7\xd2\xe7\xec\x4d\xe6\x38\xf9\xc6\x4e\x6b\x3c\x01\xf5\x11\xdf\x94\x19\xca\x6b\xd7\x9a\x5a\x81\xb8\x3d\x37\xd9\x14\xf9\x35\xa0\x2b\xb5\x5a\x66\xd2\xb8\x3d\xab\xca\xaf\xff\x57\x46\xb2\x33\x5b\xf3\x51\xbd\xeb\xea\xde\xcd\x23\xd7\xd2\x6a\x02\x7d\x44\x76\x1a\xa3\xa2\xd5\x12\x95\x73\x63\xc9\xf9\xaf\x65\x57\xfc\x72\x7b\x4a\x22\x8c\x58\x2a\xbc\xe8\x50\xfe\x57\xab\x85\x1f\xed\x9c\xf3\xa9\x1e\xd7\x96\xe0\xc5\xef\x7f\x92\x82\xe6\x41\xea\x01\x0b\x56\xd9\xe7\x70\xf1\xea\x98\x30\x75\x36\x63\x38\xfe\x2f\x00\x00\xff\xff\x86\x4e\x83\x08\xe2\x13\x00\x00") +var __000016_common_fieldsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x58\x4f\x73\xda\xc8\x13\xbd\xeb\x53\xf4\xc1\x94\xa1\x0a\xe7\xf0\xab\xca\x25\xd4\xef\xa0\x88\xc1\x4c\x05\x0b\x32\x1a\x12\xe7\x44\x29\x52\x63\x6b\x0d\x23\x22\x0d\xce\xf2\xed\xb7\xe6\x8f\x24\x84\x24\xc0\xeb\x8d\x6f\x48\xaf\xa7\xbb\x5f\x77\xbf\x1e\xf9\xee\x0e\xbc\x0c\x43\x89\x20\x71\x83\x5b\x94\xd9\x81\x61\x94\x66\x31\xc8\xf0\xe7\x06\x1d\x8f\x11\x97\x13\xe0\xee\xe7\x19\x01\x3a\x01\x7f\xce\x81\x3c\xd2\x80\x07\x0d\x83\xbe\x03\x00\x90\xc4\x10\x10\x46\xdd\x19\x2c\x18\x7d\x70\xd9\x0f\xf8\x42\x7e\x0c\xf5\x2b\x91\xc6\xe8\x87\x5b\x84\x6f\x2e\xf3\xa6\x2e\xeb\xff\xef\xe3\xc7\x81\x3e\xd1\x5f\xce\x66\x06\xb3\x43\xcc\x68\x7c\x0e\x91\xcb\x50\xee\xf3\x6f\x98\xe5\x49\x2a\xce\x01\x63\x7c\x4d\x22\xe4\x87\xdd\x59\x87\x91\xce\x3e\x76\x25\x50\x9f\x93\x7b\xc2\x60\x4c\x26\xee\x72\xa6\xd2\xe4\xcc\xf5\x78\x9f\x2c\xe6\xde\x14\x26\x6c\xfe\x00\xfe\xfc\x7b\x7f\x30\xf8\xf4\xc9\x42\x9d\xc1\xc8\x71\xee\xee\x60\xb2\x17\x91\x54\xd1\xc8\x14\xc2\x38\x86\x4c\x13\x42\x63\x88\xd2\xcd\x7e\x2b\x0a\x12\xe7\x0c\x18\x59\xcc\x5c\x8f\xc0\x64\xe9\x7b\x9c\xce\x7d\x05\x5f\x95\x44\x1a\xbb\x95\xb1\xea\xeb\x02\xac\x84\x22\x8c\x93\x47\x3e\x00\x46\xf8\x92\xf9\x01\x7c\x9b\xd3\x31\xb8\x01\xdc\xdc\x38\x9f\xc9\x3d\xf5\x75\x1e\xe4\x91\x78\x4b\x4e\x60\x9d\x66\xdb\x50\xf6\x6f\xdd\x19\x27\xcc\xd6\xad\x47\xc1\x1d\x8f\xc1\x9b\xcf\x96\x0f\xfe\x49\x15\xcb\x58\x6d\x4e\xb7\x43\xa8\x1c\x0f\x46\xfa\x6c\xe6\xd2\x80\x28\x23\xea\x11\xb8\x75\xe3\x18\x1b\x39\xaa\xd4\xb5\xdd\x27\xe8\xd5\x8e\x18\x39\xe4\xd1\x23\x0b\x95\xac\x3e\xeb\xfb\x94\xf8\x30\xe7\x53\xc2\x02\xe0\x53\x62\x1e\x56\x4e\x4a\x30\xdc\x92\x2c\x4b\x33\x45\x50\x22\x9e\x3a\xdd\x41\xef\xd4\xe1\x10\x82\xaf\x33\xc2\xd8\xc3\xc8\x21\xfe\x78\xe4\xdc\xdc\xc0\xcc\xf5\xef\x97\xee\x3d\x81\xdd\x66\xf7\x94\xff\xda\x98\xaa\x3d\x24\x4f\x59\xa8\xcb\xb6\x2e\xea\xb7\x4e\x33\xc0\xbf\x93\x5c\x56\x2e\xf3\x73\xd5\xdb\xea\x23\x70\x55\xd8\xac\xac\xcd\x3b\x6b\x57\x72\xf2\x9d\xf2\x29\x24\x22\xc7\x4c\xe2\x51\x9f\x58\x37\xea\x9c\x7e\x89\x55\x7f\xd4\x0f\x08\xe3\xaa\x94\xf3\xe6\x78\x16\xe3\x37\xb4\x43\x36\xac\x8f\xd2\xf0\x68\x60\x86\xd5\x58\x0c\x6a\x0e\x02\x32\x23\x1e\x87\x31\x0d\x38\xf5\x3d\x0e\xff\xee\xcc\xda\x91\x7a\xb0\x7a\xb4\xf6\xcc\xb0\x45\xfd\x7b\x48\xe2\xe1\x7b\x9d\x54\x19\x2c\x17\x63\x55\xc9\x1e\x85\xea\x6d\x40\x78\xd5\x5c\xff\x87\x24\x5a\x7f\x48\x62\xa7\x16\x5c\x77\x01\x92\x68\x5d\xd5\x6a\x4a\x18\x01\xf9\xa1\x54\x39\x73\x58\xf1\xf3\x28\x3f\xd7\x1f\x83\xfc\x60\x95\xce\xa0\xcc\x8f\x06\xa6\xae\x75\x06\x5a\x7b\xd6\xb0\x38\x12\x3d\x03\xaf\x1e\x34\xb0\x95\xf4\x19\x68\xf9\xdb\x4c\xfd\xc9\x54\xd5\x54\xa1\x45\x16\xbc\x74\xbb\xdb\xa0\xc4\xd8\x4e\x45\x31\x4f\x7f\x44\x15\xac\x0b\xf1\x04\x71\x28\xc3\xca\xcf\x3b\xe4\xe0\x58\xc4\xb7\x69\x9c\xac\x0f\xe6\x94\xf3\x02\xa0\x81\x2b\x0d\x7c\xe3\xd0\x1f\x6d\xde\x67\x54\x19\x60\xf2\x24\xe0\x05\x0f\x10\xa5\x22\x97\x59\x98\x08\xd3\xa5\x95\xc9\xd5\x3a\xef\x07\x9c\xb9\xd4\xe7\xb0\x7e\x59\xf5\xe8\xea\x44\x0a\xea\xe3\x37\x67\x84\xde\xfb\x6a\x4b\x43\xbf\x18\x04\x15\xfa\x84\x30\xe2\x7b\xa4\xb1\xe7\xfb\x49\x3c\x38\xd7\x1a\x26\xc8\xe3\xe2\x96\x05\x8e\xf7\xbb\x4d\x12\x29\xc1\x4c\x7f\xfe\x85\x91\xac\x97\xba\xd9\x52\x93\x56\x52\x20\xdc\x64\x18\xc6\x07\xa3\xd4\x39\xa4\xa2\xd1\x5c\x3a\x06\x55\xed\x82\x69\x86\xdb\xf4\x15\xed\xf2\xc8\x41\x3e\x87\x12\xc2\x0c\x41\xa4\xbf\x21\x11\xa7\x29\x5e\xb1\x50\xcb\xa8\xc7\x6c\xbe\x38\xda\xac\x76\xab\x96\xa3\x34\xbc\x00\x2c\xb5\xed\x02\xae\xae\x78\x17\xc0\x56\x26\x2f\xa0\x2a\x65\x38\xdd\xf9\x05\x6b\xe3\x2c\xdd\xe9\xee\xdc\x8b\xe4\xd7\x1e\x4f\x1b\xf3\x42\x2b\x5a\xaf\x65\x2f\x56\x9e\x7b\x74\x65\x4e\xbc\x28\x31\x6a\x4d\x87\x2f\x66\x44\x04\xfe\x2e\xb6\x7f\x71\x85\xbb\xea\xe6\xa3\x7f\xda\xec\x4b\xa5\x57\xb2\x5f\x9c\xd2\x9a\x7e\xa7\xb8\xa9\x89\x57\x4d\x9c\xa4\x22\xff\x83\x02\xa7\x85\x45\x09\xdc\x7b\x75\xcd\x6d\x5e\x48\x95\xc4\x61\x18\x3d\xdb\x3b\xbe\x5d\xea\x67\xae\xa2\xb7\xaa\xa3\xa2\x74\x2f\xe4\xed\x60\x74\x0d\x3e\xc3\x08\x93\x57\x8c\xb7\x98\xe7\xe1\x13\xe6\x6f\x34\x43\xf1\x8a\x9b\x74\x77\xb5\x5d\x8e\x42\xbe\xd5\x06\x15\xcf\x39\x0a\x75\xbd\x2c\x6c\xaf\x34\x35\x6c\x08\xb1\x0e\x93\xcd\x3e\xd3\x56\x9a\xe9\xdd\x6e\x73\x38\xda\x7e\xad\x2c\x77\x5e\x19\x5b\x39\xee\x46\x9f\x61\xf8\xb2\x51\x1b\x57\xdd\x56\x5d\xec\x76\x5b\x5c\xe0\xf6\x12\x07\x5d\xcc\xd6\x46\xaf\x9d\xdd\xe3\x7d\xdc\xce\x68\x0d\x71\x8e\xc5\x56\x60\x2b\x0f\x35\x64\x27\x5b\x35\xd4\x25\x86\x5a\xf2\x68\xb0\x52\xca\x73\xf1\xfd\x92\x43\xb8\x96\x98\xc1\x3e\x47\x47\xab\xef\x15\x9f\x99\xa3\x13\x64\x57\x6d\x1a\xb8\xa3\x08\x4d\x38\x0c\xcd\xd6\x6b\x6e\x8b\xdc\x39\xd6\xe4\x82\xca\x07\xcb\x39\x38\x27\x97\x96\x53\x80\x5d\x16\xe0\x2c\x7d\xfa\x75\x49\xec\x37\x4f\xa1\x69\xf6\x33\xfe\x39\x94\xea\xcb\x40\xff\xb0\xd5\x9c\x86\xf9\xb3\x7d\x62\x8f\xcc\xbe\xe0\x61\x49\xc7\xa0\x3f\xdc\xdb\x62\x22\x45\xe1\x3a\x83\x2a\x11\xd7\x44\xa5\x7a\xa1\xb8\x03\x5c\x0a\xaa\x11\x93\x32\xee\x8e\xa7\xf6\xf6\xfd\xb1\xa8\x56\xec\x8c\x44\x37\x6b\x60\x9a\xb5\xf0\xd9\x08\xa8\x0d\xf4\xdf\xc6\x65\x30\xda\x4f\x23\x44\x35\x22\x9e\x1a\xf5\x46\x5c\xe5\x9b\x6b\x82\x91\xc9\x16\x73\x19\x6e\x77\xd5\x7f\xac\x3a\x38\x31\xc7\x0a\x31\x31\x33\xd9\xe1\xb6\x7c\xff\x36\xe7\x26\x77\x35\xee\x18\x2f\xec\x37\x6f\xf9\x68\x9f\xa1\xce\xc7\x19\x8c\xfe\x09\x00\x00\xff\xff\x84\x5d\xbb\xae\xbe\x13\x00\x00") func _000016_common_fieldsUpSqlBytes() ([]byte, error) { return bindataRead( @@ -399,8 +399,8 @@ func _000016_common_fieldsUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000016_common_fields.up.sql", size: 5090, mode: os.FileMode(0644), modTime: time.Unix(1725040082, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc1, 0x96, 0x32, 0xa3, 0x1e, 0x90, 0x6e, 0x4, 0x7c, 0x20, 0xe1, 0xb5, 0x8c, 0xa3, 0x53, 0x31, 0x44, 0xf5, 0xf6, 0xa0, 0x6f, 0x41, 0x89, 0x6, 0xe0, 0x7a, 0xc, 0xf2, 0x42, 0x1, 0xbf, 0x31}} + info := bindataFileInfo{name: "000016_common_fields.up.sql", size: 5054, mode: os.FileMode(0644), modTime: time.Unix(1725040401, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xec, 0x50, 0x40, 0x27, 0x11, 0x66, 0x6c, 0x70, 0x70, 0x47, 0xd0, 0x9e, 0xd1, 0x3a, 0x2c, 0x2b, 0x84, 0xb6, 0xb, 0x6, 0x56, 0x14, 0x8, 0x92, 0x5d, 0x29, 0x20, 0xcc, 0xc3, 0x24, 0xde, 0x68}} return a, nil } diff --git a/telemetry/common_fields.go b/telemetry/common_fields.go index f10d4b0..d087420 100644 --- a/telemetry/common_fields.go +++ b/telemetry/common_fields.go @@ -6,9 +6,9 @@ import ( "github.com/status-im/telemetry/pkg/types" ) -func InsertCommonFields(tx *sql.Tx, data *types.CommonFields) (int, error) { +func InsertTelemetryRecord(tx *sql.Tx, data *types.TelemetryRecord) (int, error) { stmt, err := tx.Prepare(` - INSERT INTO commonFields (nodeName, peerId, statusVersion, deviceType) + INSERT INTO telemetryRecord (nodeName, peerId, statusVersion, deviceType) VALUES ($1, $2, $3, $4) RETURNING id; `) @@ -16,16 +16,16 @@ func InsertCommonFields(tx *sql.Tx, data *types.CommonFields) (int, error) { return 0, err } - var commonFieldsId int + var recordId int err = stmt.QueryRow( data.NodeName, data.PeerID, data.StatusVersion, data.DeviceType, - ).Scan(&commonFieldsId) + ).Scan(&recordId) if err != nil { return 0, err } - return commonFieldsId, nil + return recordId, nil } diff --git a/telemetry/peer_count.go b/telemetry/peer_count.go index 62495b6..2545693 100644 --- a/telemetry/peer_count.go +++ b/telemetry/peer_count.go @@ -25,7 +25,7 @@ func (r *PeerCount) process(db *sql.DB, errs *MetricErrors, data *types.Telemetr } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &r.data.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &r.data.TelemetryRecord) if err != nil { return err } @@ -41,7 +41,7 @@ func (r *PeerCount) process(db *sql.DB, errs *MetricErrors, data *types.Telemetr var lastInsertId int err = peerCountStmt.QueryRow( - commonFieldsId, + recordId, r.data.NodeKeyUID, r.data.PeerCount, ).Scan(&lastInsertId) @@ -75,7 +75,7 @@ func (r *PeerConnFailure) process(db *sql.DB, errs *MetricErrors, data *types.Te } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &r.data.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &r.data.TelemetryRecord) if err != nil { return err } @@ -89,7 +89,7 @@ func (r *PeerConnFailure) process(db *sql.DB, errs *MetricErrors, data *types.Te lastInsertId := 0 err = stmt.QueryRow( - commonFieldsId, + recordId, r.data.NodeKeyUID, r.data.FailedPeerId, r.data.FailureCount, diff --git a/telemetry/receivedenvelope.go b/telemetry/receivedenvelope.go index 31f1647..4275960 100644 --- a/telemetry/receivedenvelope.go +++ b/telemetry/receivedenvelope.go @@ -21,12 +21,12 @@ func (r *ReceivedEnvelope) put(db *sql.DB) error { } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &r.data.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &r.data.TelemetryRecord) if err != nil { return err } - stmt, err := tx.Prepare(`INSERT INTO receivedEnvelopes (commonFieldsId, messageHash, sentAt, pubsubTopic, + stmt, err := tx.Prepare(`INSERT INTO receivedEnvelopes (recordId, messageHash, sentAt, pubsubTopic, topic, receiverKeyUID, processingError) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT ON CONSTRAINT receivedEnvelopes_unique DO NOTHING @@ -37,7 +37,7 @@ func (r *ReceivedEnvelope) put(db *sql.DB) error { lastInsertId := 0 err = stmt.QueryRow( - commonFieldsId, + recordId, r.data.MessageHash, r.data.SentAt, r.data.PubsubTopic, @@ -102,12 +102,12 @@ func (r *SentEnvelope) put(db *sql.DB) error { } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &r.data.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &r.data.TelemetryRecord) if err != nil { return err } - stmt, err := tx.Prepare(`INSERT INTO sentEnvelopes (commonFieldsId, messageHash, sentAt, pubsubTopic, + stmt, err := tx.Prepare(`INSERT INTO sentEnvelopes (recordId, messageHash, sentAt, pubsubTopic, topic, senderKeyUID, publishMethod) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT ON CONSTRAINT sentEnvelopes_unique DO NOTHING @@ -118,7 +118,7 @@ func (r *SentEnvelope) put(db *sql.DB) error { lastInsertId := int64(0) err = stmt.QueryRow( - commonFieldsId, + recordId, r.data.MessageHash, r.data.SentAt, r.data.PubsubTopic, @@ -170,12 +170,12 @@ func (e *ErrorSendingEnvelope) process(db *sql.DB, errs *MetricErrors, data *typ } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &e.data.SentEnvelope.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &e.data.SentEnvelope.TelemetryRecord) if err != nil { return err } - stmt, err := tx.Prepare(`INSERT INTO errorSendingEnvelope (commonFieldsId, messageHash, sentAt, pubsubTopic, + stmt, err := tx.Prepare(`INSERT INTO errorSendingEnvelope (recordId, messageHash, sentAt, pubsubTopic, topic, senderKeyUID, publishMethod, error) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT ON CONSTRAINT errorSendingEnvelope_unique DO NOTHING @@ -186,7 +186,7 @@ func (e *ErrorSendingEnvelope) process(db *sql.DB, errs *MetricErrors, data *typ lastInsertId := int64(0) err = stmt.QueryRow( - commonFieldsId, + recordId, e.data.SentEnvelope.MessageHash, e.data.SentEnvelope.SentAt, e.data.SentEnvelope.PubsubTopic, diff --git a/telemetry/receivedenvelope_test.go b/telemetry/receivedenvelope_test.go index 3547b52..93fe5a4 100644 --- a/telemetry/receivedenvelope_test.go +++ b/telemetry/receivedenvelope_test.go @@ -16,7 +16,7 @@ func TestEnvelopesUpdate(t *testing.T) { var errs MetricErrors firstEnvelopeData := types.ReceivedEnvelope{ - CommonFields: types.CommonFields{ + TelemetryRecord: types.TelemetryRecord{ NodeName: "status", }, MessageHash: "1", @@ -40,7 +40,7 @@ func TestEnvelopesUpdate(t *testing.T) { require.NoError(t, err) envelopeToUpdateData := types.ReceivedEnvelope{ - CommonFields: types.CommonFields{ + TelemetryRecord: types.TelemetryRecord{ NodeName: "status", }, MessageHash: "1", diff --git a/telemetry/receivedmessage.go b/telemetry/receivedmessage.go index 8ee8fb2..2cf2795 100644 --- a/telemetry/receivedmessage.go +++ b/telemetry/receivedmessage.go @@ -42,19 +42,19 @@ func (r *ReceivedMessage) put(db *sql.DB) error { } defer tx.Rollback() - commonFieldsId, err := InsertCommonFields(tx, &r.data.CommonFields) + recordId, err := InsertTelemetryRecord(tx, &r.data.TelemetryRecord) if err != nil { return fmt.Errorf("failed to insert common fields: %w", err) } - stmt, err := tx.Prepare("INSERT INTO receivedMessages (commonFieldsId, chatId, messageHash, messageId, receiverKeyUID, sentAt, topic, messageType, messageSize, pubSubTopic) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id;") + stmt, err := tx.Prepare("INSERT INTO receivedMessages (recordId, chatId, messageHash, messageId, receiverKeyUID, sentAt, topic, messageType, messageSize, pubSubTopic) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id;") if err != nil { return fmt.Errorf("failed to prepare statement: %w", err) } lastInsertId := 0 err = stmt.QueryRow( - commonFieldsId, + recordId, r.data.ChatID, r.data.MessageHash, r.data.MessageID, @@ -81,7 +81,7 @@ func queryReceivedMessagesBetween(db *sql.DB, startsAt time.Time, endsAt time.Ti SELECT rm.id, rm.chatId, rm.messageHash, rm.messageId, rm.receiverKeyUID, rm.sentAt, rm.topic, rm.messageType, rm.messageSize, rm.pubSubTopic, cf.nodeName, cf.peerId, cf.statusVersion, cf.deviceType FROM receivedMessages rm - LEFT JOIN commonFields cf ON rm.commonFieldsId = cf.id + LEFT JOIN telemetryRecord cf ON rm.recordId = cf.id WHERE rm.sentAt BETWEEN $1 AND $2`, startsAt.Unix(), endsAt.Unix()) if err != nil { return nil, err @@ -120,7 +120,7 @@ func didReceivedMessageBeforeAndAfterInChat(db *sql.DB, receiverPublicKey string err := db.QueryRow(` SELECT COUNT(*) FROM receivedMessages rm - JOIN commonFields cf ON rm.commonFieldsId = cf.id + JOIN telemetryRecord cf ON rm.recordId = cf.id WHERE rm.receiverKeyUID = $1 AND cf.createdAt > $2 AND rm.chatId = $3`, receiverPublicKey, after.Unix(), @@ -134,7 +134,7 @@ func didReceivedMessageBeforeAndAfterInChat(db *sql.DB, receiverPublicKey string err = db.QueryRow(` SELECT COUNT(*) FROM receivedMessages rm - JOIN commonFields cf ON rm.commonFieldsId = cf.id + JOIN telemetryRecord cf ON rm.recordId = cf.id WHERE rm.receiverKeyUID = $1 AND cf.createdAt < $2 AND rm.chatId = $3`, receiverPublicKey, before.Unix(), diff --git a/telemetry/sql/000016_common_fields.up.sql b/telemetry/sql/000016_common_fields.up.sql index d73c95d..44f2a9e 100644 --- a/telemetry/sql/000016_common_fields.up.sql +++ b/telemetry/sql/000016_common_fields.up.sql @@ -1,5 +1,5 @@ --- Create commonFields table -CREATE TABLE IF NOT EXISTS commonFields ( +-- Create telemetryRecord table +CREATE TABLE IF NOT EXISTS telemetryRecord ( id SERIAL PRIMARY KEY, nodeName VARCHAR(255) NOT NULL, peerId VARCHAR(255) NOT NULL, @@ -8,14 +8,14 @@ CREATE TABLE IF NOT EXISTS commonFields ( createdAt INTEGER DEFAULT EXTRACT(EPOCH FROM NOW())::INTEGER ); --- Function to add commonFieldsId column -CREATE OR REPLACE FUNCTION add_commonfields_column(table_name TEXT) RETURNS VOID AS $$ +-- Function to add recordId column +CREATE OR REPLACE FUNCTION add_telemetryrecord_column(table_name TEXT) RETURNS VOID AS $$ BEGIN - EXECUTE format('ALTER TABLE %I ADD COLUMN IF NOT EXISTS commonFieldsId INTEGER', table_name); - RAISE NOTICE 'Added commonFieldsId column to table: %', table_name; + EXECUTE format('ALTER TABLE %I ADD COLUMN IF NOT EXISTS recordId INTEGER', table_name); + RAISE NOTICE 'Added recordId column to table: %', table_name; EXCEPTION WHEN OTHERS THEN - RAISE EXCEPTION 'Error adding commonFieldsId column to table %: %', table_name, SQLERRM; + RAISE EXCEPTION 'Error adding recordId column to table %: %', table_name, SQLERRM; END; $$ LANGUAGE plpgsql; @@ -23,15 +23,15 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION migrate_existing_records(table_name TEXT) RETURNS VOID AS $$ BEGIN EXECUTE format(' - WITH inserted_common_fields AS ( - INSERT INTO commonFields (nodeName, peerId, statusVersion, deviceType, createdAt) + WITH inserted_telemetry_record AS ( + INSERT INTO telemetryRecord (nodeName, peerId, statusVersion, deviceType, createdAt) SELECT DISTINCT nodeName, peerId, statusVersion, deviceType, createdAt FROM %I RETURNING id, nodeName, peerId, statusVersion, deviceType, createdAt ) UPDATE %I t - SET commonFieldsId = icf.id - FROM inserted_common_fields icf + SET recordId = icf.id + FROM inserted_telemetry_record icf WHERE t.nodeName = icf.nodeName AND t.peerId = icf.peerId AND t.statusVersion = icf.statusVersion @@ -51,14 +51,14 @@ CREATE OR REPLACE FUNCTION modify_table(table_name TEXT) RETURNS VOID AS $$ BEGIN -- Create the foreign key constraint BEGIN - EXECUTE format('ALTER TABLE %I ADD CONSTRAINT fk_%I_commonFields - FOREIGN KEY (commonFieldsId) REFERENCES commonFields(id)', table_name, table_name); + EXECUTE format('ALTER TABLE %I ADD CONSTRAINT fk_%I_telemetryRecord + FOREIGN KEY (recordId) REFERENCES telemetryRecord(id)', table_name, table_name); EXCEPTION WHEN duplicate_object THEN RAISE NOTICE 'Foreign key constraint already exists on %', table_name; END; - -- Remove columns that are now in commonFields + -- Remove columns that are now in telemetryRecord EXECUTE format('ALTER TABLE %I DROP COLUMN IF EXISTS createdAt, DROP COLUMN IF EXISTS nodeName, @@ -70,7 +70,7 @@ BEGIN EXECUTE format('ALTER TABLE %I DROP CONSTRAINT IF EXISTS %I_unique', table_name, table_name); -- Make the new column NOT NULL - EXECUTE format('ALTER TABLE %I ALTER COLUMN commonFieldsId SET NOT NULL', table_name); + EXECUTE format('ALTER TABLE %I ALTER COLUMN recordId SET NOT NULL', table_name); RAISE NOTICE 'Completed modifications for table: %', table_name; EXCEPTION @@ -79,13 +79,13 @@ EXCEPTION END; $$ LANGUAGE plpgsql; --- Add commonFieldsId column to each table -SELECT add_commonfields_column('peercount'); -SELECT add_commonfields_column('receivedmessages'); -SELECT add_commonfields_column('receivedenvelopes'); -SELECT add_commonfields_column('sentenvelopes'); -SELECT add_commonfields_column('errorsendingenvelope'); -SELECT add_commonfields_column('peerconnfailure'); +-- Add recordId column to each table +SELECT add_telemetryrecord_column('peercount'); +SELECT add_telemetryrecord_column('receivedmessages'); +SELECT add_telemetryrecord_column('receivedenvelopes'); +SELECT add_telemetryrecord_column('sentenvelopes'); +SELECT add_telemetryrecord_column('errorsendingenvelope'); +SELECT add_telemetryrecord_column('peerconnfailure'); -- Apply migration to each table SELECT migrate_existing_records('peercount'); @@ -104,7 +104,7 @@ SELECT modify_table('errorsendingenvelope'); SELECT modify_table('peerconnfailure'); -- Drop the functions after use -DROP FUNCTION add_commonfields_column; +DROP FUNCTION add_telemetryrecord_column; DROP FUNCTION migrate_existing_records; DROP FUNCTION modify_table; @@ -112,7 +112,7 @@ DROP FUNCTION modify_table; ALTER TABLE receivedMessages ADD CONSTRAINT receivedMessages_unique UNIQUE ( - commonFieldsId, + recordId, chatId, messageHash, receiverKeyUID @@ -121,7 +121,7 @@ UNIQUE ( ALTER TABLE receivedEnvelopes ADD CONSTRAINT receivedEnvelopes_unique UNIQUE ( - commonFieldsId, + recordId, sentAt, messageHash, receiverKeyUID @@ -130,7 +130,7 @@ UNIQUE ( ALTER TABLE sentEnvelopes ADD CONSTRAINT sentEnvelopes_unique UNIQUE ( - commonFieldsId, + recordId, sentAt, messageHash, senderKeyUID @@ -139,7 +139,7 @@ UNIQUE ( ALTER TABLE errorSendingEnvelope ADD CONSTRAINT errorSendingEnvelope_unique UNIQUE ( - commonFieldsId, + recordId, sentAt, messageHash, senderKeyUID, @@ -149,7 +149,7 @@ UNIQUE ( ALTER TABLE peerCount ADD CONSTRAINT peerCount_unique UNIQUE ( - commonFieldsId, + recordId, timestamp, nodeKeyUID ); @@ -157,7 +157,7 @@ UNIQUE ( ALTER TABLE peerConnFailure ADD CONSTRAINT peerConnFailure_unique UNIQUE ( - commonFieldsId, + recordId, timestamp, failedPeerId, failureCount