From 871b86471d670e60c056425ab11f9bc722555361 Mon Sep 17 00:00:00 2001 From: tfinethy Date: Fri, 15 Feb 2019 11:13:03 -0500 Subject: [PATCH 1/5] Include response time in PodResult Signed-off-by: tfinethy Remove all swagger updates Change response-time to match status-code formatting Switch to float64 and use milliseconds as the unit --- pkg/goldpinger/client.go | 8 +++++--- pkg/models/pod_result.go | 3 +++ pkg/restapi/embedded_spec.go | 8 ++++++++ swagger.yml | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/goldpinger/client.go b/pkg/goldpinger/client.go index 46cf20b..2c9e119 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 := float64(time.Since(start).Nanoseconds()) / float64(int64(time.Millisecond)) + channelResult.podResult = models.PodResult{HostIP: channelResult.hostIPv4, OK: &OK, Response: resp.Payload, StatusCode: 200, ResponseTime: 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..aa3ab2b 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"` + // response time + ResponseTime float64 `json:"response-time,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..c8ad34d 100644 --- a/pkg/restapi/embedded_spec.go +++ b/pkg/restapi/embedded_spec.go @@ -227,6 +227,10 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, + "response-time": { + "type": "number", + "format": "float64" + }, "status-code": { "type": "integer", "format": "int32" @@ -445,6 +449,10 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, + "response-time": { + "type": "number", + "format": "float64" + }, "status-code": { "type": "integer", "format": "int32" diff --git a/swagger.yml b/swagger.yml index 6a957b0..cc30866 100644 --- a/swagger.yml +++ b/swagger.yml @@ -36,6 +36,9 @@ definitions: status-code: type: integer format: int32 + response-time: + type: number + format: float64 CheckResults: type: object additionalProperties: From 2bcff8b2d1ea775d7a9476a73d662eb2a6873792 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Wed, 20 Feb 2019 16:41:15 +0000 Subject: [PATCH 2/5] make the response time field explicit in its usage of milliseconds Signed-off-by: Mikolaj Pawlikowski --- swagger.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/swagger.yml b/swagger.yml index cc30866..ff31d4e 100644 --- a/swagger.yml +++ b/swagger.yml @@ -36,9 +36,10 @@ definitions: status-code: type: integer format: int32 - response-time: + response-time-ms: type: number - format: float64 + format: int64 + description: wall clock time in milliseconds CheckResults: type: object additionalProperties: From 15b45986062a22252edf179e5dc29ebd5d426ce6 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Wed, 20 Feb 2019 16:43:42 +0000 Subject: [PATCH 3/5] make swagger to update the response-time-ms field Signed-off-by: Mikolaj Pawlikowski --- pkg/goldpinger/client.go | 4 ++-- pkg/models/pod_result.go | 4 ++-- pkg/restapi/embedded_spec.go | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/goldpinger/client.go b/pkg/goldpinger/client.go index 2c9e119..924f679 100644 --- a/pkg/goldpinger/client.go +++ b/pkg/goldpinger/client.go @@ -71,8 +71,8 @@ func PingAllPods(pods map[string]string) models.CheckResults { channelResult.hostIPv4.UnmarshalText([]byte(hostIP)) var OK = (err == nil) if OK { - responseTime := float64(time.Since(start).Nanoseconds()) / float64(int64(time.Millisecond)) - channelResult.podResult = models.PodResult{HostIP: channelResult.hostIPv4, OK: &OK, Response: resp.Payload, StatusCode: 200, ResponseTime: responseTime} + 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} diff --git a/pkg/models/pod_result.go b/pkg/models/pod_result.go index aa3ab2b..7d33ea2 100644 --- a/pkg/models/pod_result.go +++ b/pkg/models/pod_result.go @@ -30,8 +30,8 @@ type PodResult struct { // response Response *PingResults `json:"response,omitempty"` - // response time - ResponseTime float64 `json:"response-time,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 c8ad34d..d7ec1c7 100644 --- a/pkg/restapi/embedded_spec.go +++ b/pkg/restapi/embedded_spec.go @@ -227,9 +227,10 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, - "response-time": { + "response-time-ms": { + "description": "wall clock time in milliseconds", "type": "number", - "format": "float64" + "format": "int64" }, "status-code": { "type": "integer", @@ -449,9 +450,10 @@ func init() { "response": { "$ref": "#/definitions/PingResults" }, - "response-time": { + "response-time-ms": { + "description": "wall clock time in milliseconds", "type": "number", - "format": "float64" + "format": "int64" }, "status-code": { "type": "integer", From 513d8ee489297c8dfae6d09dead983c3e37d781d Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Wed, 20 Feb 2019 16:44:25 +0000 Subject: [PATCH 4/5] newer go-swagger has some fancier templates Signed-off-by: Mikolaj Pawlikowski --- pkg/client/operations/check_all_pods_parameters.go | 3 +-- pkg/client/operations/check_service_pods_parameters.go | 3 +-- pkg/client/operations/healthz_parameters.go | 3 +-- pkg/client/operations/ping_parameters.go | 3 +-- pkg/restapi/operations/check_all_pods_urlbuilder.go | 6 +++--- pkg/restapi/operations/check_service_pods_responses.go | 6 +++++- pkg/restapi/operations/check_service_pods_urlbuilder.go | 6 +++--- pkg/restapi/operations/healthz_urlbuilder.go | 6 +++--- pkg/restapi/operations/ping_urlbuilder.go | 6 +++--- pkg/restapi/server.go | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) 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/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() From 06565c4ba85dffebe2086cafb354ed6b7a37cea3 Mon Sep 17 00:00:00 2001 From: Mikolaj Pawlikowski Date: Wed, 20 Feb 2019 16:49:06 +0000 Subject: [PATCH 5/5] minor version bump Signed-off-by: Mikolaj Pawlikowski --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)