-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtenants_test.go
More file actions
87 lines (71 loc) · 2.65 KB
/
tenants_test.go
File metadata and controls
87 lines (71 loc) · 2.65 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//go:build integration
package e2e
import (
"testing"
e2emon "github.com/efficientgo/e2e/monitoring"
"github.com/efficientgo/core/testutil"
"github.com/efficientgo/e2e"
"github.com/efficientgo/e2e/monitoring/matchers"
)
func TestTenantsRetryAuthenticationProviderRegistration(t *testing.T) {
t.Parallel()
e, err := e2e.New(e2e.WithName(uniqueE2ENetworkName(t)))
testutil.Ok(t, err)
t.Cleanup(e.Close)
prepareConfigsAndCerts(t, e)
dex, _, _ := startBaseServices(t, e)
readEndpoint, writeEndpoint, _ := startServicesForMetrics(t, e)
// Start API with stopped Dex and observe retries.
dex.Stop()
api, err := newObservatoriumAPIService(
e,
withMetricsEndpoints("http://"+readEndpoint, "http://"+writeEndpoint),
)
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(api))
t.Run("tenants-authenticator-provider-retry", func(t *testing.T) {
// Check that retries metric increases eventually.
// This is with the new authenticators setup.
testutil.Ok(t, api.WaitSumMetricsWithOptions(
e2emon.Greater(0),
[]string{"observatorium_api_tenants_failed_registrations_total"},
e2emon.WaitMissingMetrics(),
e2emon.WithLabelMatchers(
matchers.MustNewMatcher(matchers.MatchEqual, "tenant", defaultTenantName),
matchers.MustNewMatcher(matchers.MatchEqual, "provider", "oidc"),
),
))
// Test a tenant with legacy configuration setup.
testutil.Ok(t, api.WaitSumMetricsWithOptions(
e2emon.Greater(0),
[]string{"observatorium_api_tenants_failed_registrations_total"},
e2emon.WaitMissingMetrics(),
e2emon.WithLabelMatchers(
matchers.MustNewMatcher(matchers.MatchEqual, "tenant", "test-attacker"),
matchers.MustNewMatcher(matchers.MatchEqual, "provider", "oidc"),
),
))
// Restart Dex.
testutil.Ok(t, e2e.StartAndWaitReady(dex))
token, err := obtainToken(dex.Endpoint("https"), getContainerName(e, "dex"), getTLSClientConfig(t, e))
testutil.Ok(t, err)
up, err := newUpRun(
e, "up-tenants", metrics,
"https://"+api.InternalEndpoint("https")+"/api/metrics/v1/"+defaultTenantName+"/api/v1/query",
"https://"+api.InternalEndpoint("https")+"/api/metrics/v1/"+defaultTenantName+"/api/v1/receive",
withToken(token),
withRunParameters(&runParams{initialDelay: "100ms", period: "300ms", threshold: "1", latency: "5s", duration: "0"}),
)
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(up))
// Check that we successfully hit API after re-registration.
testutil.Ok(t, api.WaitSumMetricsWithOptions(
e2emon.Greater(0),
[]string{"http_requests_total"},
e2emon.WaitMissingMetrics(),
e2emon.WithLabelMatchers(
matchers.MustNewMatcher(matchers.MatchEqual, "code", "200"),
),
))
})
}