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

feat: add useragent to conformance test run #3211

Merged
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
35 changes: 35 additions & 0 deletions conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
// Conformance Test Suite - Public Methods
// -----------------------------------------------------------------------------

const (
testSuiteUserAgentPrefix = "gateway-api-conformance.test"
)

// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest) {
Expand Down Expand Up @@ -374,6 +378,35 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
}
}

func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
featureNames := []string{}
for _, v := range test.Features {
featureNames = append(featureNames, string(v))
}
if len(test.Features) == 0 {
featureNames = []string{"unknownFeature"}
}
suite.RestConfig.UserAgent = strings.Join(
[]string{
testSuiteUserAgentPrefix,
suite.apiVersion,
test.ShortName,
strings.Join(featureNames, ","),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this list could get pretty long, is it okay to have all the feature names present in every useragent string? How long can a useragent string be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youngnick, good question!

Looking at the latest Kubernetes test results, filtering by conformance tests:

$ curl -sSL https://storage.googleapis.com/kubernetes-jenkins/logs/ci-kubernetes-e2e-gci-gce/1810176656531263488/artifacts/junit_01.xml \ 
  | yq -p=xml -o=yaml \
  | yq '.testsuites.testsuite.testcase[] | select(.+@name == "*[Conformance]*") | .+@name' \
  | sed 's/.*\]\(.*\)\[.*/\1/g' \
  | awk '{ print length($0) " " $0; }' | sort -r -n | cut -d ' ' -f 2- | head -n 1 | wc -c

The longest useragent is 131 characters.
The current longest useragent with the changes from this PR is

apisnoop=# select distinct(useragent) as ua, length(useragent) as ual from testing.audit_event where useragent ilike 'gateway-api-conformance.test%' order by ual desc limit 1;
                                                                         ua                                                                          |
 ual
-----------------------------------------------------------------------------------------------------------------------------------------------------+
-----
 gateway-api-conformance.test::v1.2.0-dev::HTTPRouteRequestMultipleMirrors::Gateway,HTTPRoute,HTTPRouteRequestMirror,HTTPRouteRequestMultipleMirrors |
 147
(1 row)

is 147.

Kubernetes Audit Logging appears to only store 1024 characters for useragents
https://github.com/kubernetes/kubernetes/blob/2b03f04/staging/src/k8s.io/apiserver/pkg/audit/request.go#L39

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed analysis @BobyMCbobs! If I'm understanding this correctly, it seems like this would be easy to change in the future if/when we run into an issue, and the only limit that really matters is k8s API Server. Given that, I think I'm ok with the current path. In the future we could add a numerical id for each feature if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robscott, absolutely!
Yes and the main thing is that we are able to map tests to features. Using this as a framework, we can pump any extra data through as usefulness and need arises.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we could add a numerical id for each feature if needed.

I think this is a great idea, instead of putting all the features' names here.

},
"::")
client, err := client.New(suite.RestConfig, client.Options{})
if err != nil {
return err
}
clientset, err := clientset.NewForConfig(suite.RestConfig)
if err != nil {
return err
}
suite.Client = client
suite.Clientset = clientset
return nil
}

// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) error {
// verify that the test suite isn't already running, don't start a new run
Expand Down Expand Up @@ -410,6 +443,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
}

succeeded := t.Run(test.ShortName, func(t *testing.T) {
err := suite.setClientsetForTest(test)
require.NoError(t, err, "failed to create new clientset for test")
test.Run(t, suite)
})
if !succeeded {
Expand Down