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

Commit 3615fd2

Browse files
committed
F004, F005 limit items in recommendations implemented
1 parent 62bb884 commit 3615fd2

File tree

7 files changed

+121
-29
lines changed

7 files changed

+121
-29
lines changed

pghrep/src/checkup/a002/a002.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func A002CheckAllVersionsIsSame(report A002Report,
143143
if diff && len(hosts) > 1 {
144144
result.AppendConclusion(english.PluralWord(len(hosts),
145145
MSG_NOT_ALL_VERSIONS_SAME_CONCLUSION_1, MSG_NOT_ALL_VERSIONS_SAME_CONCLUSION_N),
146-
strings.Join(hosts, "`, `"), strings.Join(getUniques(vers), "`, `"))
146+
strings.Join(hosts, "`, `"), strings.Join(checkup.GetUniques(vers), "`, `"))
147147
result.AppendRecommendation(MSG_NOT_ALL_VERSIONS_SAME_RECOMMENDATION)
148148
result.P2 = true
149149
} else {
@@ -228,7 +228,7 @@ func A002CheckMinorVersions(report A002Report, result checkup.ReportOutcome) che
228228
updateVersions = append(updateVersions, majorVersion+"."+strconv.Itoa(lastVersion))
229229
}
230230
}
231-
curVersions = getUniques(curVersions)
231+
curVersions = checkup.GetUniques(curVersions)
232232
if len(curVersions) > 0 {
233233
result.AppendConclusion(english.PluralWord(len(curVersions),
234234
MSG_NOT_LAST_MINOR_VERSION_CONCLUSION_1, MSG_NOT_LAST_MINOR_VERSION_CONCLUSION_N),
@@ -239,21 +239,6 @@ func A002CheckMinorVersions(report A002Report, result checkup.ReportOutcome) che
239239
return result
240240
}
241241

242-
func getUniques(array []string) []string {
243-
items := map[string]bool{}
244-
for _, item := range array {
245-
items[item] = true
246-
}
247-
248-
res := make([]string, len(items))
249-
i := 0
250-
for key, _ := range items {
251-
res[i] = key
252-
i++
253-
}
254-
return res
255-
}
256-
257242
func A002Process(report A002Report) checkup.ReportOutcome {
258243
var result checkup.ReportOutcome
259244
A002PrepareVersionInfo()

pghrep/src/checkup/checkuputil.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
const MSG_ALL_GOOD_CONCLUSION string = "Hooray, all good. Keep this up!"
1717
const MSG_NO_RECOMMENDATION string = "No recommendations."
18+
const MSG_ETC_ITEM string = " - etc."
19+
const RECOMMENDATION_ITEMS_LIMIT int = 5
1820

1921
type ReportHost struct {
2022
InternalAlias string `json:"internal_alias"`
@@ -128,3 +130,28 @@ func PrintReccomendations(result ReportOutcome) {
128130
fmt.Println("R: ", recommendation)
129131
}
130132
}
133+
134+
func GetUniques(array []string) []string {
135+
items := map[string]bool{}
136+
for _, item := range array {
137+
items[item] = true
138+
}
139+
140+
res := make([]string, len(items))
141+
i := 0
142+
for key, _ := range items {
143+
res[i] = key
144+
i++
145+
}
146+
return res
147+
}
148+
149+
func LimitList(array []string) []string {
150+
if len(array) <= RECOMMENDATION_ITEMS_LIMIT {
151+
return array
152+
} else {
153+
limitedArray := array[0:RECOMMENDATION_ITEMS_LIMIT]
154+
limitedArray = append(limitedArray, MSG_ETC_ITEM)
155+
return limitedArray
156+
}
157+
}

pghrep/src/checkup/f004/f004.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ func F004Process(report F004Report) checkup.ReportOutcome {
6464
strings.Join(top5tables, ""))
6565
result.P1 = true
6666
} else {
67-
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg, fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2))
67+
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg,
68+
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2))
6869
}
6970
if len(criticalTables) > 0 {
70-
result.AppendConclusion(MSG_BLOAT_CRITICAL_CONCLUSION, CRITICAL_BLOAT_RATIO, strings.Join(criticalTables, ""))
71+
result.AppendConclusion(MSG_BLOAT_CRITICAL_CONCLUSION, len(criticalTables), CRITICAL_BLOAT_RATIO,
72+
strings.Join(checkup.LimitList(criticalTables), ""))
7173
result.AppendRecommendation(MSG_BLOAT_CRITICAL_RECOMMENDATION)
7274
result.P1 = true
7375
}
7476
if len(warningTables) > 0 {
75-
result.AppendConclusion(MSG_BLOAT_WARNING_CONCLUSION, WARNING_BLOAT_RATIO, CRITICAL_BLOAT_RATIO, strings.Join(warningTables, ""))
77+
result.AppendConclusion(MSG_BLOAT_WARNING_CONCLUSION, len(warningTables), WARNING_BLOAT_RATIO, CRITICAL_BLOAT_RATIO,
78+
strings.Join(checkup.LimitList(warningTables), ""))
7679
if !result.P1 {
7780
result.AppendRecommendation(MSG_BLOAT_WARNING_RECOMMENDATION)
7881
}

pghrep/src/checkup/f004/f004_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,82 @@ func TestF004Warnig(t *testing.T) {
147147
OverridedSettings: false,
148148
BloatRatio: 2.46177370030581,
149149
},
150+
"table_3": F004HeapBloat{
151+
Num: 2,
152+
IsNa: "",
153+
TableName: "table_3",
154+
RealSize: "",
155+
ExtraSizeBytes: 3915776,
156+
ExtraRatioPercent: 59.3788819875776,
157+
Extra: "",
158+
BloatSizeBytes: 3915776,
159+
BloatRatioPercent: 59.3788819875776,
160+
BloatEstimate: "",
161+
RealSizeBytes: 6594560,
162+
LiveDataSize: "",
163+
LiveDataSizeBytes: 2678784,
164+
LastVaccuum: "",
165+
Fillfactor: 100.0,
166+
OverridedSettings: false,
167+
BloatRatio: 2.46177370030581,
168+
},
169+
"table_4": F004HeapBloat{
170+
Num: 2,
171+
IsNa: "",
172+
TableName: "table_4",
173+
RealSize: "",
174+
ExtraSizeBytes: 3915776,
175+
ExtraRatioPercent: 59.3788819875776,
176+
Extra: "",
177+
BloatSizeBytes: 3915776,
178+
BloatRatioPercent: 59.3788819875776,
179+
BloatEstimate: "",
180+
RealSizeBytes: 6594560,
181+
LiveDataSize: "",
182+
LiveDataSizeBytes: 2678784,
183+
LastVaccuum: "",
184+
Fillfactor: 100.0,
185+
OverridedSettings: false,
186+
BloatRatio: 2.46177370030581,
187+
},
188+
"table_5": F004HeapBloat{
189+
Num: 2,
190+
IsNa: "",
191+
TableName: "table_5",
192+
RealSize: "",
193+
ExtraSizeBytes: 3915776,
194+
ExtraRatioPercent: 59.3788819875776,
195+
Extra: "",
196+
BloatSizeBytes: 3915776,
197+
BloatRatioPercent: 59.3788819875776,
198+
BloatEstimate: "",
199+
RealSizeBytes: 6594560,
200+
LiveDataSize: "",
201+
LiveDataSizeBytes: 2678784,
202+
LastVaccuum: "",
203+
Fillfactor: 100.0,
204+
OverridedSettings: false,
205+
BloatRatio: 2.46177370030581,
206+
},
207+
"table_6": F004HeapBloat{
208+
Num: 2,
209+
IsNa: "",
210+
TableName: "table_6",
211+
RealSize: "",
212+
ExtraSizeBytes: 3915776,
213+
ExtraRatioPercent: 59.3788819875776,
214+
Extra: "",
215+
BloatSizeBytes: 3915776,
216+
BloatRatioPercent: 59.3788819875776,
217+
BloatEstimate: "",
218+
RealSizeBytes: 6594560,
219+
LiveDataSize: "",
220+
LiveDataSizeBytes: 2678784,
221+
LastVaccuum: "",
222+
Fillfactor: 100.0,
223+
OverridedSettings: false,
224+
BloatRatio: 2.46177370030581,
225+
},
150226
}
151227

152228
report.Results = F004ReportHostsResults{"test-host": hostResult}

pghrep/src/checkup/f004/f004messages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ const MSG_BLOAT_PX_RECOMMENDATION string = "Read more on this topic: \n" +
2626
" - [PostgreSQL Bloat: origins, monitoring and managing](https://www.compose.com/articles/postgresql-bloat-origins-monitoring-and-managing/) (2016, Compose) \n" +
2727
" - [Dealing with significant Postgres database bloat — what are your options?](https://medium.com/compass-true-north/dealing-with-significant-postgres-database-bloat-what-are-your-options-a6c1814a03a5) (2018, Compass) \n" +
2828
" - [Postgres database bloat analysis](https://about.gitlab.com/handbook/engineering/infrastructure/blueprint/201901-postgres-bloat/) (2019, GitLab) \n"
29-
const MSG_BLOAT_WARNING_CONCLUSION string = "[P2] There are some tables with size > 1 MiB and table bloat estimate >= %.0f%% and < %.0f%%: \n%s \n"
30-
const MSG_BLOAT_CRITICAL_CONCLUSION string = "[P1] The following tables have significant size (>1 MiB) and bloat estimate > %.0f%%: \n%s \n"
29+
const MSG_BLOAT_WARNING_CONCLUSION string = "[P2] There are %d tables with size > 1 MiB and table bloat estimate >= %.0f%% and < %.0f%%: \n%s \n"
30+
const MSG_BLOAT_CRITICAL_CONCLUSION string = "[P1] The following %d tables have significant size (>1 MiB) and bloat estimate > %.0f%%: \n%s \n"
3131
const TABLE_DETAILS string = " - `%s`: size %s, can be reduced %.2f times, by ~%s (~%.0f%%) \n"

pghrep/src/checkup/f005/f005.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ func F005Process(report F005Report) checkup.ReportOutcome {
6464
strings.Join(top5Indexes, ""))
6565
result.P1 = true
6666
} else {
67-
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg, fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2))
67+
result.AppendConclusion(MSG_TOTAL_BLOAT_LOW_CONCLUSION, totalData.BloatRatioPercentAvg,
68+
fmtutils.ByteFormat(float64(totalData.BloatSizeBytesSum), 2))
6869
}
6970
if len(criticalIndexes) > 0 {
70-
result.AppendConclusion(MSG_BLOAT_CRITICAL_CONCLUSION, CRITICAL_BLOAT_RATIO, strings.Join(criticalIndexes, ""))
71+
result.AppendConclusion(MSG_BLOAT_CRITICAL_CONCLUSION, len(criticalIndexes), CRITICAL_BLOAT_RATIO,
72+
strings.Join(checkup.LimitList(criticalIndexes), ""))
7173
result.AppendRecommendation(MSG_BLOAT_CRITICAL_RECOMMENDATION)
7274
result.P1 = true
7375
}
7476
if len(warningIndexes) > 0 {
75-
result.AppendConclusion(MSG_BLOAT_WARNING_CONCLUSION, WARNING_BLOAT_RATIO, CRITICAL_BLOAT_RATIO, strings.Join(warningIndexes, ""))
77+
result.AppendConclusion(MSG_BLOAT_WARNING_CONCLUSION, len(warningIndexes), WARNING_BLOAT_RATIO, CRITICAL_BLOAT_RATIO, strings.Join(checkup.LimitList(warningIndexes), ""))
7678
if !result.P1 {
7779
result.AppendRecommendation(MSG_BLOAT_WARNING_RECOMMENDATION)
7880
}

pghrep/src/checkup/f005/f005messages.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ const MSG_BLOAT_GENERAL_RECOMMENDATION_1 string = "If you want to get exact bloa
1717
const MSG_BLOAT_GENERAL_RECOMMENDATION_2 string = "To reduce the index bloat, consider using one of the following: \n" +
1818
" - [`VACUUM FULL`](https://www.postgresql.org/docs/OUR_MAJOR_VERSION/sql-vacuum.html) (:warning: requires downtime / maintenance window), \n" +
1919
" - [`REINDEX`](https://www.postgresql.org/docs/OUR_MAJOR_VERSION/sql-reindex.html) (`REINDEX INDEX`, `REINDEX TABLE`; :warning: requires downtime / maintenance window), \n" +
20-
" - `REINDEX CONCURRENTLY` << ONLY IF MAJOR VERSION IS >= 12 \n" +
21-
" - recreating indexes online using `CREATE INDEX CONCURRENTLY`, `DROP INDEX CONCURRENTLY` and renaming (not trivial for indexes supporting PK, FK), << ONLY IF MAJOR VERSION IS < 12 \n" +
20+
" - recreating indexes online using `CREATE INDEX CONCURRENTLY`, `DROP INDEX CONCURRENTLY` and renaming (not trivial for indexes supporting PK, FK) // Postgres 12 also provides `REINDEX CONCURRENTLY`, \n" +
2221
" - one of the tools reducing the bloat online, without interrupting the operations: \n" +
2322
" - [pg_repack](https://github.com/reorg/pg_repack), \n" +
2423
" - [pg_squeeze](https://github.com/reorg/pg_repack), \n" +
@@ -30,6 +29,6 @@ const MSG_BLOAT_PX_RECOMMENDATION string = "Read more on this topic: \n" +
3029
" - [PostgreSQL Bloat: origins, monitoring and managing](https://www.compose.com/articles/postgresql-bloat-origins-monitoring-and-managing/) (2016, Compose) \n" +
3130
" - [Dealing with significant Postgres database bloat — what are your options?](Dealing with significant Postgres database bloat — what are your options?) (2018, Compass) \n" +
3231
" - [Postgres database bloat analysis](https://about.gitlab.com/handbook/engineering/infrastructure/blueprint/201901-postgres-bloat/) (2019, GitLab) \n"
33-
const MSG_BLOAT_WARNING_CONCLUSION string = "[P2] There are some indexes with size > 1 MiB and index bloat estimate >= %.0f%% and < %.0f%%: \n%s \n"
34-
const MSG_BLOAT_CRITICAL_CONCLUSION string = "[P1] The following indexes have significant size (>1 MiB) and bloat estimate > %.0f%%: \n%s \n"
32+
const MSG_BLOAT_WARNING_CONCLUSION string = "[P2] There are %d indexes with size > 1 MiB and index bloat estimate >= %.0f%% and < %.0f%%: \n%s \n"
33+
const MSG_BLOAT_CRITICAL_CONCLUSION string = "[P1] The following %d indexes have significant size (>1 MiB) and bloat estimate > %.0f%%: \n%s \n"
3534
const INDEX_DETAILS string = " - `%s`: size %s, can be reduced %.2f times, by ~%s (~%.0f%%) \n"

0 commit comments

Comments
 (0)