Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
e2e: Remove the code to initialise prom client
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
  • Loading branch information
surajssd committed Mar 19, 2020
1 parent 9a3b1b7 commit 165004e
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions test/monitoring/control-plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ import (
"testing"
"time"

testutil "github.com/kinvolk/lokomotive/test/components/util"

"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
)

// nolint:funlen
func TestPrometheusMetrics(t *testing.T) {
func testControlPlanePrometheusMetrics(t *testing.T, v1api v1.API) {
testCases := []struct {
componentName string
query string
Expand Down Expand Up @@ -66,39 +62,20 @@ func TestPrometheusMetrics(t *testing.T) {
},
}

const prometheusPodPort = 9090

p := &testutil.PortForwardInfo{
PodName: "prometheus-prometheus-operator-prometheus-0",
Namespace: "monitoring",
PodPort: prometheusPodPort,
}

p.PortForward(t)
defer p.CloseChan()
p.WaitUntilForwardingAvailable(t)

promClient, err := api.NewClient(api.Config{
Address: fmt.Sprintf("http://127.0.0.1:%d", p.LocalPort),
})
if err != nil {
t.Fatalf("Error creating client: %v", err)
}

for _, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("prometheus-%s", tc.componentName), func(t *testing.T) {
t.Logf("querying %q", tc.query)

v1api := v1.NewAPI(promClient)
const contextTimeout = 10

ctx, cancel := context.WithTimeout(context.Background(), contextTimeout*time.Second)
defer cancel()

results, warnings, err := v1api.Query(ctx, tc.query, time.Now())
if err != nil {
t.Fatalf("error querying Prometheus: %v", err)
t.Errorf("error querying Prometheus: %v", err)
return
}

if len(warnings) > 0 {
Expand Down

0 comments on commit 165004e

Please sign in to comment.