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

Minor refactor for broker ingress, adding unittests. #2270

Merged
merged 9 commits into from
Dec 19, 2019

Conversation

n3wscott
Copy link
Contributor

@n3wscott n3wscott commented Dec 5, 2019

  • Found an issue where the broker filter and ingress report metrics with the same name, preventing go coverage from running.
  • Introduce an event defaulter to wrap the management of TTL for broker ingress. This centralizes the logic of dealing with TTL, deleting some code.

Release Note

NONE

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Dec 5, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 5, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: n3wscott

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 Dec 5, 2019
@@ -38,23 +38,23 @@ var (
// eventCountM is a counter which records the number of events received
// by a Trigger.
eventCountM = stats.Int64(
"event_count",
"broker_filter_event_count",
Copy link
Contributor

Choose a reason for hiding this comment

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

this will break stackdriver integration... these metrics names are whitelisted in SD so that nobody is charged

Copy link
Contributor

Choose a reason for hiding this comment

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

/hold

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is wrong as is as they conflict. Knative does not have knowledge of stack driver whitelists.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess now it has :)
Metrics are API surface. We cannot just change them because code coverage cannot run...

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 5, 2019
@@ -33,15 +33,15 @@ var (
// eventCountM is a counter which records the number of events received
// by the Broker.
eventCountM = stats.Int64(
"event_count",
"broker_ingress_event_count",
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing here... why do we need this change? is for a UT coverage thing?
we are matching the naming convention of metrics in serving..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code coverage can not run with the two init methods registering the two matching names. Plus this prevents us from running in the same container...

Copy link
Contributor

Choose a reason for hiding this comment

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

code coverage is not a blocker for merging things. If there is a workaround without changing the names, then go for it... Otherwise we should not change the names.

When the time comes to run in the same container, then I think we can revisit.

@n3wscott
Copy link
Contributor Author

n3wscott commented Dec 5, 2019

@nachocano I think it is not valid to hold a PR because it would break private integration that is not part of Knative.

@nachocano
Copy link
Contributor

@n3wscott it's not private integration, everyone can use SD. See pkg, serving has all the metrics there, and we too (although it should be refactored).
Furthermore, we are using the same metric naming conventions as serving. Serving doesn't add prefixes, and neither we should.
Metrics are API surface, people have dashboards and are relying on metrics. We cannot just simply change them because "code coverage doesn't run".

@n3wscott
Copy link
Contributor Author

n3wscott commented Dec 5, 2019

Then we should use the registration that serving uses to prevent errors from the the view.Register call. As it is, it does not work.

@nachocano
Copy link
Contributor

Then we should use the registration that serving uses to prevent errors from the the view.Register call. As it is, it does not work.

OK, that makes sense. Can you take care of that change in this PR?

@n3wscott
Copy link
Contributor Author

n3wscott commented Dec 5, 2019

Let me take a crack.

I don't want this merged before 0.11 is cut regardless.

@nachocano
Copy link
Contributor

Let me take a crack.

Thanks!

I don't want this merged before 0.11 is cut regardless.

Yes, makes sense!

@n3wscott
Copy link
Contributor Author

n3wscott commented Dec 6, 2019

There is way more work that I want to start for refactoring the measurements code.

I am removing the panic and moving on.

@nachocano
Copy link
Contributor

nachocano commented Dec 6, 2019 via email

@n3wscott
Copy link
Contributor Author

/retest
I reverted the issue that Nacho had with the previous PR.
/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 18, 2019
package ingress

import (
"context"
"knative.dev/eventing/pkg/broker"
Copy link
Contributor

Choose a reason for hiding this comment

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

formatter?

pkg/broker/ttl.go Outdated Show resolved Hide resolved
// If TTL is not found, it will set it to the default passed in.
// If TTL is <= 0, it will remain 0.
// If TTL is > 1, it will be reduced by one.
func TTLDefaulter(logger *zap.Logger, defaultTTL int32) client.EventDefaulter {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check defaultTTL is > 0?

package broker

import (
"context"
Copy link
Contributor

Choose a reason for hiding this comment

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

format imports?

// Setting the extension as a string as the CloudEvents sdk does not support non-string extensions.
event.SetExtension(broker.EventArrivalTime, time.Now().Format(time.RFC3339))
event.SetExtension(broker.EventArrivalTime, cloudevents.Timestamp{Time: time.Now()})
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make sure we are not breaking the way we are reading the extension on the filter pod?

var arrivalTimeStr string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it works.

@nachocano
Copy link
Contributor

Very cosmetic comments, and one that I think is important, the arrival time extension.
Can you update the PR description and release notes as we are not adding that prefix anymore?

} else if ttl, err = cetypes.ToInteger(ttlraw); err != nil {
logger.Warn("Failed to convert existing TTL into integer, defaulting.",
zap.String("event.id", event.ID()),
zap.Any(TTLAttribute, ttlraw),
zap.Error(err),
)
ttl = defaultTTL + 1
ttl = defaultTTL
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks!

@nachocano
Copy link
Contributor

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 18, 2019
@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/ingress/ingress_handler.go 60.0% 82.9% 22.9
pkg/broker/ttl.go Do not exist 85.0%

@knative-prow-robot knative-prow-robot merged commit 5631d77 into knative:master Dec 19, 2019
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants