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 8d708e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion test/e2e/testdata/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ spec:
port: 19001
protocol: TCP
targetPort: 19001
type: LoadBalancer
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 "LoadBalancer":
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
2 changes: 1 addition & 1 deletion test/e2e/tests/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var PrometheusTest = suite.ConformanceTest{
if err := ScrapeMetrics(t, suite.Client, types.NamespacedName{
Namespace: "envoy-gateway-system",
Name: "envoy-gateway-lb",
}, "/metrics"); err != nil {
}, 19001, "/metrics"); err != nil {
t.Logf("failed to get metric: %v", err)
return false, nil
}
Expand Down

0 comments on commit 8d708e8

Please sign in to comment.