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

Adding a filter for custom error respnse codes to be added as CE extensions #2657

Merged

Conversation

matzew
Copy link
Contributor

@matzew matzew commented Sep 19, 2022

Signed-off-by: Matthias Wessendorf [email protected]

Fixes #2376

Proposed Changes

  • adding custom header prefix for enhancing failed couldevents when sent to dead letter sink

Release Note

If a fail response contains a custom http header that starts with `kne-`, the prefix will be removed and the rest of the header will be used as the CE extension on the CloudEvent delivered to the dead letter sink.

Docs

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/data-plane size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 19, 2022
@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

TODO: will add test(s)

@@ -77,6 +78,7 @@ public class RecordDispatcherImpl implements RecordDispatcher {
private static final String KN_ERROR_DEST_EXT_NAME = "knativeerrordest";
private static final String KN_ERROR_CODE_EXT_NAME = "knativeerrorcode";
private static final String KN_ERROR_DATA_EXT_NAME = "knativeerrordata";
private static final String EKB_ERROR_PREFIX = "kne-";
Copy link
Contributor Author

@matzew matzew Sep 19, 2022

Choose a reason for hiding this comment

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

@pierDipi I have no idea what is better kne- as in Knative Error?

Or ekb-, as in "eventing kafka broker", as that is more generic

Copy link
Member

Choose a reason for hiding this comment

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

I like kne-

@@ -292,6 +294,13 @@ private ConsumerRecordContext errorTransform(final ConsumerRecordContext recordC
extensions.put(KN_ERROR_DEST_EXT_NAME, destination);
extensions.put(KN_ERROR_CODE_EXT_NAME, String.valueOf(response.statusCode()));

// transform all headers keys to be lowercase and filter by prefix.
// afterwards extract the prefix and add them to the extensions map
response.headers().entries().stream().collect(Collectors.toMap(entry -> entry.getKey().toLowerCase(), entry -> entry.getValue()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

works, but perhaps can be written "nicer" ...

Copy link
Member

@pierDipi pierDipi Sep 19, 2022

Choose a reason for hiding this comment

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

This should be much faster with less allocations and IMHO cleaner:

    response.headers().forEach((k, v) -> {
      if (k.regionMatches(true, 0, EKB_ERROR_PREFIX, 0, EKB_ERROR_PREFIX.length())) { // aka startsWithIgnoreCase
        extensions.put(k.substring(EKB_ERROR_PREFIX.length()).toLowerCase(), v);
      }
    });

@codecov
Copy link

codecov bot commented Sep 19, 2022

Codecov Report

Merging #2657 (0613635) into main (3470bcd) will increase coverage by 6.21%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #2657      +/-   ##
============================================
+ Coverage     55.92%   62.13%   +6.21%     
- Complexity        0      723     +723     
============================================
  Files            75      148      +73     
  Lines          7864    10406    +2542     
  Branches          0      229     +229     
============================================
+ Hits           4398     6466    +2068     
- Misses         3150     3489     +339     
- Partials        316      451     +135     
Flag Coverage Δ
java-unittests 81.35% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...a/broker/dispatcher/impl/RecordDispatcherImpl.java 89.59% <100.00%> (ø)
...venting/kafka/broker/core/tracing/TracingSpan.java 90.90% <0.00%> (ø)
...atcher/impl/filter/subscriptionsapi/NotFilter.java 100.00% <0.00%> (ø)
...g/kafka/broker/receiver/impl/ReceiverVerticle.java 97.87% <0.00%> (ø)
...cher/impl/filter/subscriptionsapi/CeSqlFilter.java 100.00% <0.00%> (ø)
...enting/kafka/broker/core/utils/Configurations.java 64.51% <0.00%> (ø)
...ker/core/reconciler/IngressReconcilerListener.java 50.00% <0.00%> (ø)
...ve/eventing/kafka/broker/core/metrics/Metrics.java 76.92% <0.00%> (ø)
...ative/eventing/kafka/broker/dispatcher/Filter.java 100.00% <0.00%> (ø)
... and 64 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 19, 2022
@matzew matzew changed the title WIP: Adding a filter for custom error respnse codes to be added as CE extensions Adding a filter for custom error respnse codes to be added as CE extensions Sep 19, 2022
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 19, 2022
@matzew matzew force-pushed the custom_error_extension_prefix branch from d2e91c3 to 86d702c Compare September 19, 2022 11:42
@matzew matzew force-pushed the custom_error_extension_prefix branch from 6312452 to 9baa960 Compare September 19, 2022 11:48
Signed-off-by: Matthias Wessendorf <[email protected]>
@knative-prow knative-prow bot added area/test size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 19, 2022
Comment on lines 296 to 297
// transform all headers keys to be lowercase and filter by prefix.
// afterwards extract the prefix and add them to the extensions map
Copy link
Member

Choose a reason for hiding this comment

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

The comment isn't true anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pierDipi I updated the comment

Signed-off-by: Matthias Wessendorf <[email protected]>
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Sep 19, 2022
@knative-prow
Copy link

knative-prow bot commented Sep 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: matzew, pierDipi

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

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/cherry-pick release-1.7

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.7 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/cherry-pick release-1.6

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.6 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/retest

1 similar comment
@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/retest

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/test integration-tests

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/test reconciler-tests-namespaced-broker

@matzew
Copy link
Contributor Author

matzew commented Sep 19, 2022

/test channel-integration-tests-sasl-plain

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #2659

In response to this:

/cherry-pick release-1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #2660

In response to this:

/cherry-pick release-1.6

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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/data-plane area/test 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.

Enrich failed events with custom attributes provided via HTTP Response Headers
3 participants