Skip to content

Commit

Permalink
Fixed parse Patroni response (#26)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikhail Grigorev <[email protected]>
  • Loading branch information
CHERTS and Mikhail Grigorev authored Jul 5, 2024
1 parent 42612ec commit fc5fa02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This project is a continuation of the development of the original pgSCV by [Alex
Download the archive from [releases](https://github.com/cherts/pgscv/releases). Unpack the archive. Create minimum config file. Start pgSCV systemd service under `postgres` user.

```bash
curl -s -L https://github.com/cherts/pgscv/releases/download/v0.8.4/pgscv_0.8.4_linux_amd64.tar.gz -o - | tar xzf - -C /tmp && \
curl -s -L https://github.com/cherts/pgscv/releases/download/v0.8.5/pgscv_0.8.5_linux_amd64.tar.gz -o - | tar xzf - -C /tmp && \
mv /tmp/pgscv.yaml /etc && \
mv /tmp/pgscv.service /etc/systemd/system && \
mv /tmp/pgscv.default /etc/default/pgscv && \
Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Загрузите архив со страницы [releases](https://github.com/cherts/pgscv/releases). Распакуйте архив. Создайте минимальный файл конфигураации. Запустите pgSCV под пользователем postgres.

```bash
curl -s -L https://github.com/cherts/pgscv/releases/download/v0.8.4/pgscv_0.8.4_linux_amd64.tar.gz -o - | tar xzf - -C /tmp && \
curl -s -L https://github.com/cherts/pgscv/releases/download/v0.8.5/pgscv_0.8.5_linux_amd64.tar.gz -o - | tar xzf - -C /tmp && \
mv /tmp/pgscv.yaml /etc && \
mv /tmp/pgscv.service /etc/systemd/system && \
mv /tmp/pgscv.default /etc/default/pgscv && \
Expand Down
12 changes: 8 additions & 4 deletions internal/collector/patroni_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,13 @@ func parsePatroniResponse(resp *apiPatroniResponse) (*patroniInfo, error) {
running = 1
}

t1, err := time.Parse("2006-01-02 15:04:05.999999Z07:00", resp.PmStartTime)
if err != nil {
return nil, fmt.Errorf("parse patroni postmaster_start_time string '%s' failed: %s", resp.PmStartTime, err)
var PmStartTimeSec float64
if resp.PmStartTime != "null" && resp.PmStartTime != "" {
t1, err := time.Parse("2006-01-02 15:04:05.999999Z07:00", resp.PmStartTime)
if err != nil {
return nil, fmt.Errorf("parse patroni postmaster_start_time string '%s' failed: %s", resp.PmStartTime, err)
}
PmStartTimeSec = float64(t1.UnixNano()) / 1000000000
}

var master, stdleader, replica float64
Expand Down Expand Up @@ -523,7 +527,7 @@ func parsePatroniResponse(resp *apiPatroniResponse) (*patroniInfo, error) {
version: float64(version),
versionStr: resp.Patroni.Version,
running: running,
startTime: float64(t1.UnixNano()) / 1000000000,
startTime: PmStartTimeSec,
master: master,
standbyLeader: stdleader,
replica: replica,
Expand Down
2 changes: 1 addition & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func attemptRequest(baseurl string) error {
return err
}

if resp.StatusCode != http.StatusOK {
if (resp.StatusCode != http.StatusOK) && (resp.StatusCode != 503) {
return fmt.Errorf("bad response: %s", resp.Status)
}

Expand Down

0 comments on commit fc5fa02

Please sign in to comment.