Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add device type to all metrics #44

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type PeerCount struct {
PeerID string `json:"peerId"`
PeerCount int `json:"peerCount"`
StatusVersion string `json:"statusVersion"`
DeviceType string `json:"deviceType"`
}

type PeerConnFailure struct {
Expand All @@ -42,6 +43,7 @@ type PeerConnFailure struct {
StatusVersion string `json:"statusVersion"`
FailedPeerId string `json:"failedPeerId"`
FailureCount int `json:"failureCount"`
DeviceType string `json:"deviceType"`
}

type SentEnvelope struct {
Expand All @@ -57,12 +59,14 @@ type SentEnvelope struct {
ProcessingError string `json:"processingError"`
PublishMethod string `json:"publishMethod"`
StatusVersion string `json:"statusVersion"`
DeviceType string `json:"deviceType"`
}

type ErrorSendingEnvelope struct {
CreatedAt int64 `json:"createdAt"`
Error string `json:"error"`
SentEnvelope SentEnvelope `json:"sentEnvelope"`
DeviceType string `json:"deviceType"`
}

type ReceivedEnvelope struct {
Expand All @@ -77,6 +81,7 @@ type ReceivedEnvelope struct {
NodeName string `json:"nodeName"`
ProcessingError string `json:"processingError"`
StatusVersion string `json:"statusVersion"`
DeviceType string `json:"deviceType"`
}

type Metric struct {
Expand Down Expand Up @@ -110,4 +115,5 @@ type ReceivedMessage struct {
PubsubTopic string `json:"pubsubTopic"`
CreatedAt int64 `json:"createdAt"`
StatusVersion string `json:"statusVersion"`
DeviceType string `json:"deviceType"`
}
5 changes: 5 additions & 0 deletions telemetry/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func dropTables(db *sql.DB) {
log.Fatalf("an error '%s' was not expected when dropping the table", err)
}

_, err = db.Exec("DROP TABLE IF EXISTS peerconnfailure")
if err != nil {
log.Fatalf("an error '%s' was not expected when dropping the table", err)
}

_, err = db.Exec("DROP TABLE IF EXISTS errorsendingenvelope")
if err != nil {
log.Fatalf("an error '%s' was not expected when dropping the table", err)
Expand Down
147 changes: 80 additions & 67 deletions telemetry/bindata.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions telemetry/peer_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (r *PeerCount) process(db *sql.DB, errs *MetricErrors, data *types.Telemetr
return err
}

stmt, err := db.Prepare("INSERT INTO peerCount (timestamp, nodeName, nodeKeyUid, peerId, peerCount, statusVersion, createdAt) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id;")
stmt, err := db.Prepare("INSERT INTO peerCount (timestamp, nodeName, nodeKeyUid, peerId, peerCount, statusVersion, createdAt, deviceType) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id;")
if err != nil {
return err
}
Expand All @@ -36,6 +36,7 @@ func (r *PeerCount) process(db *sql.DB, errs *MetricErrors, data *types.Telemetr
r.data.PeerCount,
r.data.StatusVersion,
r.data.CreatedAt,
r.data.DeviceType,
).Scan(&lastInsertId)
if err != nil {
errs.Append(data.Id, fmt.Sprintf("Error saving peer count: %v", err))
Expand All @@ -56,7 +57,7 @@ func (r *PeerConnFailure) process(db *sql.DB, errs *MetricErrors, data *types.Te
return err
}

stmt, err := db.Prepare("INSERT INTO peerConnFailure (timestamp, nodeName, nodeKeyUid, peerId, failedPeerId, failureCount, statusVersion, createdAt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id;")
stmt, err := db.Prepare("INSERT INTO peerConnFailure (timestamp, nodeName, nodeKeyUid, peerId, failedPeerId, failureCount, statusVersion, createdAt, deviceType) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id;")
if err != nil {
return err
}
Expand All @@ -74,6 +75,7 @@ func (r *PeerConnFailure) process(db *sql.DB, errs *MetricErrors, data *types.Te
r.data.FailureCount,
r.data.StatusVersion,
r.data.CreatedAt,
r.data.DeviceType,
).Scan(&lastInsertId)
if err != nil {
errs.Append(data.Id, fmt.Sprintf("Error saving peer connection failure: %v", err))
Expand Down
15 changes: 9 additions & 6 deletions telemetry/receivedenvelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type ReceivedEnvelope struct {
func (r *ReceivedEnvelope) put(db *sql.DB) error {
r.data.CreatedAt = time.Now().Unix()
stmt, err := db.Prepare(`INSERT INTO receivedEnvelopes (messageHash, sentAt, createdAt, pubsubTopic,
topic, receiverKeyUID, nodeName, processingError, statusVersion)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
topic, receiverKeyUID, nodeName, processingError, statusVersion, deviceType)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
ON CONFLICT ON CONSTRAINT receivedEnvelopes_unique DO NOTHING
RETURNING id;`)
if err != nil {
Expand All @@ -36,6 +36,7 @@ func (r *ReceivedEnvelope) put(db *sql.DB) error {
r.data.NodeName,
r.data.ProcessingError,
r.data.StatusVersion,
r.data.DeviceType,
).Scan(&lastInsertId)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down Expand Up @@ -88,8 +89,8 @@ type SentEnvelope struct {
func (r *SentEnvelope) put(db *sql.DB) error {
r.data.CreatedAt = time.Now().Unix()
stmt, err := db.Prepare(`INSERT INTO sentEnvelopes (messageHash, sentAt, createdAt, pubsubTopic,
topic, senderKeyUID, peerId, nodeName, publishMethod, statusVersion)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
topic, senderKeyUID, peerId, nodeName, publishMethod, statusVersion, deviceType)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT ON CONSTRAINT sentEnvelopes_unique DO NOTHING
RETURNING id;`)
if err != nil {
Expand All @@ -108,6 +109,7 @@ func (r *SentEnvelope) put(db *sql.DB) error {
r.data.NodeName,
r.data.PublishMethod,
r.data.StatusVersion,
r.data.DeviceType,
).Scan(&lastInsertId)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down Expand Up @@ -147,8 +149,8 @@ func (e *ErrorSendingEnvelope) process(db *sql.DB, errs *MetricErrors, data *typ

e.data.CreatedAt = time.Now().Unix()
stmt, err := db.Prepare(`INSERT INTO errorSendingEnvelope (messageHash, sentAt, createdAt, pubsubTopic,
topic, senderKeyUID, peerId, nodeName, publishMethod, statusVersion, error)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
topic, senderKeyUID, peerId, nodeName, publishMethod, statusVersion, error, deviceType)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
ON CONFLICT ON CONSTRAINT errorSendingEnvelope_unique DO NOTHING
RETURNING id;`)
if err != nil {
Expand All @@ -168,6 +170,7 @@ func (e *ErrorSendingEnvelope) process(db *sql.DB, errs *MetricErrors, data *typ
e.data.SentEnvelope.PublishMethod,
e.data.SentEnvelope.StatusVersion,
e.data.Error,
e.data.DeviceType,
).Scan(&lastInsertId)

if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions telemetry/receivedmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *ReceivedMessage) process(db *sql.DB, errs *MetricErrors, data *types.Te
}

func (r *ReceivedMessage) put(db *sql.DB) error {
stmt, err := db.Prepare("INSERT INTO receivedMessages (chatId, messageHash, messageId, receiverKeyUID, peerId, nodeName, sentAt, topic, messageType, messageSize, createdAt, pubSubTopic, statusVersion) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING id;")
stmt, err := db.Prepare("INSERT INTO receivedMessages (chatId, messageHash, messageId, receiverKeyUID, peerId, nodeName, sentAt, topic, messageType, messageSize, createdAt, pubSubTopic, statusVersion, deviceType) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING id;")
if err != nil {
return err
}
Expand All @@ -55,7 +55,9 @@ func (r *ReceivedMessage) put(db *sql.DB) error {
r.data.MessageSize,
r.data.CreatedAt,
r.data.PubsubTopic,
r.data.StatusVersion).Scan(&lastInsertId)
r.data.StatusVersion,
r.data.DeviceType,
).Scan(&lastInsertId)
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions telemetry/sql/000015_device_type.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE peercount ADD COLUMN deviceType VARCHAR(255);
ALTER TABLE receivedMessages ADD COLUMN deviceType VARCHAR(255);
ALTER TABLE receivedEnvelopes ADD COLUMN deviceType VARCHAR(255);
ALTER TABLE sentEnvelopes ADD COLUMN deviceType VARCHAR(255);
ALTER TABLE errorSendingEnvelope ADD COLUMN deviceType VARCHAR(255);
ALTER TABLE peerConnFailure ADD COLUMN deviceType VARCHAR(255);
Loading