/
prometheus.go
62 lines (53 loc) · 1.77 KB
/
prometheus.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
package suites
import (
"context"
"fmt"
"github.com/Azure/aks-app-routing-operator/testing/e2e/infra"
"github.com/Azure/aks-app-routing-operator/testing/e2e/logger"
"github.com/Azure/aks-app-routing-operator/testing/e2e/manifests"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var (
promNs = manifests.UncollisionedNs()
)
func promSuite(in infra.Provisioned) []test {
return []test{
{
name: "ingress prometheus metrics",
cfgs: builderFromInfra(in).
withOsm(in, false, true).
withVersions(manifests.AllOperatorVersions...).
withZones(manifests.AllDnsZoneCounts, manifests.AllDnsZoneCounts).
build(),
run: func(ctx context.Context, config *rest.Config, operator manifests.OperatorConfig) error {
lgr := logger.FromContext(ctx)
lgr.Info("starting test")
c, err := client.New(config, client.Options{})
if err != nil {
return fmt.Errorf("creating client: %w")
}
lgr.Info("creating namespace")
if err := upsert(ctx, c, promNs); err != nil {
return fmt.Errorf("creating namespace: %w", err)
}
lgr = lgr.With("namespace", promNs.Name)
ctx = logger.WithContext(ctx, lgr)
resources := manifests.PrometheusClientAndServer(promNs.Name, "prometheus")
for _, object := range resources.Objects() {
if err := upsert(ctx, c, object); err != nil {
return fmt.Errorf("upserting resource: %w", err)
}
}
lgr = lgr.With("client", resources.Client.Name)
ctx = logger.WithContext(ctx, lgr)
lgr.Info("waiting for prometheus client to be ready")
if err := waitForAvailable(ctx, c, *resources.Client); err != nil {
return fmt.Errorf("waiting for prometheus client to be ready: %w", err)
}
lgr.Info("finished testing prometheus")
return nil
},
},
}
}