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

Add usable fields to error queue #167

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws-kinesis-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.13
v0.14
2 changes: 1 addition & 1 deletion aws-sqs-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.14
v0.15
74 changes: 62 additions & 12 deletions common/util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package common

import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
Expand All @@ -14,16 +16,35 @@ import (
"go.uber.org/zap"
)

// ConnectorMetadata contains common fields used by connectors
type ConnectorMetadata struct {
Topic string
ResponseTopic string
ErrorTopic string
HTTPEndpoint string
MaxRetries int
ContentType string
SourceName string
}
type (
// ConnectorMetadata contains common fields used by connectors
ConnectorMetadata struct {
Topic string
ResponseTopic string
ErrorTopic string
HTTPEndpoint string
MaxRetries int
ContentType string
SourceName string
}

Request struct {
Message string
HTTPEndpoint string
Headers http.Header
}

Response struct {
ResponseBody string
StatusCode int
ErrorString string
}

ErrorResponse struct {
Request Request
sanketsudake marked this conversation as resolved.
Show resolved Hide resolved
Response Response
}
)

// ParseConnectorMetadata parses connector side common fields and returns as ConnectorMetadata or returns error
func ParseConnectorMetadata() (ConnectorMetadata, error) {
Expand Down Expand Up @@ -87,12 +108,41 @@ func HandleHTTPRequest(message string, headers http.Header, data ConnectorMetada
}
}

errResp := ErrorResponse{
sanketsudake marked this conversation as resolved.
Show resolved Hide resolved
Request: Request{
Message: message,
HTTPEndpoint: data.HTTPEndpoint,
Headers: headers,
},
Response: Response{
ResponseBody: "",
StatusCode: http.StatusInternalServerError,
ErrorString: "",
},
}

if resp == nil {
return nil, fmt.Errorf("every function invocation retry failed; final retry gave empty response. http_endpoint: %v, source: %v", data.HTTPEndpoint, data.SourceName)
errResp.Response.ErrorString = fmt.Sprintf("every function invocation retry failed; final retry gave empty response. http_endpoint: %s, source: %s", data.HTTPEndpoint, data.SourceName)
errorBytes, err := json.Marshal(errResp)
if err != nil {
return nil, fmt.Errorf("failed marshalling error response. http_endpoint: %s, source: %s", data.HTTPEndpoint, data.SourceName)
}
return nil, errors.New(string(errorBytes))
}

if resp.StatusCode < 200 || resp.StatusCode > 300 {
return nil, fmt.Errorf("request returned failure: %v. http_endpoint: %v, source: %v", resp.StatusCode, data.HTTPEndpoint, data.SourceName)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed reading response body. http_endpoint: %s, source: %s", data.HTTPEndpoint, data.SourceName)
}
errResp.Response.ResponseBody = string(body)
errResp.Response.StatusCode = resp.StatusCode
errResp.Response.ErrorString = fmt.Sprintf("request returned failure: %d. http_endpoint: %s, source: %s", resp.StatusCode, data.HTTPEndpoint, data.SourceName)
errorBytes, err := json.Marshal(errResp)
if err != nil {
return nil, fmt.Errorf("failed marshalling error response. http_endpoint: %s, source: %s", data.HTTPEndpoint, data.SourceName)
}
return nil, errors.New(string(errorBytes))
}
return resp, nil
}
Expand Down
2 changes: 1 addition & 1 deletion gcp-pubsub-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.9
v0.10
2 changes: 1 addition & 1 deletion kafka-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.15
v0.16
2 changes: 1 addition & 1 deletion nats-jetstream-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.7
v0.8
2 changes: 1 addition & 1 deletion nats-streaming-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.16
v0.17
2 changes: 1 addition & 1 deletion rabbitmq-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.13
v0.14
2 changes: 1 addition & 1 deletion redis-http-connector/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.6
v0.7