8000 fix(api): healthCheck port external service (#3384) · ovh/cds@cf554cc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cf554cc

Browse files
yesnaultsguiheux
authored andcommitted
fix(api): healthCheck port external service (#3384)
1 parent d3eee5e commit cf554cc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

engine/api/services/external.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/go-gorp/gorp"
10+
"github.com/lib/pq"
1011

1112
"github.com/ovh/cds/engine/api/cache"
1213
"github.com/ovh/cds/sdk"
@@ -48,6 +49,10 @@ func ping(db gorp.SqlExecutor, s sdk.ExternalService) error {
4849
var serv service
4950
query := `select * from services where name = $1 for update nowait`
5051
if err := db.SelectOne(&serv, query, s.Name); err != nil {
52+
if pqerr, ok := err.(*pq.Error); ok && pqerr.Code == "55P03" {
53+
log.Debug("services.ping> Unable to lock service %s: %v", s.Name, err)
54+
return nil
55+
}
5156
log.Warning("services.ping> Unable to lock service %s: %v", s.Name, err)
5257
return err
5358
}
@@ -61,7 +66,13 @@ func ping(db gorp.SqlExecutor, s sdk.ExternalService) error {
6166
},
6267
},
6368
}
64-
_, code, err := doRequest(context.Background(), fmt.Sprintf("%s:%s", s.HealthURL, s.HealthPort), "", "GET", s.HealthPath, nil)
69+
var pingURL string
70+
if s.HealthPort == "0" || s.HealthPort == "" {
71+
pingURL = s.HealthURL
72+
} else {
73+
pingURL = fmt.Sprintf("%s:%s", s.HealthURL, s.HealthPort)
74+
}
75+
_, code, err := doRequest(context.Background(), pingURL, "", "GET", s.HealthPath, nil)
6576
if err != nil || code >= 400 {
6677
mon.Lines[0].Status = sdk.MonitoringStatusWarn
6778
mon.Lines[0].Value = "Health: KO"
@@ -108,7 +119,7 @@ func InitExternal(dbFunc func() *gorp.DbMap, store cache.Store, ss []sdk.Externa
108119
}
109120
s.Service.LastHeartbeat = oldSrv.LastHeartbeat
110121
s.Service.MonitoringStatus = oldSrv.MonitoringStatus
111-
s.Service.Config = oldSrv.Config
122+
s.Service.Config = s
112123
if err := Update(tx, &s.Service); err != nil {
113124
_ = tx.Rollback()
114125
return fmt.Errorf("InitExternal> unable to update external service: %v", err)

0 commit comments

Comments
 (0)
0