Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit eea20ff

Browse files
committed
Merge branch 'dmius-l003' into 'master'
fix: l003 sort See merge request postgres-ai/postgres-checkup!451
2 parents e680614 + cb90246 commit eea20ff

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

pghrep/src/checkup/checkuputil.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ func SortItemsByInt(data interface{}, field string, reverse bool) []string {
274274
// Get map keys sorted by defined float64 field inside struct
275275
func SortItemsByFloat64(data interface{}, field string, reverse bool) []string {
276276
var result []string
277-
var numData map[float64]string = map[float64]string{}
277+
var numData map[float64]int = map[float64]int{}
278278
var keys []float64
279+
var values []string
279280

280281
v := reflect.ValueOf(data)
281282

@@ -298,7 +299,16 @@ func SortItemsByFloat64(data interface{}, field string, reverse bool) []string {
298299

299300
num := valNum.Interface()
300301
floatNum := num.(float64)
301-
numData[floatNum] = id.(string)
302+
for true {
303+
if _, ok := numData[floatNum]; ok {
304+
floatNum = floatNum * 1.000001
305+
} else {
306+
break
307+
}
308+
}
309+
310+
values = append(values, id.(string))
311+
numData[floatNum] = len(values) - 1
302312
keys = append(keys, floatNum)
303313
}
304314

@@ -309,7 +319,7 @@ func SortItemsByFloat64(data interface{}, field string, reverse bool) []string {
309319
}
310320

311321
for _, key := range keys {
312-
result = append(result, numData[key])
322+
result = append(result, values[numData[key]])
313323
}
314324
}
315325

pghrep/src/checkup/l003/l003.go

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
checkup ".."
9+
"../../pyraconv"
910
"github.com/dustin/go-humanize/english"
1011
)
1112

@@ -41,6 +42,18 @@ func L003Process(report L003Report) (checkup.ReportResult, error) {
4142
return result, nil
4243
}
4344

45+
func L003ProcessSortTables(data map[string]interface{}, report L003Report) (map[string]interface{}, error) {
46+
for host, hostData := range report.Results {
47+
sortedTables := checkup.SortItemsByFloat64(hostData.Data.Tables, "CapacityUsedPercent", true)
48+
results := pyraconv.ToInterfaceMap(data["results"])
49+
rawHostData := pyraconv.ToInterfaceMap(results[host])
50+
tablesData := pyraconv.ToInterfaceMap(rawHostData["data"])
51+
tablesData["sortedTables"] = sortedTables
52+
}
53+
54+
return data, nil
55+
}
56+
4457
func L003PreprocessReportData(data map[string]interface{}) {
4558
var report L003Report
4659
filePath := data["source_path_full"].(string)
@@ -56,5 +69,6 @@ func L003PreprocessReportData(data map[string]interface{}) {
5669
return
5770
}
5871

72+
data, _ = L003ProcessSortTables(data, report)
5973
checkup.SaveReportResult(data, result)
6074
}

pghrep/templates/L003.tpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ Current database: {{ .database }}
88
{{- if (index (index .results .hosts.master) "data") }}
99
{{ if gt (Int (index (index (index .results .reorderedHosts.master) "data") "min_table_size_bytes")) 0 }}NOTICE: only tables larger than {{ ByteFormat (index (index (index .results .reorderedHosts.master) "data") "min_table_size_bytes") 0 }} are analyzed.
1010
{{end}}
11-
{{- if (index (index (index .results .hosts.master) "data") "tables") }}
11+
{{- if (index (index (index .results .hosts.master) "data") "sortedTables") }}
1212
### Master (`{{.hosts.master}}`) ###
1313
{{ if ge (len (index (index .results .hosts.master) "data")) .LISTLIMIT }}The list is limited to {{.LISTLIMIT}} items. Total: {{ Sub (len (index (index .results .hosts.master) "data")) 1 }}.{{ end }}
1414

1515
| Table | PK | Type | Current max value | ▼ Capacity used, % |
1616
|------|----|------|-------------------|-------------------------------|
17-
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "tables") "_keys") }}
17+
{{ range $i, $table := (index (index (index .results .hosts.master) "data") "sortedTables") }}
1818
{{- if lt $i $.LISTLIMIT -}}
19-
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "tables") $key) -}}
19+
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "tables") $table) -}}
2020
|`{{ index $value "table"}}` | `{{ index $value "pk"}}` | {{ index $value "type"}} | {{- RawIntFormat (index $value "current_max_value")}} | {{ index $value "capacity_used_percent"}}|
21-
{{ end }}
2221
{{- end }}
22+
{{ end }}
2323
{{- else -}}{{/*Tables data*/}}
2424
Nothing found
2525
{{- end }}{{/*Tables data*/}}

0 commit comments

Comments
 (0)