make controller variables available to kafka trigger #41
base: master
Are you sure you want to change the base?
Changes from 8 commits
15b5abb
65946dc
8f1bc0e
fadc1d8
7a6ad68
19f862b
a60728c
f935316
65bc22d
e59d8b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,12 +20,14 @@ import ( | |||||
"encoding/json" | ||||||
"fmt" | ||||||
"net/http" | ||||||
"strconv" | ||||||
"strings" | ||||||
"time" | ||||||
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
"k8s.io/client-go/kubernetes" | ||||||
|
||||||
"github.com/Shopify/sarama" | ||||||
kubelessutil "github.com/kubeless/kubeless/pkg/utils" | ||||||
) | ||||||
|
||||||
|
@@ -46,8 +48,9 @@ func GetFunctionPort(clientset kubernetes.Interface, namespace, functionName str | |||||
} | ||||||
|
||||||
// GetHTTPReq returns the http request object that can be used to send a event with payload to function service | ||||||
func GetHTTPReq(funcName string, funcPort int, kafkaTopic, namespace, eventNamespace, method, body string) (*http.Request, error) { | ||||||
req, err := http.NewRequest(method, fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", funcName, namespace, funcPort), strings.NewReader(body)) | ||||||
func GetHTTPReq(funcName string, funcPort int, kafkaMessage *sarama.ConsumerMessage, namespace, eventNamespace string) (*http.Request, error) { | ||||||
body := string(kafkaMessage.Value) | ||||||
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", funcName, namespace, funcPort), strings.NewReader(body)) | ||||||
if err != nil { | ||||||
return nil, fmt.Errorf("Unable to create request %v", err) | ||||||
} | ||||||
|
@@ -56,10 +59,16 @@ func GetHTTPReq(funcName string, funcPort int, kafkaTopic, namespace, eventNames | |||||
if err != nil { | ||||||
return nil, fmt.Errorf("Failed to create a event-ID %v", err) | ||||||
} | ||||||
messageTimestamp := kafkaMessage.Timestamp.UTC().Format(time.RFC3339) | ||||||
req.Header.Add("event-id", eventID) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what is the intention of having a n id, which has nothing to do with the message. It's not a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The event id was always present. Are you suggesting it is redundant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but that is @andresmgot call 🤷♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The goal of the eventID was to simply have a unique ID for the message. I would leave it (regardless of its usefulness) to avoid breaking changes. |
||||||
req.Header.Add("event-time", timestamp.String()) | ||||||
uedun marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I was misunderstood. What I had in mind is to use the message timestamp instead of the current time
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sepetrov re There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by adding the more relevant fields and new headers, we keep backwards compat but start putting in more useful info There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true. My suggestions are BC-breaking, because I personally to see any value in current implementation. That is @andresmgot call again. I would be happy to have the new metadata available regardless the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, let's avoid breaking changes if possible. Some functions may rely in the current format. |
||||||
req.Header.Add("event-namespace", eventNamespace) | ||||||
req.Header.Add("event-topic", kafkaTopic) | ||||||
req.Header.Add("event-topic", kafkaMessage.Topic) | ||||||
req.Header.Add("event-partition", strconv.FormatInt(int64(kafkaMessage.Partition), 10)) | ||||||
req.Header.Add("event-offset", strconv.FormatInt(kafkaMessage.Offset, 10)) | ||||||
req.Header.Add("event-key", string(kafkaMessage.Key)) | ||||||
req.Header.Add("event-message-timestamp", messageTimestamp) | ||||||
|
||||||
if IsJSON(body) { | ||||||
req.Header.Add("Content-Type", "application/json") | ||||||
req.Header.Add("event-type", "application/json") | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these changes in the imports order causes a
gofmt
issue, you'd need to set it back: