This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add Subscription prober Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Fix endpoints informer in cons. KafkaChannel controller * Fix unittests after adding status prober Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Format and order go imports in cons. channel controller Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Rename import alias and remove unused variable Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Add dispatcher prober test for tesitng a single pod Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Support probing dispatchers for multiple partitions kafka channels Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Update deps Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Fix conumer handler test Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * remove unused hashes from status probing test Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Apply review comments and add a prober test Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Remove old comment Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Fix fake status manager Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Return error if IsReady returns an error Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Change probing to be partition based and fix some corner cases of channel deletion * Change cleanup logic to clean ready subscriptions only Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com> * Remove cleanup to avaid consumers race Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
- Loading branch information
Showing
51 changed files
with
2,374 additions
and
857 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
pkg/channel/consolidated/dispatcher/consumer_message_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright 2021 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package dispatcher | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/Shopify/sarama" | ||
protocolkafka "github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2" | ||
"github.com/cloudevents/sdk-go/v2/binding" | ||
"go.uber.org/zap" | ||
"knative.dev/eventing-kafka/pkg/common/consumer" | ||
"knative.dev/eventing-kafka/pkg/common/tracing" | ||
eventingchannels "knative.dev/eventing/pkg/channel" | ||
) | ||
|
||
type consumerMessageHandler struct { | ||
logger *zap.SugaredLogger | ||
sub Subscription | ||
dispatcher *eventingchannels.MessageDispatcherImpl | ||
kafkaSubscription *KafkaSubscription | ||
consumerGroup string | ||
} | ||
|
||
var _ consumer.KafkaConsumerHandler = (*consumerMessageHandler)(nil) | ||
|
||
func (c consumerMessageHandler) GetConsumerGroup() string { | ||
return c.consumerGroup | ||
} | ||
|
||
func (c consumerMessageHandler) SetReady(partition int32, ready bool) { | ||
c.kafkaSubscription.SetReady(c.sub.UID, partition, ready) | ||
} | ||
|
||
func (c consumerMessageHandler) Handle(ctx context.Context, consumerMessage *sarama.ConsumerMessage) (bool, error) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
c.logger.Warn("Panic happened while handling a message", | ||
zap.String("topic", consumerMessage.Topic), | ||
zap.Any("panic value", r), | ||
) | ||
} | ||
}() | ||
message := protocolkafka.NewMessageFromConsumerMessage(consumerMessage) | ||
if message.ReadEncoding() == binding.EncodingUnknown { | ||
return false, errors.New("received a message with unknown encoding") | ||
} | ||
|
||
c.logger.Debug("Going to dispatch the message", | ||
zap.String("topic", consumerMessage.Topic), | ||
zap.String("subscription", c.sub.String()), | ||
) | ||
|
||
ctx, span := tracing.StartTraceFromMessage(c.logger, ctx, message, consumerMessage.Topic) | ||
defer span.End() | ||
|
||
_, err := c.dispatcher.DispatchMessageWithRetries( | ||
ctx, | ||
message, | ||
nil, | ||
c.sub.Subscriber, | ||
c.sub.Reply, | ||
c.sub.DeadLetter, | ||
c.sub.RetryConfig, | ||
) | ||
|
||
// NOTE: only return `true` here if DispatchMessage actually delivered the message. | ||
return err == nil, err | ||
} |
Oops, something went wrong.