Skip to content

Commit

Permalink
feat: add delivery confirmed metric
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Oct 1, 2024
1 parent 1d60d2e commit 5a35627
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 78 deletions.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
server.RegisterMetric(types.PeerCountByOriginMetric, &metrics.PeerCountByOrigin{})
server.RegisterMetric(types.MissingMessageMetric, &metrics.MissingMessage{})
server.RegisterMetric(types.MissingRelevantMessageMetric, &metrics.MissingRelevantMessage{})

server.RegisterMetric(types.MessageDeliveryConfirmedMetric, &metrics.MessageDeliveryConfirmed{})
server.RegisterMetric(types.MessageCheckSuccessMetric, &metrics.MessageCheckSuccess{})
server.RegisterMetric(types.MessageCheckFailureMetric, &metrics.MessageCheckFailure{})
server.RegisterMetric(types.DialFailureMetric, &metrics.DialFailure{})
Expand Down
14 changes: 10 additions & 4 deletions lib/common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func DropTables(db *sql.DB) {
"dialFailure",
"missingmessages",
"missingrelevantmessages",
"messageDeliveryConfirmed",
"schema_migrations",
}

Expand Down Expand Up @@ -106,21 +107,26 @@ func DropTables(db *sql.DB) {
log.Fatalf("an error '%s' was not expected when dropping the index", err)
}

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

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

_, err = tx.Exec("DROP INDEX IF EXISTS missingRelevantMessages_unique")
if err != nil {
log.Fatalf("an error '%s' was not expected when dropping the index", err)
}

_, err = tx.Exec("DROP INDEX IF EXISTS messageDeliveryConfirmed_unique")
if err != nil {
log.Fatalf("an error '%s' was not expected when dropping the index", err)
}

_, err = tx.Exec("DROP TABLE IF EXISTS schema_migrations")
if err != nil {
log.Fatalf("an error '%s' was not expected when dropping the table", err)
Expand Down
119 changes: 71 additions & 48 deletions lib/database/bindata.go

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

14 changes: 7 additions & 7 deletions lib/database/sql/000020_dial_failure.up.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
CREATE TABLE IF NOT EXISTS dial_error_types (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS dialFailure (
id SERIAL PRIMARY KEY,
recordId INTEGER NOT NULL,
errorType INTEGER NOT NULL,
errorMsg TEXT,
protocols TEXT NOT NULL,
timestamp INTEGER NOT NULL,
CONSTRAINT dialFailure_unique UNIQUE (recordId, errorType, protocols, timestamp)
CONSTRAINT dialFailure_unique UNIQUE (recordId, errorType, protocols, timestamp),
CONSTRAINT fk_dialFailure_errorType FOREIGN KEY (errorType) REFERENCES dial_error_types(id)
);

ALTER TABLE dialFailure ADD CONSTRAINT fk_dialFailure_telemetryRecord
FOREIGN KEY (recordId) REFERENCES telemetryRecord(id);


CREATE TABLE IF NOT EXISTS dial_error_types (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);

INSERT INTO dial_error_types (id, name)
SELECT v.id, v.name
FROM (VALUES
Expand Down
10 changes: 10 additions & 0 deletions lib/database/sql/000022_message_delivery_confirmed.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS messageDeliveryConfirmed (
id SERIAL PRIMARY KEY,
recordId INTEGER NOT NULL,
messageHash TEXT NOT NULL,
timestamp INTEGER NOT NULL,
CONSTRAINT messageDeliveryConfirmed_unique UNIQUE (recordId, messageHash, timestamp)
);

ALTER TABLE messageDeliveryConfirmed ADD CONSTRAINT fk_messageDeliveryConfirmed_telemetryRecord
FOREIGN KEY (recordId) REFERENCES telemetryRecord(id);
9 changes: 7 additions & 2 deletions lib/metrics/missing_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ type MissingRelevantMessage struct {
GenericMetric[types.MissingRelevantMessage]
}

type MessageDeliveryConfirmed struct {
GenericMetric[types.MessageDeliveryConfirmed]
}

var (
MissingMessageProcessor = &MissingMessage{}
MissingRelevantMessageProcessor = &MissingRelevantMessage{}
MissingMessageProcessor = &MissingMessage{}
MissingRelevantMessageProcessor = &MissingRelevantMessage{}
MessageDeliveryConfirmedProcessor = &MessageDeliveryConfirmed{}
)
Loading

0 comments on commit 5a35627

Please sign in to comment.