Skip to content

Commit

Permalink
fix: rename common fields to telemetry record
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Aug 30, 2024
1 parent 8a5db99 commit f9b3d8c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 68 deletions.
12 changes: 6 additions & 6 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ 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"`
DeviceType string `json:"deviceType"`
}

type PeerCount struct {
CommonFields
TelemetryRecord
ID int `json:"id"`
NodeKeyUID string `json:"nodeKeyUID"`
PeerCount int `json:"peerCount"`
Timestamp int64 `json:"timestamp"`
}

type PeerConnFailure struct {
CommonFields
TelemetryRecord
ID int `json:"id"`
NodeKeyUID string `json:"nodeKeyUID"`
FailedPeerId string `json:"failedPeerId"`
Expand All @@ -46,7 +46,7 @@ type PeerConnFailure struct {
}

type SentEnvelope struct {
CommonFields
TelemetryRecord
ID int `json:"id"`
MessageHash string `json:"messageHash"`
SentAt int64 `json:"sentAt"`
Expand All @@ -64,7 +64,7 @@ type ErrorSendingEnvelope struct {
}

type ReceivedEnvelope struct {
CommonFields
TelemetryRecord
ID int `json:"id"`
SentAt int64 `json:"sentAt"`
MessageHash string `json:"messageHash"`
Expand All @@ -91,7 +91,7 @@ type ProtocolStats struct {
}

type ReceivedMessage struct {
CommonFields
TelemetryRecord
ID int `json:"id"`
ChatID string `json:"chatId"`
MessageHash string `json:"messageHash"`
Expand Down
6 changes: 3 additions & 3 deletions telemetry/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions telemetry/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions telemetry/common_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ 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;
`)
if err != nil {
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
}
8 changes: 4 additions & 4 deletions telemetry/peer_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions telemetry/receivedenvelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions telemetry/receivedenvelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit f9b3d8c

Please sign in to comment.