From 871b86471d670e60c056425ab11f9bc722555361 Mon Sep 17 00:00:00 2001 From: tfinethy Date: Fri, 15 Feb 2019 11:13:03 -0500 Subject: [PATCH] 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: