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

Commit ae95301

Browse files
committed
Merge branch 'dmius-nodata-fix' into 'master'
A004 fix nil bug, A007 fix table, No data replaced by Nothing found in all templates See merge request postgres-ai/postgres-checkup!304
2 parents c7ce586 + d67faf6 commit ae95301

24 files changed

+124
-97
lines changed

pghrep/src/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,32 @@ func determineMasterReplica(data map[string]interface{}) {
331331
data["hosts"] = hostRoles
332332
}
333333

334+
/*
335+
Replace master on replica#1 if master not defined
336+
*/
337+
func reorderHosts(data map[string]interface{}) {
338+
hosts := pyraconv.ToInterfaceMap(data["hosts"])
339+
masterHost := pyraconv.ToString(hosts["master"])
340+
replicaHosts := pyraconv.ToStringArray(hosts["replicas"])
341+
var allHosts []string
342+
if hosts["master"] != nil {
343+
allHosts = append(allHosts, masterHost)
344+
}
345+
for _, replicaHost := range replicaHosts {
346+
allHosts = append(allHosts, replicaHost)
347+
}
348+
if len(allHosts) == 0 {
349+
return
350+
}
351+
master := allHosts[0]
352+
var replicas []string
353+
replicas = append(replicas, allHosts[1:]...)
354+
reorderedHosts := make(map[string]interface{})
355+
reorderedHosts["master"] = master
356+
reorderedHosts["replicas"] = replicas
357+
data["reorderedHosts"] = reorderedHosts
358+
}
359+
334360
func main() {
335361
// get input data checkId, checkData
336362
var checkId string
@@ -372,6 +398,7 @@ func main() {
372398
checkId = strings.ToUpper(checkId)
373399
loadDependencies(resultData)
374400
determineMasterReplica(resultData)
401+
reorderHosts(resultData)
375402

376403
l, err := newLoader()
377404
if err != nil {

pghrep/templates/A001.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Data collected: {{ DtFormat .timestamptz }}
100100
```
101101
{{ end }}
102102
{{ else }}
103-
`No data`
103+
`Nothing found`
104104
{{ end}}{{ end }}{{ end }}
105105

106106
## Conclusions ##

pghrep/templates/A002.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Data collected: {{ DtFormat .timestamptz }}
2424
{{ (index (index $.results $value) "data").version }}
2525
```
2626
{{ else }}
27-
No data
27+
Nothing found
2828
{{ end}}{{ end }}{{ end }}
2929

3030
## Conclusions ##

pghrep/templates/A003.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Data collected: {{ DtFormat .timestamptz }}
1313
| {{ $value.category }}|[{{ $key }}](https://postgresqlco.nf/en/doc/param/{{ $key }}) | {{ Br $value.setting }} | {{ if $value.unit }}{{ $value.unit }} {{ end }} | {{ UnitValue $value.setting $value.unit }} |
1414
{{ end }}
1515
{{- else -}}{{/*Master data*/}}
16-
No data
16+
Nothing found
1717
{{- end }}{{/*Master data*/}}
1818
{{- else -}}{{/*Master results*/}}
19-
No data
19+
Nothing found
2020
{{- end }}{{/*Master results*/}}
2121
{{- else -}}{{/*Master*/}}
22-
No data
22+
Nothing found
2323
{{ end }}{{/*Master*/}}
2424

pghrep/templates/A004.tpl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
## Observations ##
44
Data collected: {{ DtFormat .timestamptz }}
55

6-
|▼ Indicator | {{.hosts.master}} {{ range $skey, $host := .hosts.replicas }}| {{ $host }} {{ end }}|
7-
|--------|-------{{ range $skey, $host := .hosts.replicas }}|-------- {{ end }}|
8-
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "general_info") "_keys") }}
9-
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "general_info") $key) -}}
6+
|▼ Indicator | {{.reorderedHosts.master}} {{ range $skey, $host := .reorderedHosts.replicas }}| {{ $host }} {{ end }}|
7+
|--------|-------{{ range $skey, $host := .reorderedHosts.replicas }}|-------- {{ end }}|
8+
{{ range $i, $key := (index (index (index (index .results .reorderedHosts.master) "data") "general_info") "_keys") }}
9+
{{- $value := (index (index (index (index $.results $.reorderedHosts.master) "data") "general_info") $key) -}}
1010
|{{ $key }} |
1111
{{- Nobr (index $value "value") }}
12-
{{- range $skey, $host := $.hosts.replicas }}|
12+
{{- range $skey, $host := $.reorderedHosts.replicas }}|
1313
{{- if (index $.results $host) }}
1414
{{- if (index (index $.results $host) "data") }}
1515
{{- if (index (index (index $.results $host) "data") "general_info") }}
@@ -20,15 +20,15 @@ Data collected: {{ DtFormat .timestamptz }}
2020
{{- end }}|
2121
{{ end }}
2222

23-
{{ if .hosts.master }}
24-
{{- if (index .results .hosts.master) -}}
25-
{{- if (index (index .results .hosts.master) "data") -}}
23+
{{ if .reorderedHosts.master }}
24+
{{- if (index .results .reorderedHosts.master) -}}
25+
{{- if (index (index .results .reorderedHosts.master) "data") -}}
2626
### Databases sizes ###
2727

2828
| Database | ▼ Size |
2929
|----------|--------|
30-
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "database_sizes") "_keys") }}
31-
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "database_sizes") $key) -}}
30+
{{ range $i, $key := (index (index (index (index .results .reorderedHosts.master) "data") "database_sizes") "_keys") }}
31+
{{- $value := (index (index (index (index $.results $.reorderedHosts.master) "data") "database_sizes") $key) -}}
3232
| `{{ $key }}` | {{ ByteFormat $value 2 }} |
3333
{{ end }}
3434
{{- end -}}

pghrep/templates/A006.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ No differences in `pg_settings` are found.
2222
No differences in `pg_config` are found.
2323
{{end}}
2424
{{ else }}
25-
No data
25+
Nothing found
2626
{{ end }}
2727

2828
## Conclusions ##

pghrep/templates/A007.tpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Data collected: {{ DtFormat .timestamptz }}
88
### Master (`{{.hosts.master}}`) ###
99
| Source | Settings count | Changed settings |
1010
|-------|----------------|-----------------|
11-
{{ range $key, $value := (index (index (index .results .hosts.master) "data") "changes") }}| {{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
12-
{{ end }}|{{ end }}
11+
{{ range $key, $value := (index (index (index .results .hosts.master) "data") "changes") }}| {{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }}{{ end }}{{ end }}|
12+
{{ end }}
13+
1314
{{ end }}
1415
{{ end }}
1516
{{ end }}
@@ -21,8 +22,8 @@ Data collected: {{ DtFormat .timestamptz }}
2122
{{ if (index $.results $host) }}
2223
| Source | Settings count | Changed settings |
2324
|-------|----------------|-----------------|
24-
{{ range $key, $value := (index (index (index $.results $host) "data") "changes") }}|{{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }} {{ end }}
25-
{{ end }}|{{ end }}
25+
{{ range $key, $value := (index (index (index $.results $host) "data") "changes") }}|{{ if $value.sourcefile }}{{ $value.sourcefile }}{{ else}}default{{ end }} | {{ $value.count }} | {{ if $value.examples}} {{ if (gt (len $value.examples) 0) }}{{ range $skey, $sname := (index $value "examples") }}{{ $sname }} {{ end }}{{ end }}{{ end }}|
26+
{{ end }}
2627
{{ else }}
2728
No data
2829
{{ end}}{{ end }}{{ end }}

pghrep/templates/D004.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ Data collected: {{ DtFormat .timestamptz }}
2626
{{ end }}
2727
{{- end -}}
2828
{{- else -}}{{/*Master data*/}}
29-
No data
29+
Nothing found
3030
{{- end }}{{/*Master data*/}}
3131
{{- else -}}{{/*Master results*/}}
32-
No data
32+
Nothing found
3333
{{- end }}{{/*Master results*/}}
3434
{{- else -}}{{/*Master*/}}
35-
No data
35+
Nothing found
3636
{{ end }}{{/*Master*/}}
3737

3838
## Conclusions ##

pghrep/templates/F001.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ No tuned tables are found
3737
| Setting {{ range $skey, $host := .hosts.replicas }}| {{ $host }} {{ end }} |
3838
|--------{{ range $skey, $host := .hosts.replicas }}|-------- {{ end }}|
3939
|[hot_standby_feedback](https://postgresqlco.nf/en/doc/param/hot_standby_feedback)
40-
{{- range $skey, $host := .hosts.replicas -}}| {{if (index $.results $host) }}{{- $value := (index (index (index (index (index $.results $host) "data") "settings") "global_settings") "hot_standby_feedback") -}}{{- $value.setting -}}{{ else }}No data{{ end }} |
40+
{{- range $skey, $host := .hosts.replicas -}}| {{if (index $.results $host) }}{{- $value := (index (index (index (index (index $.results $host) "data") "settings") "global_settings") "hot_standby_feedback") -}}{{- $value.setting -}}{{ else }}Nothing found{{ end }} |
4141
{{- end -}}{{/* range replicas */}}
4242
{{ end }}{{/* if replicas */}}
4343

pghrep/templates/F002.tpl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Current database: {{ .database }}
2323
{{ end }}{{/* range */}}
2424
{{- end -}}{{/* if per_instance exists */}}
2525

26-
{{/* if index (index (index .results .hosts.master) "data") "per_database" */}}
2726
#### Tables in the observed database ####
2827
{{ if gt (len (index (index (index .results .hosts.master) "data") "per_database")) .LISTLIMIT }}The list is limited to {{.LISTLIMIT}} items.{{ end }}
2928

@@ -43,13 +42,13 @@ Current database: {{ .database }}
4342
\* This table has specific autovacuum settings. See 'F001 Autovacuum: Current settings'
4443
{{- end }}
4544
{{- else -}}{{/*Master data*/}}
46-
No data
45+
Nothing found
4746
{{- end }}{{/*Master data*/}}
4847
{{- else -}}{{/*Master results*/}}
49-
No data
48+
Nothing found
5049
{{- end }}{{/*Master results*/}}
5150
{{- else -}}{{/*Master*/}}
52-
No data
51+
Nothing found
5352
{{ end }}{{/*Master*/}}
5453

5554

0 commit comments

Comments
 (0)