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

E2E Test for Broker Tracing #1995

Merged
merged 23 commits into from
Oct 9, 2019
Merged

Conversation

Harwayne
Copy link
Contributor

@Harwayne Harwayne commented Oct 3, 2019

Helps with #1766

Proposed Changes

  • Add an E2E Test for tracing through the Broker.

The initial work for this PR was done by @daisy-ycguo in #1878.

Release Note

Tracing works through Broker, Triggers, and their replies.

@knative-prow-robot knative-prow-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. area/test-and-release Test infrastructure, tests or release labels Oct 3, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 3, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Harwayne

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 3, 2019
channelTypeMeta := common.GetChannelTypeMeta(channel)
client.CreateBrokerOrFail(brokerName, channelTypeMeta)

// DO NOT SUBMIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111!!!!!!!!!!!!!!!!!!
Copy link
Contributor

Choose a reason for hiding this comment

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

Found "DO NOT SUBMIT".

return it[key] < jt[key]
}
}
panic(fmt.Errorf("can't tell the difference between %v, %v", ic, jc))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't panic.

@Harwayne
Copy link
Contributor Author

Harwayne commented Oct 4, 2019

/retest

@Harwayne
Copy link
Contributor Author

Harwayne commented Oct 4, 2019

/test pull-knative-eventing-integration-tests

1 similar comment
@Harwayne
Copy link
Contributor Author

Harwayne commented Oct 4, 2019

/test pull-knative-eventing-integration-tests

@Harwayne
Copy link
Contributor Author

Harwayne commented Oct 4, 2019

/test pull-knative-eventing-integration-tests

@Harwayne Harwayne marked this pull request as ready for review October 4, 2019 19:39
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2019
@Harwayne
Copy link
Contributor Author

Harwayne commented Oct 7, 2019

@chizhg This is ready for review.

@@ -252,10 +253,9 @@ func (r *Handler) sendEvent(ctx context.Context, tctx cloudevents.HTTPTransportC
}

sendingCTX := utils.ContextFrom(tctx, subscriberURI)
Copy link
Member

Choose a reason for hiding this comment

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

Ctx instead of CTX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I understand, Go prefers non-word segments to share capitalization. https://talks.golang.org/2014/names.slide#5 refers to acronyms, "Acronyms should be all capitals, as in ServeHTTP and IDProcessor." CTX isn't an acronym, but it does feel like a similar, non-word segment. So I chose to keep it at the same level of capitalization.

@@ -91,6 +89,10 @@ func (h *Handler) serveHTTP(ctx context.Context, event cloudevents.Event, resp *

start := time.Now()
sendingCTX := utils.ContextFrom(tctx, h.ChannelURI)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

test/common/creation.go Show resolved Hide resolved
@@ -144,7 +145,7 @@ func (t *Tracker) WaitForKResourcesReady() error {
t.logf("Waiting for all KResources to become ready")
for _, metaResource := range t.resourcesToCheckStatus {
if err := base.WaitForResourceReady(t.dynamicClient, &metaResource); err != nil {
return err
return fmt.Errorf("waiting for %+v to become ready: %v", metaResource, err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("waiting for %+v to become ready: %v", metaResource, err)
return fmt.Errorf("failed waiting for %+v to become ready: %v", metaResource, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Create a Trigger that receives events (type=bar) and sends them to the logger Pod.
loggerTrigger := client.CreateTriggerOrFail(
"logger",
Copy link
Member

Choose a reason for hiding this comment

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

Define it as a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could, but why? This is the only place the value is used. Everywhere else it is needed, we use loggerTrigger.Name.

Tags: map[string]string{
"http.method": "POST",
"http.status_code": "202",
"http.url": fmt.Sprintf("http://%s/", loggerSVCHost),
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove the trailing /?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This is doing an exact match against the values recorded in the trace. The trace records the trailing /, so the test needs it too.

Kind model.Kind
LocalEndpointServiceName string
Tags map[string]string
Note string `json:"aaNote,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Are these a and aa prefixes added for sorting? If yes can we have some comments for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment, does it make sense?

}

func (t TestSpanTree) String() string {
b, _ := json.Marshal(t)
return string(b)
}

func (t *TestSpanTree) SortChildren() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have some comments for what this sort function does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if g, w := actual.ToTestSpanTree().SpanCount(), t.SpanCount(); g != w {
return fmt.Errorf("unexpected number of spans. got %d want %d", g, w)
}
t.SortChildren()
err := traceTreeMatches(".", t, actual)
Copy link
Member

Choose a reason for hiding this comment

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

Inline the error check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Due to https://github.com/knative/eventing/issues/1998, wait for the Broker to become ready
// before creating the Triggers.
err := client.WaitForResourceReady(brokerName, &metav1.TypeMeta{
Copy link
Member

@chizhg chizhg Oct 8, 2019

Choose a reason for hiding this comment

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

We can use common.BrokerTypeMeta here.
Also sounds like this is a bug we'll fix anyway, can we change the comment to a TODO? Since we also have the similar logic in e2e tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

I think the other e2e tests use the default Broker, which is likely created via the injection annotation and happens to be ready in time.

Copy link
Member

Choose a reason for hiding this comment

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

There are also two test cases that create brokers:

client.CreateBrokerOrFail(brokerName, channelTypeMeta)

client.CreateBrokerOrFail(brokerName, channelTypeMeta)

// +build e2e

/*
Copyright 2019 The Knative Authors
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Copyright 2019 The Knative Authors
Copyright 2019 The Knative Authors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copyright 2019 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Copy link
Member

@chizhg chizhg Oct 8, 2019

Choose a reason for hiding this comment

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

Also missed linefeed here, and in the header of other new files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,48 @@
/*
Copy link
Member

@chizhg chizhg Oct 8, 2019

Choose a reason for hiding this comment

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

Since you define them as functions here, do you think uri.go will be a better file name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// 1. Shorter children first.
// 2. Span kind.
// 3. "http.url", "http.host", "http.path" tag presence and values.
// If all of those are equal, then arbitrarily chose the earlier index.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If all of those are equal, then arbitrarily chose the earlier index.
// If all of those are equal, then arbitrarily choose the earlier index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// manually.
//
// The order it uses:
// 1. Shorter children first.
Copy link
Member

Choose a reason for hiding this comment

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

Lower children first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shorter. Where height is defined as the maximal number of descendants before hitting a leaf node. For example:

    A
  /   \
B      C
|
D

'A' has a height of 2. 'B' has a height of 1. 'C' and 'D' have heights of 0.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/broker/filter/filter_handler.go 81.8% 81.5% -0.3

@chizhg
Copy link
Member

chizhg commented Oct 9, 2019

It looks really hard to get this test working, I can imagine how much effort you put on it 👍
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 9, 2019
@knative-prow-robot knative-prow-robot merged commit aca7b61 into knative:master Oct 9, 2019
@Harwayne Harwayne deleted the broker-trace branch October 9, 2019 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test-and-release Test infrastructure, tests or release cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants