diff --git a/Makefile b/Makefile index c6a64ea..cd48870 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ name ?= goldpinger -version ?= 1.2.0 +version ?= 1.3.0 bin ?= goldpinger pkg ?= "github.com/bloomberg/goldpinger" tag = $(name):$(version) diff --git a/pkg/client/operations/check_all_pods_parameters.go b/pkg/client/operations/check_all_pods_parameters.go index a103447..92e99c9 100644 --- a/pkg/client/operations/check_all_pods_parameters.go +++ b/pkg/client/operations/check_all_pods_parameters.go @@ -6,11 +6,10 @@ package operations // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/pkg/client/operations/check_service_pods_parameters.go b/pkg/client/operations/check_service_pods_parameters.go index 63f1ea6..007ba8c 100644 --- a/pkg/client/operations/check_service_pods_parameters.go +++ b/pkg/client/operations/check_service_pods_parameters.go @@ -6,11 +6,10 @@ package operations // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/pkg/client/operations/healthz_parameters.go b/pkg/client/operations/healthz_parameters.go index 8acc7e7..f0cfde7 100644 --- a/pkg/client/operations/healthz_parameters.go +++ b/pkg/client/operations/healthz_parameters.go @@ -6,11 +6,10 @@ package operations // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/pkg/client/operations/ping_parameters.go b/pkg/client/operations/ping_parameters.go index 608ad46..2e93062 100644 --- a/pkg/client/operations/ping_parameters.go +++ b/pkg/client/operations/ping_parameters.go @@ -6,11 +6,10 @@ package operations // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "net/http" "time" - "golang.org/x/net/context" - "github.com/go-openapi/errors" "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" diff --git a/pkg/goldpinger/client.go b/pkg/goldpinger/client.go index 46cf20b..924f679 100644 --- a/pkg/goldpinger/client.go +++ b/pkg/goldpinger/client.go @@ -65,12 +65,14 @@ func PingAllPods(pods map[string]string) models.CheckResults { CountCall("made", "ping") timer := GetLabeledPeersCallsTimer("ping", hostIP, podIP) + start := time.Now() resp, err := getClient(pickPodHostIP(podIP, hostIP)).Operations.Ping(nil) channelResult.hostIPv4.UnmarshalText([]byte(hostIP)) var OK = (err == nil) if OK { - channelResult.podResult = models.PodResult{HostIP: channelResult.hostIPv4, OK: &OK, Response: resp.Payload, StatusCode: 200} + responseTime := time.Since(start).Nanoseconds() / int64(time.Millisecond) + channelResult.podResult = models.PodResult{HostIP: channelResult.hostIPv4, OK: &OK, Response: resp.Payload, StatusCode: 200, ResponseTimeMs: responseTime} timer.ObserveDuration() } else { channelResult.podResult = models.PodResult{HostIP: channelResult.hostIPv4, OK: &OK, Error: err.Error(), StatusCode: 500} @@ -167,8 +169,8 @@ func HealthCheck() *models.HealthCheckResults { ok := true start := time.Now() result := models.HealthCheckResults{ - OK: &ok, - DurationNs: time.Since(start).Nanoseconds(), + OK: &ok, + DurationNs: time.Since(start).Nanoseconds(), GeneratedAt: strfmt.DateTime(start), } return &result diff --git a/pkg/models/pod_result.go b/pkg/models/pod_result.go index 8137118..7d33ea2 100644 --- a/pkg/models/pod_result.go +++ b/pkg/models/pod_result.go @@ -30,6 +30,9 @@ type PodResult struct { // response Response *PingResults `json:"response,omitempty"` + // wall clock time in milliseconds + ResponseTimeMs int64 `json:"response-time-ms,omitempty"` + // status code StatusCode int32 `json:"status-code,omitempty"` } diff --git a/pkg/restapi/embedded_spec.go b/pkg/restapi/embedded_spec.go index ccc2c87..d7ec1c7 100644 --- a/pkg/restapi/embedded_spec.go +++ b/pkg/restapi/embedded_spec.go @@ -227,6 +227,11 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, + "response-time-ms": { + "description": "wall clock time in milliseconds", + "type": "number", + "format": "int64" + }, "status-code": { "type": "integer", "format": "int32" @@ -445,6 +450,11 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, + "response-time-ms": { + "description": "wall clock time in milliseconds", + "type": "number", + "format": "int64" + }, "status-code": { "type": "integer", "format": "int32" diff --git a/pkg/restapi/operations/check_all_pods_urlbuilder.go b/pkg/restapi/operations/check_all_pods_urlbuilder.go index cf7e056..f196da4 100644 --- a/pkg/restapi/operations/check_all_pods_urlbuilder.go +++ b/pkg/restapi/operations/check_all_pods_urlbuilder.go @@ -33,14 +33,14 @@ func (o *CheckAllPodsURL) SetBasePath(bp string) { // Build a url path and query string func (o *CheckAllPodsURL) Build() (*url.URL, error) { - var result url.URL + var _result url.URL var _path = "/check_all" _basePath := o._basePath - result.Path = golangswaggerpaths.Join(_basePath, _path) + _result.Path = golangswaggerpaths.Join(_basePath, _path) - return &result, nil + return &_result, nil } // Must is a helper function to panic when the url builder returns an error diff --git a/pkg/restapi/operations/check_service_pods_responses.go b/pkg/restapi/operations/check_service_pods_responses.go index cd9bd39..b4497c4 100644 --- a/pkg/restapi/operations/check_service_pods_responses.go +++ b/pkg/restapi/operations/check_service_pods_responses.go @@ -50,8 +50,12 @@ func (o *CheckServicePodsOK) WriteResponse(rw http.ResponseWriter, producer runt rw.WriteHeader(200) payload := o.Payload + if payload == nil { + // return empty map + payload = models.CheckResults{} + } + if err := producer.Produce(rw, payload); err != nil { panic(err) // let the recovery middleware deal with this } - } diff --git a/pkg/restapi/operations/check_service_pods_urlbuilder.go b/pkg/restapi/operations/check_service_pods_urlbuilder.go index 2206d95..9f61ad4 100644 --- a/pkg/restapi/operations/check_service_pods_urlbuilder.go +++ b/pkg/restapi/operations/check_service_pods_urlbuilder.go @@ -33,14 +33,14 @@ func (o *CheckServicePodsURL) SetBasePath(bp string) { // Build a url path and query string func (o *CheckServicePodsURL) Build() (*url.URL, error) { - var result url.URL + var _result url.URL var _path = "/check" _basePath := o._basePath - result.Path = golangswaggerpaths.Join(_basePath, _path) + _result.Path = golangswaggerpaths.Join(_basePath, _path) - return &result, nil + return &_result, nil } // Must is a helper function to panic when the url builder returns an error diff --git a/pkg/restapi/operations/healthz_urlbuilder.go b/pkg/restapi/operations/healthz_urlbuilder.go index 569c379..2c362fd 100644 --- a/pkg/restapi/operations/healthz_urlbuilder.go +++ b/pkg/restapi/operations/healthz_urlbuilder.go @@ -33,14 +33,14 @@ func (o *HealthzURL) SetBasePath(bp string) { // Build a url path and query string func (o *HealthzURL) Build() (*url.URL, error) { - var result url.URL + var _result url.URL var _path = "/healthz" _basePath := o._basePath - result.Path = golangswaggerpaths.Join(_basePath, _path) + _result.Path = golangswaggerpaths.Join(_basePath, _path) - return &result, nil + return &_result, nil } // Must is a helper function to panic when the url builder returns an error diff --git a/pkg/restapi/operations/ping_urlbuilder.go b/pkg/restapi/operations/ping_urlbuilder.go index 75c17fd..0a77aa2 100644 --- a/pkg/restapi/operations/ping_urlbuilder.go +++ b/pkg/restapi/operations/ping_urlbuilder.go @@ -33,14 +33,14 @@ func (o *PingURL) SetBasePath(bp string) { // Build a url path and query string func (o *PingURL) Build() (*url.URL, error) { - var result url.URL + var _result url.URL var _path = "/ping" _basePath := o._basePath - result.Path = golangswaggerpaths.Join(_basePath, _path) + _result.Path = golangswaggerpaths.Join(_basePath, _path) - return &result, nil + return &_result, nil } // Must is a helper function to panic when the url builder returns an error diff --git a/pkg/restapi/server.go b/pkg/restapi/server.go index abd6668..465426b 100644 --- a/pkg/restapi/server.go +++ b/pkg/restapi/server.go @@ -187,6 +187,7 @@ func (s *Server) Serve() (err error) { configureServer(domainSocket, "unix", string(s.SocketPath)) + servers = append(servers, domainSocket) wg.Add(1) s.Logf("Serving goldpinger at unix://%s", s.SocketPath) go func(l net.Listener) { @@ -196,7 +197,6 @@ func (s *Server) Serve() (err error) { } s.Logf("Stopped serving goldpinger at unix://%s", s.SocketPath) }(s.domainSocketL) - servers = append(servers, domainSocket) } if s.hasScheme(schemeHTTP) { @@ -217,6 +217,7 @@ func (s *Server) Serve() (err error) { configureServer(httpServer, "http", s.httpServerL.Addr().String()) + servers = append(servers, httpServer) wg.Add(1) s.Logf("Serving goldpinger at http://%s", s.httpServerL.Addr()) go func(l net.Listener) { @@ -226,7 +227,6 @@ func (s *Server) Serve() (err error) { } s.Logf("Stopped serving goldpinger at http://%s", l.Addr()) }(s.httpServerL) - servers = append(servers, httpServer) } if s.hasScheme(schemeHTTPS) { @@ -313,6 +313,7 @@ func (s *Server) Serve() (err error) { configureServer(httpsServer, "https", s.httpsServerL.Addr().String()) + servers = append(servers, httpsServer) wg.Add(1) s.Logf("Serving goldpinger at https://%s", s.httpsServerL.Addr()) go func(l net.Listener) { @@ -322,7 +323,6 @@ func (s *Server) Serve() (err error) { } s.Logf("Stopped serving goldpinger at https://%s", l.Addr()) }(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig)) - servers = append(servers, httpsServer) } wg.Wait() diff --git a/swagger.yml b/swagger.yml index 6a957b0..ff31d4e 100644 --- a/swagger.yml +++ b/swagger.yml @@ -36,6 +36,10 @@ definitions: status-code: type: integer format: int32 + response-time-ms: + type: number + format: int64 + description: wall clock time in milliseconds CheckResults: type: object additionalProperties: