mirror of
https://github.com/bloomberg/goldpinger.git
synced 2026-08-28 15:57:18 +00:00
Merge pull request #49 from tylfin/responseTime
Include response time in PodResult
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name ?= goldpinger
|
||||
version ?= 1.2.0
|
||||
version ?= 1.3.0
|
||||
bin ?= goldpinger
|
||||
pkg ?= "github.com/bloomberg/goldpinger"
|
||||
tag = $(name):$(version)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user