Skip to content

Forward headers starting with Kn-#572

Merged
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
mgencur:forward_kn_namespace
Aug 9, 2023
Merged

Forward headers starting with Kn-#572
knative-prow[bot] merged 1 commit intoknative-extensions:mainfrom
mgencur:forward_kn_namespace

Conversation

@mgencur
Copy link
Copy Markdown
Contributor

@mgencur mgencur commented Aug 9, 2023

The eventshub forwarder should forward headers such as Kn-Namespace.

The sending client automatically adds some headers such as User-Agent and Content-Length. We also don't want to forward tracing-related headers starting with X- and Traceparent. So this feature only forwards specific headers related to Knative.

Changes

/kind

Fixes #

Release Note


Docs


The eventshub forwarder should forward headers such as Kn-Namespace.

The sending client automatically adds some headers such as User-Agent
and Content-Length. We also don't want to forward tracing-related
headers starting with X- and Traceparent. So this feature only forwards
specific headers related to Knative.
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Aug 9, 2023

@mgencur: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

Details

In response to this:

The eventshub forwarder should forward headers such as Kn-Namespace.

The sending client automatically adds some headers such as User-Agent and Content-Length. We also don't want to forward tracing-related headers starting with X- and Traceparent. So this feature only forwards specific headers related to Knative.

Changes

/kind

Fixes #

Release Note


Docs


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 knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 9, 2023
@knative-prow knative-prow bot requested review from psschwei and upodroid August 9, 2023 09:42
@knative-prow knative-prow bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 9, 2023
headers[k] = v
receivedHeaders[k] = v
}
if strings.HasPrefix(k, "Kn-") {
Copy link
Copy Markdown
Contributor Author

@mgencur mgencur Aug 9, 2023

Choose a reason for hiding this comment

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

The other option here would be something like this:

if !strings.HasPrefix(k, "Ce-")&&
  !strings.HasPrefix(k, "X-") &&
  k != "Traceparent" &&
  k != "User-Agent" &&
  k != "Accept-Encoding" &&
  k != "Content-Length" &&
  k != "Host" {
  headersToBeSent[k] = v
}

This would forward everything except for the unwanted ones. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks ok, to forward those, since they have a meaning for us/eventing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

your forward everything except seems also reasonable.
I'd perhaps make that some better code, but yeah.

If this current code works, let's do that, and backport

and than think about future, sounds good?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok. Testing the current solution with forwarding "Kn-*". We can leave any improvements for the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It works! This is logged at my forwarder:

{"level":"info","ts":"2023-08-09T11:33:00.349Z","logger":"eventshub.event logger","caller":"logger_vent/logger.go:26","msg":"Event: \n-- EventInfo --\n--- Kind: Received ---\n--- Event ---\nContext Attributes,\n  specversion: 1.0\n  type: dev.knative.sources.ping\n  source: /apis/v1/namespaces/test-cktbvfkv/pingsources/pingsource-oqvyeqoj\n  id: b2c43312-8767-4d17-af90-55008697dca1\n  time: 2023-08-09T11:33:00.318564821Z\n\n--- HTTP headers ---\n  Accept-Encoding: gzip\n  Forwarded: for=10.128.2.49;proto=http\n  Traceparent: 00-a4aaf20f277d96c1a067e3d478235fed-91af74b9b2d6ad70-00\n  X-Forwarded-For: 10.128.2.49, 10.129.2.53\n  X-Forwarded-Proto: http\n  Content-Length: 0\n  Kn-Namespace: test-cktbvfkv\n  User-Agent: Go-http-client/1.1\n  X-Request-Id: 6d4020dd-fa21-43ee-ae2c-d52751bfacf2\n  K-Proxy-Request: activator\n  Host: sink-krcxpelq.test-cktbvfkv.svc.cluster.local\n\n--- Origin: '127.0.0.1:55982' ---\n--- Observer: 'sink-krcxpelq' ---\n--- Time: 2023-08-09 11:33:00.34908641 +0000 UTC m=+358.441989515 ---\n--- Sequence: 0 ---\n--- Sent Id:  ' ---\n--------------------\n"}
{"level":"info","ts":"2023-08-09T11:33:00.391Z","logger":"eventshub.event logger","caller":"logger_vent/logger.go:26","msg":"Event: \n-- EventInfo --\n--- Kind: Sent ---\n--- Event ---\nContext Attributes,\n  specversion: 1.0\n  type: dev.knative.sources.ping\n  source: /apis/v1/namespaces/test-cktbvfkv/pingsources/pingsource-oqvyeqoj\n  id: b2c43312-8767-4d17-af90-55008697dca1\n  time: 2023-08-09T11:33:00.318564821Z\n\n--- HTTP headers ---\n  Ce-Source: /apis/v1/namespaces/test-cktbvfkv/pingsources/pingsource-oqvyeqoj\n  Ce-Specversion: 1.0\n  Ce-Type: dev.knative.sources.ping\n  Ce-Time: 2023-08-09T11:33:00.318564821Z\n  Kn-Namespace: test-cktbvfkv\n  Ce-Id: b2c43312-8767-4d17-af90-55008697dca1\n\n--- Origin: 'sink-krcxpelq' ---\n--- Observer: 'sink-krcxpelq' ---\n--- Time: 2023-08-09 11:33:00.391297182 +0000 UTC m=+358.484200268 ---\n--- Sequence: 0 ---\n--- Sent Id:  'b2c43312-8767-4d17-af90-55008697dca1 ---\n--------------------\n"}

Copy link
Copy Markdown
Contributor

@matzew matzew 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

/hold

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2023
@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2023
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Aug 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Details 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 knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2023
@mgencur
Copy link
Copy Markdown
Contributor Author

mgencur commented Aug 9, 2023

/cherry-pick release-1.10
/cherry-pick release-1.11

@knative-prow-robot
Copy link
Copy Markdown

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

Details

In response to this:

/cherry-pick release-1.10
/cherry-pick release-1.11

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.

@mgencur mgencur changed the title [WIP] Forward headers starting with Kn- Forward headers starting with Kn- Aug 9, 2023
@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 Aug 9, 2023
@mgencur
Copy link
Copy Markdown
Contributor Author

mgencur commented Aug 9, 2023

/cherry-pick release-1.11

@knative-prow-robot
Copy link
Copy Markdown

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

Details

In response to this:

/cherry-pick release-1.11

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.

@mgencur
Copy link
Copy Markdown
Contributor Author

mgencur commented Aug 9, 2023

/unhold

@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2023
@knative-prow knative-prow bot merged commit 6e00c29 into knative-extensions:main Aug 9, 2023
@knative-prow-robot
Copy link
Copy Markdown

@mgencur: new pull request created: #573

Details

In response to this:

/cherry-pick release-1.10
/cherry-pick release-1.11

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
Copy Markdown

@mgencur: new pull request created: #574

Details

In response to this:

/cherry-pick release-1.11

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. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants