Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain committed Oct 29, 2023
1 parent 728ca38 commit 18d13f6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
22 changes: 14 additions & 8 deletions test/e2e/tests/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var MetricTest = suite.ConformanceTest{
if err := ScrapeMetrics(t, suite.Client, types.NamespacedName{
Namespace: "envoy-gateway-system",
Name: "same-namespace-gw-metrics",
}, "/stats/prometheus"); err != nil {
}, 19001, "/stats/prometheus"); err != nil {
t.Logf("failed to get metric: %v", err)
return false, nil
}
Expand Down Expand Up @@ -93,7 +93,7 @@ var MetricTest = suite.ConformanceTest{
if err := ScrapeMetrics(t, suite.Client, types.NamespacedName{
Namespace: "monitoring",
Name: "otel-collecot-prometheus",
}, "/metrics"); err != nil {
}, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
return false, nil
}
Expand All @@ -105,19 +105,25 @@ var MetricTest = suite.ConformanceTest{
},
}

func ScrapeMetrics(t *testing.T, c client.Client, nn types.NamespacedName, path string) error {
func ScrapeMetrics(t *testing.T, c client.Client, nn types.NamespacedName, port int32, path string) error {
svc := corev1.Service{}
if err := c.Get(context.Background(), nn, &svc); err != nil {
return err
}
host := ""
for _, ing := range svc.Status.LoadBalancer.Ingress {
if ing.IP != "" {
host = ing.IP
break
switch svc.Spec.Type {
case corev1.ServiceTypeLoadBalancer:
for _, ing := range svc.Status.LoadBalancer.Ingress {
if ing.IP != "" {
host = ing.IP
break
}
}
default:
host = fmt.Sprintf("%s.%s.svc", nn.Name, nn.Namespace)
}
url := fmt.Sprintf("http://%s:19001%s", host, path)

url := fmt.Sprintf("http://%s:%d%s", host, port, path)
t.Logf("try to request: %s", url)

httpClient := http.Client{
Expand Down
42 changes: 35 additions & 7 deletions test/e2e/tests/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package tests

import (
"context"
corev1 "k8s.io/api/core/v1"

Check failure on line 13 in test/e2e/tests/prometheus.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/envoyproxy/gateway/ (goimports)
"testing"
"time"

Expand All @@ -23,17 +24,44 @@ func init() {
}

var PrometheusTest = suite.ConformanceTest{
ShortName: "Prometheus",
Description: "Make sure Prometheus endpoint is working",
ShortName: "ControlPlane",
Description: "Make sure control plane prometheus endpoint is working",
Manifests: []string{"testdata/prometheus.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
t.Run("MetricExists", func(t *testing.T) {
t.Run("Prometheus", func(t *testing.T) {
nn := types.NamespacedName{Name: "envoy-gateway-lb", Namespace: "envoy-gateway-system"}
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true,
func(_ context.Context) (done bool, err error) {
if err := ScrapeMetrics(t, suite.Client, types.NamespacedName{
Namespace: "envoy-gateway-system",
Name: "envoy-gateway-lb",
}, "/metrics"); err != nil {
svc := corev1.Service{}
if err := suite.Client.Get(context.Background(), nn, &svc); err != nil {
return false, nil
}

host := ""
switch svc.Spec.Type {
case corev1.ServiceTypeLoadBalancer:
for _, ing := range svc.Status.LoadBalancer.Ingress {
if ing.IP != "" {
host = ing.IP
break
}
}
default:
// do nothing
}

if host == "" {
return false, nil
}

return true, nil
}); err != nil {
t.Errorf("failed to get service %s : %v", nn.String(), err)
}

if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Minute, true,
func(_ context.Context) (done bool, err error) {
if err := ScrapeMetrics(t, suite.Client, nn, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
return false, nil
}
Expand Down

0 comments on commit 18d13f6

Please sign in to comment.