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

Add kubernetes based events for triggers #1222

Merged
merged 1 commit into from
Dec 14, 2021

Conversation

savitaashture
Copy link
Contributor

@savitaashture savitaashture commented Sep 7, 2021

Changes

This PR adds changes to display k8s events for EventListener Pod when http request reaches to EL

kubectl get events -w | grep eventlistener

0s          Normal    dev.tekton.event.triggers.started.v1   eventlistener/github-listener              
0s          Normal    dev.tekton.event.triggers.successful.v1   eventlistener/github-listener              

/cc @dibyom @khrm

Addresses #649

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Release Notes

Triggers now support emitting Kubernetes events from EventListener Pod

@tekton-robot tekton-robot requested review from dibyom and khrm September 7, 2021 06:48
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 7, 2021
@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/reconciler/eventlistener/eventlistener.go 67.8% 68.7% 0.9
pkg/reconciler/events/event.go Do not exist 75.0%

@savitaashture
Copy link
Contributor Author

/cc @vdemeester

@vaikas
Copy link
Contributor

vaikas commented Sep 13, 2021

FWIW, I'd caution against sending events for successful reconciliation and even for things that are non-terminal failures. This particular example emits 15 events in 78sec.

Creating events can be a problem in couple of scenarios:

  • Large number of EventListener objects get created in a short amount of time
  • Global resync, for example, when a controller restarts, or if HA is enabled, a leader switches.

In both cases there might be problems with the controller getting ratelimited due to large number of events and hilarity will ensue. We ran into this in Knative and just sharing our experience. In the end we ended up dialing back the number of events we emit because it ended up creating problems.

@khrm
Copy link
Contributor

khrm commented Sep 13, 2021

@savitaashture Based on #649, we should emit events when we trigger a resource successfully. This code should go inside EventListener's sink, not reconciliation.

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2021
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 23, 2021
@savitaashture
Copy link
Contributor Author

@khrm @dibyom PR is ready for Review PTAL

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 71.4%
pkg/sink/sink.go 75.8% 75.0% -0.8

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 71.4%
pkg/sink/sink.go 75.8% 75.0% -0.8

@@ -85,6 +85,9 @@ rules:
resources: ["podsecuritypolicies"]
resourceNames: ["tekton-triggers"]
verbs: ["use"]
- apiGroups: [""]
resources: ["events"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious if here and below we need all these permissions? Seems like create would suffice because we only emit events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes only create is required
Thanks for the heads up 👍

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 71.4%
pkg/sink/sink.go 75.8% 75.0% -0.8

@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-integration-tests

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

Thanks @savitaashture

My main comment is around this PR and #1259 - I think we should be consistent in where and how we are emitting the event. As well as be consistent on the type of events that we are emitting (though the exact contents might be different).

@@ -261,6 +261,12 @@ func (els *EventListenerStatus) SetConditionsForDynamicObjects(conditions v1beta
Message: cond.Message,
})
}

els.SetCondition(&apis.Condition{
Copy link
Member

Choose a reason for hiding this comment

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

question: why do we need this in this PR?

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 as part of this PR because EL for Knative when succeed was not displaying any messages so added this change as part of this PR itself

)

const (
// EventReasonSucceded is the reason set for events about successful completion of EventListener
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to make sure the event reasons/types here are the same as the one in #1259?

Copy link
Contributor Author

@savitaashture savitaashture Dec 3, 2021

Choose a reason for hiding this comment

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

Updated and used similar constant from #1259 PR

pkg/sink/sink.go Outdated
func (r Sink) emitEvents(ctx context.Context, el *triggersv1.EventListener, err error) {
var afterCondition *apis.Condition
if el != nil {
afterCondition = el.Status.GetCondition(apis.ConditionReady)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should send the apis.ConditionReady as the message for the event. Maybe we can try to be consistent with the cloudevents PR here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

with el.Status.GetCondition(apis.ConditionReady) not sending message to event instead we are getting el Status

pkg/sink/sink.go Outdated
@@ -111,6 +123,7 @@ func (r Sink) HandleEvent(response http.ResponseWriter, request *http.Request) {
log.Errorf("Error reading event body: %s", err)
r.recordCountMetrics(failTag)
response.WriteHeader(http.StatusInternalServerError)
r.emitEvents(r.ContextForEvents, el, err)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be co-ordinated with #1259 as well - can we have a single r.EmitEvents that sends both K8sEvents and CloudEvents (if enabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup i agree but i think we can do that once PRs merge

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 75.0%
pkg/sink/sink.go 75.8% 75.2% -0.5

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 75.0%
pkg/sink/sink.go 75.8% 75.2% -0.5

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 75.0%
pkg/sink/sink.go 75.8% 75.1% -0.7

@@ -91,17 +95,40 @@ type Response struct {
ErrorMessage string `json:"errorMessage,omitempty"`
}

func (r Sink) emitEvents(recorder record.EventRecorder, el *triggersv1.EventListener, err error) {
afterCondition := el.Status.GetCondition(apis.ConditionReady)
if el.Annotations[events.EnableEventListenerEvents] == "true" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dibyom emitting events only when user sets enable-eventlistener-events: "true" annotation
LMK your opinion on this.
If it looks okay i will update same info in Doc as well
/cc @khrm

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that sounds good. This should be an option in the config-features.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dibyom do you mean we no need to take from eventlistener annotation instead we should depend on config-features cm ?

Copy link
Member

Choose a reason for hiding this comment

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

my bad. I missed that this was an annotation. Just an annotation is fine for now as long as we document it.

@@ -91,17 +95,40 @@ type Response struct {
ErrorMessage string `json:"errorMessage,omitempty"`
}

func (r Sink) emitEvents(recorder record.EventRecorder, el *triggersv1.EventListener, err error) {
afterCondition := el.Status.GetCondition(apis.ConditionReady)
if el.Annotations[events.EnableEventListenerEvents] == "true" {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah that sounds good. This should be an option in the config-features.

pkg/sink/sink.go Outdated
events.EnableEventListenerEvents: "true",
}}}

r.emitEvents(r.EventRecorder, &elTemp, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this mean that we will always emit an event due to elTemp always setting the annotation to true? i.e. the actual EL could have it set of false but due to elTemp defaulting to true, we are still emitting one event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because from this operation
el, err := r.EventListenerLister.EventListeners(r.EventListenerNamespace).Get(r.EventListenerName) there could be chances of error while doing Get
So added elTemp so that get operation failure captured

EnableEventListenerEvents = "enable-eventlistener-events"
// TriggerProcessingStarted is sent for Sink triggers received which
// are being processed
TriggerProcessingStartedV1 = "triggers.tekton.eventlistener.triggerprocessing.started.v1"
Copy link
Member

Choose a reason for hiding this comment

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

I'm glad that this is consistent with cloudevents but I had a comment that those names should be similar to the ones for Pipelines - see #1259 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 👍

sendKubernetesEvents(recorder, afterCondition, object, err)
}

func sendKubernetesEvents(c record.EventRecorder, afterCondition *apis.Condition, object runtime.Object, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm still not sure if we need to rely on the status of the EventListener for emitting events in Triggers - if the EL is not ready, we are probably not going to receive the event at all i.e. the server is not up or something.

IMO it will be clearer emitEvents just sends the eventType (Successful, Failed etc.) as a param instead of the afterCondition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had a scenario with custom-resource example as part of 0.16.0 Triggers release we had an issue #1219 related to metadata.resourceVersion as part of Knative and because of that EL status was not True but pods were up and running so that is the reason i considered this way of using EL status in order to cover such scenarios also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But agree with you that the current PR focuses on events for Trigger process so we no need to consider eventlistener status instead we can send the type as you suggested

I have updated PR PTAL

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 66.7%
pkg/sink/sink.go 75.9% 75.1% -0.8

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 66.7%
pkg/sink/sink.go 75.9% 75.1% -0.8

@@ -3,6 +3,8 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: github-listener
annotations:
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to change this in our examples?

Copy link
Contributor Author

@savitaashture savitaashture Dec 13, 2021

Choose a reason for hiding this comment

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

Its not needed but just as an example for emitting event added annotation

Reverted back for both v1alpha1 and v1beta1

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom, vdemeester

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2021
@dibyom
Copy link
Member

dibyom commented Dec 10, 2021

Few small nits, but otherwise good to go!

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 66.7%

@tekton-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/apis/triggers/v1alpha1/event_listener_types.go 80.6% 81.2% 0.6
pkg/apis/triggers/v1beta1/event_listener_types.go 80.6% 81.2% 0.6
pkg/reconciler/events/event.go Do not exist 66.7%
pkg/sink/sink.go 75.9% 75.1% -0.8

@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-integration-tests

2 similar comments
@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-integration-tests

@savitaashture
Copy link
Contributor Author

/test pull-tekton-triggers-integration-tests

@savitaashture
Copy link
Contributor Author

@dibyom I have addressed all review comments PTAL

@dibyom
Copy link
Member

dibyom commented Dec 14, 2021

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2021
@tekton-robot tekton-robot merged commit d9b14bf into tektoncd:main Dec 14, 2021
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. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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