Skip to content

Commit 3615ccb

Browse files
committed
Update internal dependencies
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 10ae9e9 commit 3615ccb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6853
-5011
lines changed

go.mod

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
module github.com/openfaas/nats-queue-worker
22

3-
go 1.16
3+
go 1.18
44

55
require (
6+
github.com/nats-io/stan.go v0.10.4
7+
github.com/openfaas/faas-provider v0.19.1
8+
)
9+
10+
require (
11+
github.com/beorn7/perks v1.0.1 // indirect
12+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
13+
github.com/gogo/protobuf v1.3.2 // indirect
614
github.com/golang/protobuf v1.5.2 // indirect
7-
github.com/nats-io/nats-server/v2 v2.3.2 // indirect
8-
github.com/nats-io/nats-streaming-server v0.22.0 // indirect
9-
github.com/nats-io/stan.go v0.9.0
10-
github.com/openfaas/faas-provider v0.18.6
15+
github.com/gorilla/mux v1.8.0 // indirect
16+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
17+
github.com/nats-io/nats.go v1.22.1 // indirect
18+
github.com/nats-io/nkeys v0.3.0 // indirect
19+
github.com/nats-io/nuid v1.0.1 // indirect
20+
github.com/prometheus/client_golang v1.12.2 // indirect
21+
github.com/prometheus/client_model v0.2.0 // indirect
22+
github.com/prometheus/common v0.32.1 // indirect
23+
github.com/prometheus/procfs v0.7.3 // indirect
24+
golang.org/x/crypto v0.5.0 // indirect
25+
golang.org/x/sys v0.4.0 // indirect
26+
google.golang.org/protobuf v1.26.0 // indirect
1127
)

go.sum

+411
Large diffs are not rendered by default.

handler/handler.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88

99
const sharedQueue = "faas-request"
1010

11-
// CreateNATSQueue ready for asynchronous processing
11+
// CreateNATSQueue ready for asynchronous message processing of paylods of
12+
// up to a maximum of 256KB in size.
1213
func CreateNATSQueue(address string, port int, clusterName, channel string, clientConfig NATSConfig) (*NATSQueue, error) {
1314
var err error
1415
natsURL := fmt.Sprintf("nats://%s:%d", address, port)

handler/nats_queue.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handler
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"log"
67
"sync"
78
"time"
@@ -37,6 +38,10 @@ func (q *NATSQueue) Queue(req *ftypes.QueueRequest) error {
3738
if v := req.Header.Get("X-Call-Id"); len(v) > 0 {
3839
callId = v
3940
}
41+
max := 256 * 1000
42+
if len(req.Body) > max {
43+
return fmt.Errorf("request body too large for OpenFaaS CE (%d bytes), maximum: %d bytes", len(req.Body), 256*1000)
44+
}
4045

4146
log.Printf("[%s] Queueing (%d) bytes for: %s.\n", callId, len(req.Body), req.Function)
4247

main.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"log"
109
"net"
1110
"net/http"
@@ -40,6 +39,8 @@ func main() {
4039
log.Printf("Starting queue-worker (Community Edition). Concurrency: %d\tChannel: %s\tVersion: %s\tGit Commit: %s",
4140
config.MaxInflight, sharedQueue, release, sha)
4241

42+
log.Printf("[Warning] NATS Streaming is deprecated and will be removed in a future release. See: https://www.openfaas.com/blog/jetstream-for-openfaas/")
43+
4344
client := makeClient()
4445

4546
counter := uint64(0)
@@ -99,7 +100,7 @@ func main() {
99100
timeTaken := time.Since(started).Seconds()
100101

101102
if req.CallbackURL != nil {
102-
resultStatusCode, resultErr := postResult(&client,
103+
resultStatusCode, err := postResult(&client,
103104
res,
104105
functionResult,
105106
req.CallbackURL.String(),
@@ -108,8 +109,8 @@ func main() {
108109
req.Function,
109110
timeTaken)
110111

111-
if resultErr != nil {
112-
log.Printf("[#%d] Posted callback to: %s - status %d, error: %s\n", i, req.CallbackURL.String(), http.StatusServiceUnavailable, resultErr.Error())
112+
if err != nil {
113+
log.Printf("[#%d] Posted callback to: %s - status %d, error: %s\n", i, req.CallbackURL.String(), http.StatusServiceUnavailable, err.Error())
113114
} else {
114115
log.Printf("[#%d] Posted result to %s - status: %d", i, req.CallbackURL.String(), resultStatusCode)
115116
}
@@ -121,7 +122,7 @@ func main() {
121122
if res.Body != nil {
122123
defer res.Body.Close()
123124

124-
resData, err := ioutil.ReadAll(res.Body)
125+
resData, err := io.ReadAll(res.Body)
125126
functionResult = resData
126127

127128
if err != nil {
@@ -140,7 +141,7 @@ func main() {
140141
if req.CallbackURL != nil {
141142
log.Printf("[#%d] Callback to: %s\n", i, req.CallbackURL.String())
142143

143-
resultStatusCode, resultErr := postResult(&client,
144+
resultStatusCode, err := postResult(&client,
144145
res,
145146
functionResult,
146147
req.CallbackURL.String(),
@@ -149,8 +150,8 @@ func main() {
149150
req.Function,
150151
timeTaken)
151152

152-
if resultErr != nil {
153-
log.Printf("[#%d] Error posting to callback-url: %s\n", i, resultErr)
153+
if err != nil {
154+
log.Printf("[#%d] Error posting to callback-url: %s\n", i, err)
154155
} else {
155156
log.Printf("[#%d] Posted result for %s to callback-url: %s, status: %d", i, req.Function, req.CallbackURL.String(), resultStatusCode)
156157
}
@@ -177,15 +178,16 @@ func main() {
177178
ackWait: config.AckWait,
178179
}
179180

180-
if initErr := natsQueue.connect(); initErr != nil {
181-
log.Panic(initErr)
181+
if err := natsQueue.connect(); err != nil {
182+
log.Panic(err)
182183
}
183184

184185
// Wait for a SIGINT (perhaps triggered by user with CTRL-C)
185186
// Run cleanup when signal is received
186187
signalChan := make(chan os.Signal, 1)
187188
signal.Notify(signalChan, os.Interrupt)
188189
<-signalChan
190+
189191
fmt.Printf("\nReceived an interrupt, unsubscribing and closing connection...\n\n")
190192
if err := natsQueue.closeConnection(); err != nil {
191193
log.Panicf("Cannot close connection to %s because of an error: %v\n", natsQueue.natsURL, err)
@@ -202,7 +204,6 @@ func makeClient() http.Client {
202204
Timeout: 30 * time.Second,
203205
KeepAlive: 0,
204206
}).DialContext,
205-
206207
MaxIdleConns: 1,
207208
DisableKeepAlives: true,
208209
IdleConnTimeout: 120 * time.Millisecond,
@@ -225,7 +226,6 @@ func postResult(client *http.Client, functionRes *http.Response, result []byte,
225226
}
226227

227228
request, err := http.NewRequest(http.MethodPost, callbackURL, reader)
228-
229229
if err != nil {
230230
return http.StatusInternalServerError, fmt.Errorf("unable to post result, error: %s", err.Error())
231231
}

vendor/github.com/nats-io/nats.go/.gitignore

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/.travis.yml

+16-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/.words

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/.words.readme

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/nats-io/nats.go/README.md

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)