-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21355] [yugabyted][UI]: List the Scheduled PITR on yugabyted UI.
Summary: Create a new /pitr endpoint for sending the list of scheduled PITRs. Test Plan: Manual Testing Reviewers: sgarg-yb, nikhil Reviewed By: nikhil Subscribers: djiang, yugabyted-dev, shikhar.sahay Differential Revision: https://phorge.dev.yugabyte.com/D32992
- Loading branch information
1 parent
a7cfb26
commit d8b27b1
Showing
15 changed files
with
361 additions
and
1 deletion.
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
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,75 @@ | ||
package handlers | ||
|
||
import ( | ||
"apiserver/cmd/server/helpers" | ||
"apiserver/cmd/server/models" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
const ( | ||
_24h_FORMAT = "2006-01-02 15:04:05" | ||
_12h_FORMAT = "2006-01-02 03:04:05 PM" | ||
) | ||
|
||
// Get PITR Configs | ||
func (c *Container) GetPITRConfigurations(ctx echo.Context) error { | ||
pitrConfigFuture := make(chan helpers.PITRConfigFuture) | ||
go c.helper.GetPITRConfigFuture(pitrConfigFuture) | ||
pitrConfigResult := <-pitrConfigFuture | ||
if pitrConfigResult.Error != nil { | ||
errorMessage := fmt.Sprintf("Error retrieving PITR configuration: %v", | ||
pitrConfigResult.Error) | ||
return ctx.String(http.StatusInternalServerError, errorMessage) | ||
} | ||
var response models.PITRScheduleInfo | ||
activeSchedules := false | ||
for i := len(pitrConfigResult.Config.Schedules) - 1; i >= 0; i-- { | ||
schedule := pitrConfigResult.Config.Schedules[i] | ||
if schedule.Options.DeleteTime == "" { | ||
activeSchedules = true | ||
break | ||
} | ||
} | ||
if activeSchedules { | ||
var schedule_entry int32 = 0 | ||
for _, schedule := range pitrConfigResult.Config.Schedules { | ||
if schedule.Options.DeleteTime != "" { | ||
continue | ||
} | ||
schedule_entry++ | ||
filter := schedule.Options.Filter | ||
name := strings.Split(filter, ".")[1] | ||
interval := "24 hours" | ||
retentionInMinutes,_ := strconv.Atoi(strings.Split(schedule.Options.Retention, " ")[0]) | ||
retentionInDays := retentionInMinutes / (24 * 60) | ||
retention := fmt.Sprintf("%d days", retentionInDays) | ||
earliest_recoverable_time := schedule.Snapshots[0].SnapshotTime | ||
parsedTime, err := time.Parse(_24h_FORMAT, earliest_recoverable_time) | ||
if err != nil { | ||
return ctx.JSON(http.StatusInternalServerError, map[string]string{ | ||
"error": "Failed to parse snapshot time: " + err.Error(), | ||
}) | ||
} | ||
modifiedTime := parsedTime.Add(time.Second).Truncate(time.Second) | ||
formattedTime := modifiedTime.Format(_12h_FORMAT) | ||
|
||
scheduleEntry := models.PitrSchedule{ | ||
Id: schedule_entry, | ||
DatabaseKeyspace: name, | ||
Interval: interval, | ||
Retention: retention, | ||
EarliestRecoverableTime: formattedTime, | ||
} | ||
response.Schedules = append(response.Schedules, scheduleEntry) | ||
} | ||
} else { | ||
return ctx.JSON(http.StatusOK, []interface{}{}) | ||
} | ||
return ctx.JSON(http.StatusOK, response) | ||
} |
74 changes: 74 additions & 0 deletions
74
yugabyted-ui/apiserver/cmd/server/helpers/parse_pitr_configs.go
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,74 @@ | ||
package helpers | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"fmt" | ||
) | ||
|
||
// PITRConfig represents the entire JSON output from the yb-admin command. | ||
type PITRConfig struct { | ||
Schedules []Schedule `json:"schedules"` | ||
} | ||
|
||
// Schedule represents each individual schedule in the output. | ||
type Schedule struct { | ||
Options Options `json:"options"` | ||
Snapshots []Snapshot `json:"snapshots"` | ||
} | ||
|
||
// Options represents the options for each schedule. | ||
type Options struct { | ||
Filter string `json:"filter"` | ||
Interval string `json:"interval"` | ||
Retention string `json:"retention"` | ||
DeleteTime string `json:"delete_time,omitempty"` | ||
} | ||
|
||
// Snapshot represents each snapshot within a schedule. | ||
type Snapshot struct { | ||
SnapshotTime string `json:"snapshot_time"` | ||
} | ||
|
||
type PITRConfigFuture struct { | ||
Config PITRConfig | ||
Error error | ||
} | ||
|
||
func (h *HelperContainer) GetPITRConfigFuture(future chan PITRConfigFuture) { | ||
pitrConfigResult := PITRConfigFuture{ | ||
Config: PITRConfig{}, | ||
Error: nil, | ||
} | ||
masterAddresses := MasterAddressCache.Get() | ||
masterAddressesString := strings.Join(masterAddresses, ",") | ||
ybAdminResult, ybAdminError := h.ListSnapshotSchedules(masterAddressesString) | ||
if ybAdminError != nil { | ||
// Fetch updated master addresses and retry | ||
updatedMasterAddressesFuture := make(chan MasterAddressesFuture) | ||
go h.GetMasterAddressesFuture(updatedMasterAddressesFuture) | ||
updatedMasterAddressesResult := <-updatedMasterAddressesFuture | ||
if updatedMasterAddressesResult.Error != nil { | ||
// If fetching updated addresses also fails, return an error | ||
pitrConfigResult.Error = fmt.Errorf("failed to fetch updated master addresses: %v", | ||
updatedMasterAddressesResult.Error) | ||
future <- pitrConfigResult | ||
return | ||
} | ||
// Try with updated addresses | ||
updatedMasterAddressesString := strings.Join(updatedMasterAddressesResult.HostList, ",") | ||
ybAdminResult, ybAdminError = h.ListSnapshotSchedules(updatedMasterAddressesString) | ||
if ybAdminError != nil { | ||
// If the second attempt also fails, return an error | ||
pitrConfigResult.Error = fmt.Errorf("failed to list snapshot schedules: %v", | ||
ybAdminError) | ||
future <- pitrConfigResult | ||
return | ||
} | ||
} | ||
err := json.Unmarshal([]byte(ybAdminResult), &pitrConfigResult.Config) | ||
if err != nil { | ||
pitrConfigResult.Error = fmt.Errorf("failed to unmarshal snapshot schedules: %v", err) | ||
} | ||
future <- pitrConfigResult | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
yugabyted-ui/apiserver/cmd/server/models/model_pitr_schedule.go
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 @@ | ||
package models | ||
|
||
// PitrSchedule - Details of a Point-in-Time Recovery (PITR) schedule | ||
type PitrSchedule struct { | ||
|
||
Id int32 `json:"id"` | ||
|
||
DatabaseKeyspace string `json:"databaseKeyspace"` | ||
|
||
Interval string `json:"interval"` | ||
|
||
Retention string `json:"retention"` | ||
|
||
EarliestRecoverableTime string `json:"earliestRecoverableTime"` | ||
} |
6 changes: 6 additions & 0 deletions
6
yugabyted-ui/apiserver/cmd/server/models/model_schedules_response.go
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,6 @@ | ||
package models | ||
|
||
type PITRScheduleInfo struct { | ||
|
||
Schedules []PitrSchedule `json:"schedules"` | ||
} |
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
Oops, something went wrong.