Skip to content

Commit

Permalink
backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Oct 30, 2024
1 parent eeb6814 commit be20aba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
31 changes: 22 additions & 9 deletions flow/cmd/mirror_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,24 +602,32 @@ func (h *FlowRequestHandler) ListMirrorLogs(
}

sortOrderBy := "desc"
if req.BeforeId != -1 {
whereArgs = append(whereArgs, req.BeforeId)
whereExprs = append(whereExprs, fmt.Sprintf("id < $%d", len(whereArgs)))
} else if req.AfterId != -1 {
whereArgs = append(whereArgs, req.AfterId)
whereExprs = append(whereExprs, fmt.Sprintf("id > $%d", len(whereArgs)))
sortOrderBy = ""
if req.BeforeId != 0 && req.AfterId != 0 {
if req.BeforeId != -1 {
whereArgs = append(whereArgs, req.BeforeId)
whereExprs = append(whereExprs, fmt.Sprintf("id < $%d", len(whereArgs)))
} else if req.AfterId != -1 {
whereArgs = append(whereArgs, req.AfterId)
whereExprs = append(whereExprs, fmt.Sprintf("id > $%d", len(whereArgs)))
sortOrderBy = ""
}
}

var whereClause string
if len(whereExprs) != 0 {
whereClause = " WHERE " + strings.Join(whereExprs, " AND ")
}

// page is deprecated
var offsetClause string
if req.Page != 0 {
offsetClause = fmt.Sprintf(" offset %d", req.Page*req.NumPerPage)
}

rows, err := h.pool.Query(ctx, fmt.Sprintf(`select id, flow_name, error_message, error_type, error_timestamp
from peerdb_stats.flow_errors%s
order by id %s
limit %d`, whereClause, sortOrderBy, req.NumPerPage), whereArgs...)
limit %d%s`, whereClause, sortOrderBy, req.NumPerPage, offsetClause), whereArgs...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -658,9 +666,14 @@ func (h *FlowRequestHandler) ListMirrorLogs(
return nil, err
}

page := req.Page
if page == 0 {
page = rowsBehind/req.NumPerPage + 1
}

return &protos.ListMirrorLogsResponse{
Errors: mirrorErrors,
Total: total,
Page: rowsBehind/req.NumPerPage + 1,
Page: page,
}, nil
}
7 changes: 4 additions & 3 deletions protos/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ message MirrorLog {
message ListMirrorLogsRequest {
string flow_job_name = 1;
string level = 2;
int32 num_per_page = 3;
int32 before_id = 4;
int32 after_id = 5;
int32 page = 3;
int32 num_per_page = 4;
int32 before_id = 5;
int32 after_id = 6;
}
message ListMirrorLogsResponse {
repeated MirrorLog errors = 1;
Expand Down

0 comments on commit be20aba

Please sign in to comment.