Skip to content

Add NGF build information to test results #2353

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

Merged
merged 8 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
CI=false
CI ?= false
CLUSTER_NAME ?= kind
CONFORMANCE_PREFIX = conformance-test-runner## Prefix for the conformance test runner image
CONFORMANCE_TAG = latest## Tag for the conformance test runner image
GATEWAY_CLASS = nginx## Gateway class to use
GINKGO_FLAGS =
GINKGO_LABEL =
GITHUB_OUTPUT =
GW_API_VERSION ?= $(shell sed -n 's/.*ref=v\(.*\)/\1/p' ../config/crd/gateway-api/standard/kustomization.yaml)## Supported Gateway API version from current NGF
GW_API_PREV_VERSION ?= 1.1.0## Supported Gateway API version from previous NGF release
GW_SERVICE_TYPE = NodePort## Service type to use for the gateway
Expand All @@ -18,6 +19,10 @@ ifneq ($(GINKGO_LABEL),)
override GINKGO_FLAGS += --label-filter "$(GINKGO_LABEL)"
endif

ifeq ($(CI),true)
GITHUB_OUTPUT := --github-output
endif

.PHONY: update-go-modules
update-go-modules: ## Update the gateway-api go modules to latest main version
go get -u sigs.k8s.io/gateway-api@main
Expand Down Expand Up @@ -107,9 +112,10 @@ start-longevity-test: nfr-test ## Start the longevity test to run for 4 days in
stop-longevity-test: export STOP_LONGEVITY=true
stop-longevity-test: nfr-test ## Stop the longevity test and collects results


.PHONY: .vm-nfr-test
.vm-nfr-test: ## Runs the NFR tests on the GCP VM (called by `nfr-test`)
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending --trace -r -v --force-newlines $(ifeq $(CI),true,--github-output) \
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending --trace -r -v -buildvcs --force-newlines $(GITHUB_OUTPUT) \
--label-filter "nfr" $(GINKGO_FLAGS) --timeout 3h ./suite -- --gateway-api-version=$(GW_API_VERSION) \
--gateway-api-prev-version=$(GW_API_PREV_VERSION) --image-tag=$(TAG) --version-under-test=$(NGF_VERSION) \
--plus-enabled=$(PLUS_ENABLED) --ngf-image-repo=$(PREFIX) --nginx-image-repo=$(NGINX_PREFIX) --nginx-plus-image-repo=$(NGINX_PLUS_PREFIX) \
Expand All @@ -118,7 +124,7 @@ stop-longevity-test: nfr-test ## Stop the longevity test and collects results

.PHONY: test
test: ## Runs the functional tests on your default k8s cluster
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending --trace -r -v --force-newlines \
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending --trace -r -v -buildvcs --force-newlines $(GITHUB_OUTPUT) \
--label-filter "functional" $(GINKGO_FLAGS) ./suite -- \
--gateway-api-version=$(GW_API_VERSION) --gateway-api-prev-version=$(GW_API_PREV_VERSION) \
--image-tag=$(TAG) --version-under-test=$(NGF_VERSION) \
Expand Down
28 changes: 28 additions & 0 deletions tests/framework/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package framework

import (
"fmt"
"runtime/debug"

core "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// GetLogs returns the logs for all containers in all pods for a release.
func GetLogs(rm ResourceManager, namespace string, releaseName string) string {
var returnLogs string
pods, err := rm.GetPods(namespace, client.MatchingLabels{
Expand All @@ -32,6 +34,7 @@ func GetLogs(rm ResourceManager, namespace string, releaseName string) string {
return returnLogs
}

// GetEvents returns the events for a namespace.
func GetEvents(rm ResourceManager, namespace string) string {
var returnEvents string
events, err := rm.GetEvents(namespace)
Expand All @@ -53,3 +56,28 @@ func GetEvents(rm ResourceManager, namespace string) string {
}
return returnEvents
}

// GetBuildInfo returns the build information.
func GetBuildInfo() (commitHash string, commitTime string, dirtyBuild string) {
commitHash = "unknown"
commitTime = "unknown"
dirtyBuild = "unknown"

info, ok := debug.ReadBuildInfo()
if !ok {
return
}

for _, kv := range info.Settings {
switch kv.Key {
case "vcs.revision":
commitHash = kv.Value
case "vcs.time":
commitTime = kv.Value
case "vcs.modified":
dirtyBuild = kv.Value
}
}

return
}
9 changes: 6 additions & 3 deletions tests/framework/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ func WriteSystemInfoToFile(file *os.File, ci ClusterInfo, plus bool) error {
if ci.IsGKE {
clusterType = "GKE"
}

commit, date, dirty := GetBuildInfo()

//nolint:lll
text := fmt.Sprintf(
//nolint:lll
"# Results\n\n## Test environment\n\nNGINX Plus: %v\n\n%s Cluster:\n\n- Node count: %d\n- k8s version: %s\n- vCPUs per node: %d\n- RAM per node: %s\n- Max pods per node: %d\n",
plus, clusterType, ci.NodeCount, ci.K8sVersion, ci.CPUCountPerNode, ci.MemoryPerNode, ci.MaxPodsPerNode,
"# Results\n\n## Test environment\n\nNGINX Plus: %v\n\nNGINX Gateway Fabric:\n\n- Commit: %s\n- Date: %s\n- Dirty: %v\n\n%s Cluster:\n\n- Node count: %d\n- k8s version: %s\n- vCPUs per node: %d\n- RAM per node: %s\n- Max pods per node: %d\n",
plus, commit, date, dirty, clusterType, ci.NodeCount, ci.K8sVersion, ci.CPUCountPerNode, ci.MemoryPerNode, ci.MaxPodsPerNode,
)
if _, err := fmt.Fprint(file, text); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/remote-scripts/run-nfr-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ elif [ "${STOP_LONGEVITY}" == "true" ]; then
GINKGO_LABEL="longevity-teardown"
fi

cd nginx-gateway-fabric/tests && make .vm-nfr-test TAG="${TAG}" PREFIX="${PREFIX}" NGINX_PREFIX="${NGINX_PREFIX}" NGINX_PLUS_PREFIX="${NGINX_PLUS_PREFIX}" PLUS_ENABLED="${PLUS_ENABLED}" GINKGO_LABEL=${GINKGO_LABEL} GINKGO_FLAGS="${GINKGO_FLAGS}" PULL_POLICY=Always GW_SERVICE_TYPE=LoadBalancer GW_SVC_GKE_INTERNAL=true NGF_VERSION="${NGF_VERSION}"
cd nginx-gateway-fabric/tests && make .vm-nfr-test CI=${CI} TAG="${TAG}" PREFIX="${PREFIX}" NGINX_PREFIX="${NGINX_PREFIX}" NGINX_PLUS_PREFIX="${NGINX_PLUS_PREFIX}" PLUS_ENABLED="${PLUS_ENABLED}" GINKGO_LABEL=${GINKGO_LABEL} GINKGO_FLAGS="${GINKGO_FLAGS}" PULL_POLICY=Always GW_SERVICE_TYPE=LoadBalancer GW_SVC_GKE_INTERNAL=true NGF_VERSION="${NGF_VERSION}"

if [ "${START_LONGEVITY}" == "true" ]; then
suite/scripts/longevity-wrk.sh
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/remote-scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

source "${HOME}"/vars.env

cd nginx-gateway-fabric/tests && make test TAG="${TAG}" PREFIX="${PREFIX}" NGINX_PREFIX="${NGINX_PREFIX}" NGINX_PLUS_PREFIX="${NGINX_PLUS_PREFIX}" PLUS_ENABLED="${PLUS_ENABLED}" GINKGO_LABEL="${GINKGO_LABEL}" GINKGO_FLAGS="${GINKGO_FLAGS}" PULL_POLICY=Always GW_SERVICE_TYPE=LoadBalancer GW_SVC_GKE_INTERNAL=true NGF_VERSION="${NGF_VERSION}"
cd nginx-gateway-fabric/tests && make test CI=${CI} TAG="${TAG}" PREFIX="${PREFIX}" NGINX_PREFIX="${NGINX_PREFIX}" NGINX_PLUS_PREFIX="${NGINX_PLUS_PREFIX}" PLUS_ENABLED="${PLUS_ENABLED}" GINKGO_LABEL="${GINKGO_LABEL}" GINKGO_FLAGS="${GINKGO_FLAGS}" PULL_POLICY=Always GW_SERVICE_TYPE=LoadBalancer GW_SVC_GKE_INTERNAL=true NGF_VERSION="${NGF_VERSION}"
1 change: 1 addition & 0 deletions tests/scripts/run-tests-gcp-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gcloud compute scp --zone "${GKE_CLUSTER_ZONE}" --project="${GKE_PROJECT}" "${SC
gcloud compute ssh --zone "${GKE_CLUSTER_ZONE}" --project="${GKE_PROJECT}" username@"${RESOURCE_NAME}" \
--command="export START_LONGEVITY=${START_LONGEVITY} &&\
export STOP_LONGEVITY=${STOP_LONGEVITY} &&\
export CI=${CI} &&\
bash -s" <"${SCRIPT_DIR}"/remote-scripts/${SCRIPT}
retcode=$?

Expand Down
2 changes: 1 addition & 1 deletion tests/suite/client_settings_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/dataplane_perf_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/graceful_recovery_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/longevity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/sample_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/scale_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down
4 changes: 3 additions & 1 deletion tests/suite/system_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package suite
// This package needs to be named main to get build info
// because of https://github.com/golang/go/issues/33976
package main

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/tracing_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package suite
package main

import (
"bytes"
Expand Down
Loading