-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathmetrics_test.go
64 lines (52 loc) · 1.66 KB
/
metrics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package proxy_test
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/metrics/metricstest"
"github.com/zalando/skipper/proxy"
"github.com/zalando/skipper/proxy/proxytest"
"github.com/zalando/skipper/routing"
"github.com/zalando/skipper/routing/testdataclient"
)
func TestMetricsUncompressed(t *testing.T) {
m := &metricstest.MockMetrics{}
// will update routes after proxy address is known
dc := testdataclient.New(nil)
defer dc.Close()
p := proxytest.Config{
RoutingOptions: routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dc},
},
ProxyParams: proxy.Params{
Metrics: m,
},
}.Create()
defer p.Close()
err := dc.UpdateDoc(fmt.Sprintf(`
test: Path("/test") -> setPath("/backend") -> "%s";
backend: Path("/backend") && Header("Accept-Encoding", "gzip") -> compress() -> inlineContent("backend response") -> <shunt>;
`, p.URL), nil)
require.NoError(t, err)
// wait for route update
time.Sleep(10 * time.Millisecond)
client := p.Client()
client.Transport.(*http.Transport).DisableCompression = true
const N = 10
for i := 0; i < N; i++ {
rsp, body, err := client.GetBody(p.URL + "/test")
require.NoError(t, err)
require.Equal(t, 200, rsp.StatusCode)
require.Equal(t, []byte("backend response"), body)
}
m.WithCounters(func(counters map[string]int64) {
assert.Equal(t, counters["incoming.HTTP/1.1"], int64(2*N))
assert.Equal(t, counters["outgoing.HTTP/1.1"], int64(N))
assert.Equal(t, counters["experimental.uncompressed"], int64(N))
})
}