Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
fix(e2e): gracefully stop port forwarding to Prometheus/Grafana
Browse files Browse the repository at this point in the history
This change adds the ability to stop the port-forward that happens when
getting a handle to Prometheus or Grafana to support detaching and
reattaching in the middle of a test.

Signed-off-by: Jon Huhn <johuhn@microsoft.com>
  • Loading branch information
nojnhuh committed Dec 10, 2020
1 parent d0cd814 commit 1caafad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/framework/common_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (td *OsmTestData) GetGrafanaPodHandle(ns string, grafanaPodName string, por
Port: port,
User: "admin", // default value of grafana deployment
Password: "admin", // default value of grafana deployment
pfwd: portForwarder,
}, nil
}

Expand Down Expand Up @@ -373,6 +374,7 @@ func (td *OsmTestData) GetPrometheusPodHandle(ns string, prometheusPodName strin
return &Prometheus{
Client: client,
API: v1api,
pfwd: portForwarder,
}, nil
}

Expand Down
16 changes: 16 additions & 0 deletions tests/framework/common_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"

"github.com/openservicemesh/osm/pkg/kubernetes"
)

var (
Expand All @@ -23,6 +25,13 @@ var (
type Prometheus struct {
Client api.Client
API v1.API

pfwd *kubernetes.PortForwarder
}

// Stop gracefully stops the port forwarding to Prometheus
func (p *Prometheus) Stop() {
p.pfwd.Stop()
}

// VectorQuery runs a query at time <t>, expects single vector type and single result.
Expand Down Expand Up @@ -110,6 +119,13 @@ type Grafana struct {
Port uint16
User string
Password string

pfwd *kubernetes.PortForwarder
}

// Stop gracefully stops the port forwarding to Grafana
func (g *Grafana) Stop() {
g.pfwd.Stop()
}

// PanelPNGSnapshot takes a snapshot from a Grafana dashboard or panel
Expand Down

0 comments on commit 1caafad

Please sign in to comment.