-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track store confirmation failures
- Loading branch information
1 parent
171275d
commit 2a29886
Showing
6 changed files
with
170 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TABLE IF NOT EXISTS storeConfirmationFailed ( | ||
id SERIAL PRIMARY KEY, | ||
messageHash TEXT NOT NULL, | ||
recordId INTEGER NOT NULL | ||
); | ||
|
||
ALTER TABLE storeConfirmationFailed ADD CONSTRAINT fk_storeConfirmationFailed_telemetryRecord | ||
FOREIGN KEY (recordId) REFERENCES telemetryRecord(id); | ||
|
||
ALTER TABLE storeConfirmationFailed | ||
ADD CONSTRAINT storeConfirmationFailed_unique | ||
UNIQUE ( | ||
recordId, | ||
messageHash | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/status-im/telemetry/lib/common" | ||
"github.com/status-im/telemetry/pkg/types" | ||
) | ||
|
||
type StoreConfirmationFailed struct { | ||
types.StoreConfirmationFailed | ||
} | ||
|
||
func (s *StoreConfirmationFailed) Process(ctx context.Context, db *sql.DB, errs *common.MetricErrors, data *types.TelemetryRequest) error { | ||
if err := json.Unmarshal(*data.TelemetryData, &s); err != nil { | ||
errs.Append(data.ID, fmt.Sprintf("Error decoding store confirmation failed: %v", err)) | ||
return err | ||
} | ||
|
||
if err := s.Put(ctx, db); err != nil { | ||
errs.Append(data.ID, fmt.Sprintf("Error saving store confirmation failed: %v", err)) | ||
return err | ||
} | ||
|
||
log.Printf("AK: store confirmation metric saved: %v", s) | ||
return nil | ||
} | ||
|
||
func (s *StoreConfirmationFailed) Put(ctx context.Context, db *sql.DB) error { | ||
tx, err := db.BeginTx(ctx, nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer tx.Rollback() | ||
|
||
recordId, err := InsertTelemetryRecord(tx, &s.TelemetryRecord) | ||
if err != nil { | ||
return err | ||
} | ||
result := tx.QueryRow("INSERT INTO storeConfirmationFailed (recordId, messageHash) VALUES ($1, $2) RETURNING id;", recordId, s.MessageHash) | ||
if result.Err() != nil { | ||
return result.Err() | ||
} | ||
|
||
err = result.Scan(&s.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *StoreConfirmationFailed) Clean(db *sql.DB, before int64) (int64, error) { | ||
return common.Cleanup(db, "storeConfirmationFailed", before) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters