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: add DNS basic and advance metrics e2e #353

Merged
merged 24 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion pkg/module/metrics/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetLabels(t *testing.T) {
},
{
name: "local context",
want: append(utils.DNSLabels, "ip", "namespace", "podname", "workloadKind", "workloadName", "service", "port"),
want: append(utils.DNSLabels, "ip", "namespace", "podname", "workload_kind", "workload_name", "service", "port"),
d: &DNSMetrics{
baseMetricObject: baseMetricObject{
srcCtx: &ContextOptions{
Expand Down
28 changes: 14 additions & 14 deletions pkg/module/metrics/drops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestNewDrop(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -129,8 +129,8 @@ func TestNewDrop(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand All @@ -153,8 +153,8 @@ func TestNewDrop(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -177,8 +177,8 @@ func TestNewDrop(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -202,8 +202,8 @@ func TestNewDrop(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand All @@ -228,8 +228,8 @@ func TestNewDrop(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand All @@ -255,8 +255,8 @@ func TestNewDrop(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand Down
32 changes: 16 additions & 16 deletions pkg/module/metrics/forward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func TestNewForward(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -125,8 +125,8 @@ func TestNewForward(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand All @@ -148,8 +148,8 @@ func TestNewForward(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -172,8 +172,8 @@ func TestNewForward(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -195,8 +195,8 @@ func TestNewForward(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -218,8 +218,8 @@ func TestNewForward(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand All @@ -242,8 +242,8 @@ func TestNewForward(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand All @@ -267,8 +267,8 @@ func TestNewForward(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand Down
48 changes: 24 additions & 24 deletions pkg/module/metrics/tcpflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func TestNewTCPMetrics(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand All @@ -99,8 +99,8 @@ func TestNewTCPMetrics(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand All @@ -122,8 +122,8 @@ func TestNewTCPMetrics(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand Down Expand Up @@ -154,8 +154,8 @@ func TestNewTCPMetrics(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand Down Expand Up @@ -184,8 +184,8 @@ func TestNewTCPMetrics(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand Down Expand Up @@ -222,8 +222,8 @@ func TestNewTCPMetrics(t *testing.T) {
"source_ip",
"source_namespace",
"source_podname",
"source_workloadKind",
"source_workloadName",
"source_workload_kind",
"source_workload_name",
"source_service",
"source_port",
},
Expand Down Expand Up @@ -261,8 +261,8 @@ func TestNewTCPMetrics(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand Down Expand Up @@ -299,8 +299,8 @@ func TestNewTCPMetrics(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand Down Expand Up @@ -338,8 +338,8 @@ func TestNewTCPMetrics(t *testing.T) {
"destination_ip",
"destination_namespace",
"destination_podname",
"destination_workloadKind",
"destination_workloadName",
"destination_workload_kind",
"destination_workload_name",
"destination_service",
"destination_port",
},
Expand Down Expand Up @@ -377,8 +377,8 @@ func TestNewTCPMetrics(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand Down Expand Up @@ -416,8 +416,8 @@ func TestNewTCPMetrics(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand Down Expand Up @@ -457,8 +457,8 @@ func TestNewTCPMetrics(t *testing.T) {
"ip",
"namespace",
"podname",
"workloadKind",
"workloadName",
"workload_kind",
"workload_name",
"service",
"port",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/module/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const (
portCtxOption = "port"

// workloads context option
workloadKindCtxOption = "workloadKind"
workloadKindCtxOption = "workload_kind"

// workload context option
workloadNameCtxOption = "workloadName"
workloadNameCtxOption = "workload_name"

// workload context option
workloadCtxOption = "workload"
Expand Down
8 changes: 4 additions & 4 deletions pkg/module/metrics/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestNewCtxOps(t *testing.T) {
ctxType: source,
expected: []string{
"source_ip", "source_namespace", "source_podname",
"source_workloadKind", "source_workloadName", "source_service", "source_port",
"source_workload_kind", "source_workload_name", "source_service", "source_port",
},
f: &flow.Flow{},
expectedVals: []string{"unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"},
Expand All @@ -45,7 +45,7 @@ func TestNewCtxOps(t *testing.T) {
ctxType: destination,
expected: []string{
"destination_ip", "destination_namespace", "destination_podname",
"destination_workloadKind", "destination_workloadName", "destination_service", "destination_port",
"destination_workload_kind", "destination_workload_name", "destination_service", "destination_port",
},
f: &flow.Flow{},
expectedVals: []string{"unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"},
Expand All @@ -56,7 +56,7 @@ func TestNewCtxOps(t *testing.T) {
ctxType: source,
expected: []string{
"source_ip", "source_namespace", "source_podname",
"source_workloadKind", "source_workloadName", "source_service", "source_port",
"source_workload_kind", "source_workload_name", "source_service", "source_port",
},
f: &flow.Flow{
Source: &flow.Endpoint{
Expand All @@ -72,7 +72,7 @@ func TestNewCtxOps(t *testing.T) {
ctxType: destination,
expected: []string{
"destination_ip", "destination_namespace", "destination_podname",
"destination_workloadKind", "destination_workloadName", "destination_service", "destination_port",
"destination_workload_kind", "destination_workload_name", "destination_service", "destination_port",
},
f: &flow.Flow{
Destination: &flow.Endpoint{
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// package common contains common functions and values that are used across multiple e2e tests.
package common

const (
RetinaPort int = 10093
// netObsRGtag is used to tag resources created by this test suite
NetObsRGtag = "-e2e-netobs-"
)
28 changes: 28 additions & 0 deletions test/e2e/framework/kubernetes/get-pod-ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kubernetes

import (
"context"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

func GetPodIP(kubeConfigFilePath, namespace, podName string) (string, error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeConfigFilePath)
if err != nil {
return "", errors.Wrapf(err, "error building kubeconfig")
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return "", errors.Wrapf(err, "error creating Kubernetes clientset")
}

pod, err := clientset.CoreV1().Pods(namespace).Get(context.Background(), podName, metav1.GetOptions{})
if err != nil {
return "", errors.Wrapf(err, "error getting pod %s in namespace %s", podName, namespace)
}
return pod.Status.PodIP, nil
nddq marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading