-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: new Mapper example which serves as a slow container for testing purposes #172
Changes from 6 commits
3b0c292
09d7160
f1299c7
ae96c3d
dd1b8c4
09404c6
de00f03
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#################################################################################################### | ||
# base | ||
#################################################################################################### | ||
FROM alpine:3.20 AS base | ||
ARG TARGETARCH | ||
RUN apk update && apk upgrade && \ | ||
apk add ca-certificates && \ | ||
apk --no-cache add tzdata | ||
|
||
COPY dist/cat-sleep-example-${TARGETARCH} /bin/cat-sleep-example | ||
RUN chmod +x /bin/cat-sleep-example | ||
|
||
#################################################################################################### | ||
# cat-sleep | ||
#################################################################################################### | ||
FROM scratch AS cat-sleep | ||
COPY --from=base /usr/share/zoneinfo /usr/share/zoneinfo | ||
COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY --from=base /bin/cat-sleep-example /bin/cat-sleep-example | ||
ENTRYPOINT [ "/bin/cat-sleep-example" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
TAG ?= stable | ||
PUSH ?= false | ||
IMAGE_REGISTRY = quay.io/numaio/numaflow-go/map-cat-sleep:${TAG} | ||
ARCHITECTURES = amd64 arm64 | ||
|
||
.PHONY: build | ||
build: | ||
for arch in $(ARCHITECTURES); do \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=$${arch} go build -v -o ./dist/cat-sleep-example-$${arch} main.go; \ | ||
done | ||
|
||
.PHONY: image-push | ||
image-push: build | ||
docker buildx build -t ${IMAGE_REGISTRY} --platform linux/amd64,linux/arm64 --target cat-sleep . --push | ||
|
||
.PHONY: image | ||
image: build | ||
docker build -t ${IMAGE_REGISTRY} --target cat-sleep . | ||
@if [ "$(PUSH)" = "true" ]; then docker push ${IMAGE_REGISTRY}; fi | ||
|
||
clean: | ||
-rm -rf ./dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Cat with Sleep | ||
|
||
An example User Defined Function that outputs the same value as the input, but first does a sleep. This example is for the purpose of performing testing with a slow vertex. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module even_odd | ||
|
||
go 1.21 | ||
|
||
replace github.com/numaproj/numaflow-go => ../../../.. | ||
|
||
require github.com/numaproj/numaflow-go v0.9.0 | ||
|
||
require ( | ||
golang.org/x/net v0.29.0 // indirect | ||
golang.org/x/sync v0.8.0 // indirect | ||
golang.org/x/sys v0.25.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect | ||
google.golang.org/grpc v1.66.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= | ||
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= | ||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= | ||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= | ||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= | ||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= | ||
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= | ||
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= | ||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= | ||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||
package main | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"log" | ||||||
"os" | ||||||
"strconv" | ||||||
"time" | ||||||
|
||||||
"github.com/numaproj/numaflow-go/pkg/mapper" | ||||||
) | ||||||
|
||||||
const DEFAULT_SLEEP_SECONDS = 10 | ||||||
|
||||||
type CatSleep struct { | ||||||
} | ||||||
|
||||||
func (e *CatSleep) Map(ctx context.Context, keys []string, d mapper.Datum) mapper.Messages { | ||||||
|
||||||
// sleep for as long as the environment variable indicates (or default if not configured) | ||||||
sleepSeconds := DEFAULT_SLEEP_SECONDS | ||||||
secondsString := os.Getenv("SLEEP_SECONDS") | ||||||
if secondsString == "" { | ||||||
log.Printf("SLEEP_SECONDS environment variable not set, using default %d seconds\n", DEFAULT_SLEEP_SECONDS) | ||||||
} else { | ||||||
val, err := strconv.Atoi(secondsString) | ||||||
if err != nil { | ||||||
log.Printf("SLEEP_SECONDS environment variable %q not an int, using default %d seconds\n", secondsString, DEFAULT_SLEEP_SECONDS) | ||||||
} else { | ||||||
sleepSeconds = val | ||||||
} | ||||||
} | ||||||
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. this can be done in main? 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. True. I suppose I can make this purposely slow container more efficient. :D but it would still be neater though, I agree |
||||||
time.Sleep(time.Duration(sleepSeconds) * time.Second) | ||||||
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.
Suggested change
|
||||||
return mapper.MessagesBuilder().Append(mapper.NewMessage(d.Value()).WithKeys(keys)) | ||||||
} | ||||||
|
||||||
func main() { | ||||||
err := mapper.NewServer(&CatSleep{}).Start(context.Background()) | ||||||
if err != nil { | ||||||
log.Panic("Failed to start map function server: ", err) | ||||||
} | ||||||
} |
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.
you could move this inside
CatSleep
?