mirror of
https://github.com/tailscale/tailscale.git
synced 2025-09-21 13:41:46 +02:00
prober: include current probe results in run-probe text response
It was a bit confusing that provided history did not include the current probe results. Updates tailscale/corp#20583 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
parent
a29545e9cc
commit
ed6aa50bd5
@ -570,9 +570,9 @@ func (p *Prober) RunHandler(w http.ResponseWriter, r *http.Request) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stats := fmt.Sprintf("Last %d probes: success rate %d%%, median latency %v\n",
|
stats := fmt.Sprintf("Last %d probes (including this one): success rate %d%%, median latency %v\n",
|
||||||
len(prevInfo.RecentResults),
|
len(info.RecentResults),
|
||||||
int(prevInfo.RecentSuccessRatio()*100), prevInfo.RecentMedianLatency())
|
int(info.RecentSuccessRatio()*100), info.RecentMedianLatency())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tsweb.Error(respStatus, fmt.Sprintf("Probe failed: %s\n%s", err.Error(), stats), err)
|
return tsweb.Error(respStatus, fmt.Sprintf("Probe failed: %s\n%s", err.Error(), stats), err)
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -546,7 +547,7 @@ func TestProberRunHandler(t *testing.T) {
|
|||||||
probeFunc func(context.Context) error
|
probeFunc func(context.Context) error
|
||||||
wantResponseCode int
|
wantResponseCode int
|
||||||
wantJSONResponse RunHandlerResponse
|
wantJSONResponse RunHandlerResponse
|
||||||
wantPlaintextResponse string
|
wantPlaintextResponse *regexp.Regexp
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "success",
|
name: "success",
|
||||||
@ -561,7 +562,7 @@ func TestProberRunHandler(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PreviousSuccessRatio: 1,
|
PreviousSuccessRatio: 1,
|
||||||
},
|
},
|
||||||
wantPlaintextResponse: "Probe succeeded",
|
wantPlaintextResponse: regexp.MustCompile("(?s)Probe succeeded .*Last 2 probes.*success rate 100%"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "failure",
|
name: "failure",
|
||||||
@ -576,7 +577,7 @@ func TestProberRunHandler(t *testing.T) {
|
|||||||
RecentResults: []bool{false, false},
|
RecentResults: []bool{false, false},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantPlaintextResponse: "Probe failed",
|
wantPlaintextResponse: regexp.MustCompile("(?s)Probe failed: .*Last 2 probes.*success rate 0%"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,6 +608,7 @@ func TestProberRunHandler(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to make request: %v", err)
|
t.Fatalf("failed to make request: %v", err)
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != tt.wantResponseCode {
|
if resp.StatusCode != tt.wantResponseCode {
|
||||||
t.Errorf("unexpected response code: got %d, want %d", resp.StatusCode, tt.wantResponseCode)
|
t.Errorf("unexpected response code: got %d, want %d", resp.StatusCode, tt.wantResponseCode)
|
||||||
@ -630,8 +632,8 @@ func TestProberRunHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
if !strings.Contains(string(body), tt.wantPlaintextResponse) {
|
if !tt.wantPlaintextResponse.MatchString(string(body)) {
|
||||||
t.Errorf("unexpected response body: got %q, want to contain %q", body, tt.wantPlaintextResponse)
|
t.Errorf("unexpected response body: got %q, want to match %q", body, tt.wantPlaintextResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user