Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add e2e test for latency metrics in advanced scenario #414

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/e2e/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/microsoft/retina/test/e2e/framework/types"
"github.com/microsoft/retina/test/e2e/scenarios/dns"
"github.com/microsoft/retina/test/e2e/scenarios/drop"
"github.com/microsoft/retina/test/e2e/scenarios/latency"
tcp "github.com/microsoft/retina/test/e2e/scenarios/tcp"
)

Expand Down Expand Up @@ -181,5 +182,7 @@ func UpgradeAndTestRetinaAdvancedMetrics(kubeConfigFilePath, chartPath, valuesFi
job.AddScenario(dns.ValidateAdvancedDNSMetrics(scenario.name, scenario.req, scenario.resp, kubeConfigFilePath))
}

job.AddScenario(latency.ValidateLatencyMetric())

return job
}
18 changes: 17 additions & 1 deletion test/e2e/scenarios/dns/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ func ValidateBasicDNSMetrics(scenarioName string, req *RequestValidationParams,
Duration: sleepDelay,
},
},
{
Step: &kubernetes.ExecInPod{
PodName: podName,
PodNamespace: "kube-system",
Command: req.Command,
},
Opts: &types.StepOptions{
ExpectError: req.ExpectError,
SkipSavingParamatersToJob: true,
},
},
{
Step: &types.Sleep{
Duration: sleepDelay,
},
},
{
Step: &kubernetes.PortForward{
Namespace: "kube-system",
Expand Down Expand Up @@ -167,7 +183,7 @@ func ValidateAdvancedDNSMetrics(scenarioName string, req *RequestValidationParam
},
},
{
Step: &ValidateAdvanceDNSRequestMetrics{
Step: &ValidateAdvancedDNSRequestMetrics{
Namespace: "kube-system",
NumResponse: req.NumResponse,
PodName: podName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
dnsAdvResponseCountMetricName = "networkobservability_adv_dns_response_count"
)

type ValidateAdvanceDNSRequestMetrics struct {
type ValidateAdvancedDNSRequestMetrics struct {
Namespace string
NumResponse string
PodName string
Expand All @@ -29,15 +29,15 @@ type ValidateAdvanceDNSRequestMetrics struct {
KubeConfigFilePath string
}

func (v *ValidateAdvanceDNSRequestMetrics) Run() error {
func (v *ValidateAdvancedDNSRequestMetrics) Run() error {
metricsEndpoint := fmt.Sprintf("http://localhost:%d/metrics", common.RetinaPort)
// Get Pod IP address
podIP, err := kubernetes.GetPodIP(v.KubeConfigFilePath, v.Namespace, v.PodName)
if err != nil {
return errors.Wrapf(err, "failed to get pod IP address")
}

validateAdvanceDNSRequestMetrics := map[string]string{
validateAdvancedDNSRequestMetrics := map[string]string{
"ip": podIP,
"namespace": v.Namespace,
"num_response": v.NumResponse,
Expand All @@ -50,7 +50,7 @@ func (v *ValidateAdvanceDNSRequestMetrics) Run() error {
"workload_name": v.WorkloadName,
}

err = prom.CheckMetric(metricsEndpoint, dnsAdvRequestCountMetricName, validateAdvanceDNSRequestMetrics)
err = prom.CheckMetric(metricsEndpoint, dnsAdvRequestCountMetricName, validateAdvancedDNSRequestMetrics)
if err != nil {
return errors.Wrapf(err, "failed to verify advance dns request metrics %s", dnsAdvRequestCountMetricName)
}
Expand All @@ -59,11 +59,11 @@ func (v *ValidateAdvanceDNSRequestMetrics) Run() error {
return nil
}

func (v *ValidateAdvanceDNSRequestMetrics) Prevalidate() error {
func (v *ValidateAdvancedDNSRequestMetrics) Prevalidate() error {
return nil
}

func (v *ValidateAdvanceDNSRequestMetrics) Stop() error {
func (v *ValidateAdvancedDNSRequestMetrics) Stop() error {
return nil
}

Expand Down
47 changes: 47 additions & 0 deletions test/e2e/scenarios/latency/scenario.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package latency

import (
"time"

"github.com/microsoft/retina/test/e2e/framework/kubernetes"
"github.com/microsoft/retina/test/e2e/framework/types"
)

const sleepDelay = 5 * time.Second

func ValidateLatencyMetric() *types.Scenario {
name := "Latency Metrics"
steps := []*types.StepWrapper{
{
Step: &types.Sleep{
Duration: sleepDelay,
},
},
nddq marked this conversation as resolved.
Show resolved Hide resolved
{
Step: &kubernetes.PortForward{
Namespace: "kube-system",
LabelSelector: "k8s-app=retina",
LocalPort: "10093",
RemotePort: "10093",
Endpoint: "metrics",
OptionalLabelAffinity: "k8s-app=retina",
},
Opts: &types.StepOptions{
SkipSavingParamatersToJob: true,
RunInBackgroundWithID: "latency-port-forward",
},
},
{
Step: &ValidateAPIServerLatencyMetric{},
Opts: &types.StepOptions{
SkipSavingParamatersToJob: true,
},
},
{
Step: &types.Stop{
BackgroundID: "latency-port-forward",
},
},
}
return types.NewScenario(name, steps...)
}
35 changes: 35 additions & 0 deletions test/e2e/scenarios/latency/validate-latency-metric.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package latency

import (
"fmt"
"log"

"github.com/microsoft/retina/test/e2e/common"
prom "github.com/microsoft/retina/test/e2e/framework/prometheus"
"github.com/pkg/errors"
)

var latencyBucketMetricName = "networkobservability_adv_node_apiserver_tcp_handshake_latency"

type ValidateAPIServerLatencyMetric struct{}

func (v *ValidateAPIServerLatencyMetric) Prevalidate() error {
return nil
}

func (v *ValidateAPIServerLatencyMetric) Run() error {
promAddress := fmt.Sprintf("http://localhost:%d/metrics", common.RetinaPort)

metric := map[string]string{}
err := prom.CheckMetric(promAddress, latencyBucketMetricName, metric)
if err != nil {
return errors.Wrapf(err, "failed to verify latency metrics %s", latencyBucketMetricName)
}

log.Printf("found metrics matching %s\n", latencyBucketMetricName)
return nil
}

func (v *ValidateAPIServerLatencyMetric) Stop() error {
return nil
}
Loading