mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 09:24:04 +01:00
feat(core): do not include DNS query time in HTTP response time
Fix #49
This commit is contained in:
parent
a725e7e770
commit
bfe25f71e9
@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptrace"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -310,10 +311,10 @@ func (endpoint *Endpoint) call(result *Result) {
|
|||||||
var err error
|
var err error
|
||||||
var certificate *x509.Certificate
|
var certificate *x509.Certificate
|
||||||
endpointType := endpoint.Type()
|
endpointType := endpoint.Type()
|
||||||
if endpointType == EndpointTypeHTTP {
|
|
||||||
request = endpoint.buildHTTPRequest()
|
|
||||||
}
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
if endpointType == EndpointTypeHTTP {
|
||||||
|
request = endpoint.buildHTTPRequest(&startTime)
|
||||||
|
}
|
||||||
if endpointType == EndpointTypeDNS {
|
if endpointType == EndpointTypeDNS {
|
||||||
endpoint.DNS.query(endpoint.URL, result)
|
endpoint.DNS.query(endpoint.URL, result)
|
||||||
result.Duration = time.Since(startTime)
|
result.Duration = time.Since(startTime)
|
||||||
@ -364,7 +365,7 @@ func (endpoint *Endpoint) call(result *Result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *Endpoint) buildHTTPRequest() *http.Request {
|
func (endpoint *Endpoint) buildHTTPRequest(startTime *time.Time) *http.Request {
|
||||||
var bodyBuffer *bytes.Buffer
|
var bodyBuffer *bytes.Buffer
|
||||||
if endpoint.GraphQL {
|
if endpoint.GraphQL {
|
||||||
graphQlBody := map[string]string{
|
graphQlBody := map[string]string{
|
||||||
@ -382,6 +383,13 @@ func (endpoint *Endpoint) buildHTTPRequest() *http.Request {
|
|||||||
request.Host = v
|
request.Host = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clientTrace := &httptrace.ClientTrace{
|
||||||
|
DNSDone: func(info httptrace.DNSDoneInfo) {
|
||||||
|
*startTime = time.Now()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
clientTraceCtx := httptrace.WithClientTrace(request.Context(), clientTrace)
|
||||||
|
request = request.WithContext(clientTraceCtx)
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user