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

Delivery Format: set kn-ingress-format ce extension on mt channel based broker ingress #8075

Closed
Cali0707 opened this issue Jul 4, 2024 · 5 comments
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature-request triage/accepted Issues which should be fixed (post-triage)

Comments

@Cali0707
Copy link
Member

Cali0707 commented Jul 4, 2024

Problem
To support dispatching events from the MTChannelBasedBroker with the correct format when a user sets the spec.delivery.format to ingress, we need to set a cloudevent extension of kn-ingress-format to specify which format was used. This should be set to structured if the input event was structured, and binary if the input event was in binary. However, since this event may have been forwarded from earlier ingress, we need to only set the kn-ingress-format extension if it is not already present on the event.

Persona:
Which persona is this feature for?

Exit Criteria
Unit tests verifying that:

  1. If the extension is not present it is set correctly for both structured and binary events
  2. If the extension is already present, it is not changed for both structured and binary events

Time Estimate (optional):
How many developer-days do you think this may take to resolve? 1-2

Additional context (optional)
Add any other context about the feature request here.

  • The parent issue is: Delivery Format: support specifying the event format #8057
  • The broker ingress handler code is here:
    func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
    writer.Header().Set("Allow", "POST, OPTIONS")
    // validate request method
    if request.Method == http.MethodOptions {
    writer.Header().Set("WebHook-Allowed-Origin", "*") // Accept from any Origin:
    writer.Header().Set("WebHook-Allowed-Rate", "*") // Unlimited requests/minute
    writer.WriteHeader(http.StatusOK)
    return
    }
    if request.Method != http.MethodPost {
    h.Logger.Warn("unexpected request method", zap.String("method", request.Method))
    writer.WriteHeader(http.StatusMethodNotAllowed)
    return
    }
    // validate request URI
    if request.RequestURI == "/" {
    writer.WriteHeader(http.StatusNotFound)
    return
    }
    nsBrokerName := strings.Split(strings.TrimSuffix(request.RequestURI, "/"), "/")
    if len(nsBrokerName) != 3 {
    h.Logger.Info("Malformed uri", zap.String("URI", request.RequestURI))
    writer.WriteHeader(http.StatusBadRequest)
    return
    }
    ctx := h.withContext(request.Context())
    message := cehttp.NewMessageFromHttpRequest(request)
    defer message.Finish(nil)
    event, err := binding.ToEvent(ctx, message)
    if err != nil {
    h.Logger.Warn("failed to extract event from request", zap.Error(err))
    writer.WriteHeader(http.StatusBadRequest)
    return
    }
    // run validation for the extracted event
    validationErr := event.Validate()
    if validationErr != nil {
    h.Logger.Warn("failed to validate extracted event", zap.Error(validationErr))
    writer.WriteHeader(http.StatusBadRequest)
    return
    }
    brokerNamespace := nsBrokerName[1]
    brokerName := nsBrokerName[2]
    brokerNamespacedName := types.NamespacedName{
    Name: brokerName,
    Namespace: brokerNamespace,
    }
    broker, err := h.getBroker(brokerName, brokerNamespace)
    if err != nil {
    h.Logger.Warn("Failed to retrieve broker", zap.Error(err))
    writer.WriteHeader(http.StatusBadRequest)
    return
    }
    features := feature.FromContext(ctx)
    if features.IsOIDCAuthentication() {
    h.Logger.Debug("OIDC authentication is enabled")
    err = h.tokenVerifier.VerifyJWTFromRequest(ctx, request, broker.Status.Address.Audience, writer)
    if err != nil {
    h.Logger.Warn("Error when validating the JWT token in the request", zap.Error(err))
    return
    }
    h.Logger.Debug("Request contained a valid JWT. Continuing...")
    }
    ctx, span := trace.StartSpan(ctx, tracing.BrokerMessagingDestination(brokerNamespacedName))
    defer span.End()
    if span.IsRecordingEvents() {
    span.AddAttributes(
    tracing.MessagingSystemAttribute,
    tracing.MessagingProtocolHTTP,
    tracing.BrokerMessagingDestinationAttribute(brokerNamespacedName),
    tracing.MessagingMessageIDAttribute(event.ID()),
    )
    span.AddAttributes(opencensusclient.EventTraceAttributes(event)...)
    }
    reporterArgs := &ReportArgs{
    ns: brokerNamespace,
    broker: brokerName,
    eventType: event.Type(),
    }
    if request.TLS != nil {
    reporterArgs.eventScheme = "https"
    } else {
    reporterArgs.eventScheme = "http"
    }
    statusCode, dispatchTime := h.receive(ctx, utils.PassThroughHeaders(request.Header), event, broker)
    if dispatchTime > kncloudevents.NoDuration {
    _ = h.Reporter.ReportEventDispatchTime(reporterArgs, statusCode, dispatchTime)
    }
    _ = h.Reporter.ReportEventCount(reporterArgs, statusCode)
    writer.WriteHeader(statusCode)
    // EventType auto-create feature handling
    if h.EvenTypeHandler != nil {
    h.EvenTypeHandler.AutoCreateEventType(ctx, event, toKReference(broker), broker.GetUID())
    }
    }
@Cali0707
Copy link
Member Author

Cali0707 commented Jul 4, 2024

/good-first-issue

Copy link

knative-prow bot commented Jul 4, 2024

@Cali0707:
This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-good-first-issue command.

In response to this:

/good-first-issue

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-sigs/prow repository.

@knative-prow knative-prow bot added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Jul 4, 2024
@Cali0707 Cali0707 added the triage/accepted Issues which should be fixed (post-triage) label Jul 4, 2024
@ckcd
Copy link
Contributor

ckcd commented Jul 5, 2024

@Cali0707 may I take this?

@rahulii
Copy link
Contributor

rahulii commented Jul 5, 2024

/assign

@Cali0707
Copy link
Member Author

Cali0707 commented Jul 9, 2024

/close

Hey @rahulii we have made some changes to the design of the larger feature and this issue is no longer needed. Feel free to pick up another open issue and ask us for help on slack. Same goes for you @ckcd - if you want to work on any open unassigned issues all you need to do is comments /assign on the issue

@Cali0707 Cali0707 closed this as completed Jul 9, 2024
@pierDipi pierDipi moved this from Ready to Done in Eventing Delivery Format Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature-request triage/accepted Issues which should be fixed (post-triage)
Projects
Development

No branches or pull requests

3 participants