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 endpoint for batching different metrics in single request #16

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

adklempner
Copy link
Collaborator

@adklempner adklempner commented May 28, 2024

  • add endpoint for batching many different metrics in a single request
  • add status version field to all metrics (optional for backwards compatibility)
  • add table and endpoint for handling sent envelopes

Note that this does not break backwards compatibility with older versions of status (pre this PR status-im/status-go#5251)

Copy link
Member

@richard-ramos richard-ramos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Just left some minor comments that should be looked at before merging!

Comment on lines 79 to 83
if err := decoder.Decode(&telemetryData); err != nil {
log.Println(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it failed to decode the body, we should probably fail early here with a 4xx error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in latest commit


for _, data := range telemetryData {
switch data.TelemetryType {
case "ProtocolStats":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the constant ProtocolStatsMetric here and same for other cases. Assuming go complains about the var type then we can change TelemetryType to be an alias instead of a type like this:

type TelemetryType = string

Comment on lines 94 to 99
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil
} else {
return err
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrNoRows shouldnt happen.

Suggested change
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil
} else {
return err
}
}
if err != nil {
return err
}

Comment on lines 92 to 97
lastInsertId, _ = res.LastInsertId()

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for the error of stmt.Exec before retrieving the LastInsertId,
Also, we should check for the error in res.LastInsertId instead of using _.

Copy link
Collaborator Author

@adklempner adklempner Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I end up seeing this error:

Error saving sent envelope: LastInsertId is not supported by this driver Id:8

It looks like postgres does not support LastInsertId. This is probably why the existing code for received envelopes uses QueryRow and Scan to get the id

This commit adds a new endpoint which expects the body to be a
JSON array of arbitrary metrics, allowing a single request to
include more than one metric of one or more types. Also adds an
optional status version field to tables.
@adklempner adklempner merged commit 8fe3616 into status-im:master Jun 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants