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 4dfc180
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 63 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
6 changes: 6 additions & 0 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 @@ -121,6 +122,11 @@ func DropTables(db *sql.DB) {
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
111 changes: 67 additions & 44 deletions lib/database/bindata.go

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

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{}
)
40 changes: 24 additions & 16 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import "encoding/json"
type TelemetryType string

const (
ProtocolStatsMetric TelemetryType = "ProtocolStats"
ReceivedEnvelopeMetric TelemetryType = "ReceivedEnvelope"
SentEnvelopeMetric TelemetryType = "SentEnvelope"
UpdateEnvelopeMetric TelemetryType = "UpdateEnvelope"
ReceivedMessagesMetric TelemetryType = "ReceivedMessages"
ErrorSendingEnvelopeMetric TelemetryType = "ErrorSendingEnvelope"
PeerCountMetric TelemetryType = "PeerCount"
PeerConnFailureMetric TelemetryType = "PeerConnFailure"
PeerCountByShardMetric TelemetryType = "PeerCountByShard"
PeerCountByOriginMetric TelemetryType = "PeerCountByOrigin"
MessageCheckSuccessMetric TelemetryType = "MessageCheckSuccess"
MessageCheckFailureMetric TelemetryType = "MessageCheckFailure"
DialFailureMetric TelemetryType = "DialFailure"
StoreConfrimationErrorMetric TelemetryType = "StoreConfrimationError"
MissingMessageMetric TelemetryType = "MissedMessage"
MissingRelevantMessageMetric TelemetryType = "MissedRelevantMessage"
ProtocolStatsMetric TelemetryType = "ProtocolStats"
ReceivedEnvelopeMetric TelemetryType = "ReceivedEnvelope"
SentEnvelopeMetric TelemetryType = "SentEnvelope"
UpdateEnvelopeMetric TelemetryType = "UpdateEnvelope"
ReceivedMessagesMetric TelemetryType = "ReceivedMessages"
ErrorSendingEnvelopeMetric TelemetryType = "ErrorSendingEnvelope"
PeerCountMetric TelemetryType = "PeerCount"
PeerConnFailureMetric TelemetryType = "PeerConnFailure"
PeerCountByShardMetric TelemetryType = "PeerCountByShard"
PeerCountByOriginMetric TelemetryType = "PeerCountByOrigin"
MessageCheckSuccessMetric TelemetryType = "MessageCheckSuccess"
MessageCheckFailureMetric TelemetryType = "MessageCheckFailure"
DialFailureMetric TelemetryType = "DialFailure"
StoreConfrimationErrorMetric TelemetryType = "StoreConfrimationError"
MissingMessageMetric TelemetryType = "MissedMessage"
MissingRelevantMessageMetric TelemetryType = "MissedRelevantMessage"
MessageDeliveryConfirmedMetric TelemetryType = "MessageDeliveryConfirmed"
)

type Origin int64
Expand Down Expand Up @@ -189,3 +190,10 @@ type MissingRelevantMessage struct {
SentAt int64 `json:"sentAt"`
PubsubTopic string `json:"pubsubTopic"`
}

type MessageDeliveryConfirmed struct {
TelemetryRecord
ID int `json:"id"`
MessageHash string `json:"messageHash"`
Timestamp int64 `json:"timestamp"`
}

0 comments on commit 4dfc180

Please sign in to comment.