@@ -48,10 +48,22 @@ func (exec Executor) pgBackRestCheck() (string, string, error) {
4848}
4949
5050// postgresqlListLogFiles returns the full path of numLogs log files.
51- func (exec Executor ) listPGLogFiles (numLogs int ) (string , string , error ) {
51+ func (exec Executor ) listPGLogFiles (numLogs int , hasInstrumentation bool ) (string , string , error ) {
5252 var stdout , stderr bytes.Buffer
5353
54- command := fmt .Sprintf ("ls -1dt pgdata/pg[0-9][0-9]/log/* | head -%d" , numLogs )
54+ location := "pgdata/pg[0-9][0-9]/log/*"
55+ if hasInstrumentation {
56+ location = "pgdata/logs/postgres/*.*"
57+ }
58+ // Check both the older and the newer log locations.
59+ // If a cluster has used both locations, this will return logs from both.
60+ // If a cluster does not have one location or the other, continue without error.
61+ // This ensures we get as many logs as possible for whatever combination of
62+ // log files exists on this cluster.
63+ // Note the "*.*" pattern to exclude the `receiver` directory,
64+ // which only the collector container has permission to access.
65+ command := fmt .Sprintf ("ls -1dt %s | head -%d" ,
66+ location , numLogs )
5567 err := exec (nil , & stdout , & stderr , "bash" , "-ceu" , "--" , command )
5668
5769 return stdout .String (), stderr .String (), err
@@ -73,7 +85,9 @@ func (exec Executor) listPGConfFiles() (string, string, error) {
7385func (exec Executor ) listBackrestLogFiles () (string , string , error ) {
7486 var stdout , stderr bytes.Buffer
7587
76- command := "ls -1dt pgdata/pgbackrest/log/*"
88+ // Note the "*.*" pattern to exclude the `receiver` directory,
89+ // which only the collector container has permission to access.
90+ command := "ls -1dt pgdata/pgbackrest/log/*.*"
7791 err := exec (nil , & stdout , & stderr , "bash" , "-ceu" , "--" , command )
7892
7993 return stdout .String (), stderr .String (), err
@@ -84,7 +98,9 @@ func (exec Executor) listBackrestLogFiles() (string, string, error) {
8498func (exec Executor ) listPatroniLogFiles () (string , string , error ) {
8599 var stdout , stderr bytes.Buffer
86100
87- command := "ls -1dt pgdata/patroni/log/*"
101+ // Note the "*.*" pattern to exclude the `receiver` directory,
102+ // which only the collector container has permission to access.
103+ command := "ls -1dt pgdata/patroni/log/*.*"
88104 err := exec (nil , & stdout , & stderr , "bash" , "-ceu" , "--" , command )
89105
90106 return stdout .String (), stderr .String (), err
@@ -95,7 +111,9 @@ func (exec Executor) listPatroniLogFiles() (string, string, error) {
95111func (exec Executor ) listBackrestRepoHostLogFiles () (string , string , error ) {
96112 var stdout , stderr bytes.Buffer
97113
98- command := "ls -1dt pgbackrest/*/log/*"
114+ // Note the "*.*" pattern to exclude the `receiver` directory,
115+ // which only the collector container has permission to access.
116+ command := "ls -1dt pgbackrest/*/log/*.*"
99117 err := exec (nil , & stdout , & stderr , "bash" , "-ceu" , "--" , command )
100118
101119 return stdout .String (), stderr .String (), err
0 commit comments