Skip to content

Commit

Permalink
db list: display active time
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Nov 8, 2023
1 parent 82005f1 commit e305642
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/koyeb/databases_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ func (r *ListDatabasesReply) MarshalBinary() ([]byte, error) {
}

func (r *ListDatabasesReply) Headers() []string {
return []string{"id", "name", "region", "engine", "status", "used_storage", "created_at"}
return []string{"id", "name", "region", "engine", "status", "active_time", "used_storage", "created_at"}
}

func (r *ListDatabasesReply) Fields() []map[string]string {
items := r.databases
resp := make([]map[string]string, 0, len(items))

for _, item := range items {
var region string
var engine string
var usedStorage string
var region, engine, activeTime, usedStorage string

// At the moment, we only support neon postgres so the if statement is
// always true. If we add support for other providers in the future, the statement
// will prevent a nil pointer dereference.
if item.Deployment.DatabaseInfo.HasNeonPostgres() {
region = item.Deployment.Definition.GetDatabase().NeonPostgres.GetRegion()
engine = fmt.Sprintf("Postgres %d", item.Deployment.Definition.GetDatabase().NeonPostgres.GetPgVersion())
Expand All @@ -111,6 +112,9 @@ func (r *ListDatabasesReply) Fields() []map[string]string {
size = size / 1024 / 1024
// The maximum size is 3GB and is not configurable yet.
maxSize := 3 * 1024
activeTimeValue, _ := strconv.ParseFloat(item.Deployment.DatabaseInfo.NeonPostgres.GetActiveTimeSeconds(), 32)
// The maximum active time is 100h and is not configurable yet.
activeTime = fmt.Sprintf("%.1fh/100h", activeTimeValue/60/60)
usedStorage = fmt.Sprintf("%dMB/%dMB (%d%%)", size, maxSize, size*100/maxSize)
}

Expand All @@ -120,6 +124,7 @@ func (r *ListDatabasesReply) Fields() []map[string]string {
"region": region,
"engine": engine,
"status": formatServiceStatus(item.Service.GetStatus()),
"active_time": activeTime,
"used_storage": usedStorage,
"created_at": renderer.FormatTime(item.Service.GetCreatedAt()),
}
Expand Down

0 comments on commit e305642

Please sign in to comment.