From abfd0b542bad64152de7f3a0f48280cb5312a493 Mon Sep 17 00:00:00 2001 From: Michal M Date: Mon, 7 Jun 2021 11:03:27 +0100 Subject: [PATCH] invoker support, updates ports, workflows, docker Client returns a fatal error if communication with the producer fails Producer now has lite-producer functionality if the flag is used Lite producer is removed. changes producer to work with examples invoker Updates dockerfile to use target arg Changes defualt ports general cleanup Removes environment variables adds serving images to CI/CD updates dependabot updates workflows to use grpcurl removes logs Signed-off-by: Michal Baczun --- .github/dependabot.yml | 6 + .github/workflows/build_docker_images.yml | 16 +-- ...ole_chain.yml => function-composition.yml} | 55 ++++---- .github/workflows/image_build.yml | 24 ++++ CHANGELOG.md | 1 + configs/.wordlist.txt | 1 + .../tests/chained-function-serving/Dockerfile | 55 ++------ .../{service.yaml => Makefile} | 68 +++++---- .../chained-function-serving/client/client.go | 56 -------- .../consumer/consumer.go | 27 +--- .../docker-compose.yml | 17 ++- .../tests/chained-function-serving/go.mod | 1 + .../tests/chained-function-serving/go.sum | 6 + .../lite-producer/lite-producer.go | 87 ------------ .../producer/producer.go | 130 +++++------------- .../service-lite-producer.yaml | 18 --- .../service-producer.yaml | 7 +- 17 files changed, 156 insertions(+), 419 deletions(-) rename .github/workflows/{uBench_whole_chain.yml => function-composition.yml} (62%) rename function-images/tests/chained-function-serving/{service.yaml => Makefile} (52%) delete mode 100644 function-images/tests/chained-function-serving/client/client.go delete mode 100644 function-images/tests/chained-function-serving/lite-producer/lite-producer.go delete mode 100644 function-images/tests/chained-function-serving/service-lite-producer.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f1b219b47..1bcb49d39 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,9 @@ updates: directory: "/" schedule: interval: "weekly" + +updates: + - package-ecosystem: “gomod” + directory: “/function-images/tests/chained-function-serving” + schedule: + interval: “weekly” \ No newline at end of file diff --git a/.github/workflows/build_docker_images.yml b/.github/workflows/build_docker_images.yml index 01881f6dd..1367cfcfa 100644 --- a/.github/workflows/build_docker_images.yml +++ b/.github/workflows/build_docker_images.yml @@ -43,18 +43,4 @@ jobs: git lfs pull - name: docker build images run: | - DOCKER_BUILDKIT=1 docker build --file ./scripts/github_runner/Dockerfile.${{ matrix.image }} . - compose_images: - name: Build docker-compose function images - runs-on: ubuntu-18.04 - strategy: - fail-fast: false - matrix: - image: [tests/producer-consumer] - steps: - - uses: actions/checkout@v2 - - name: docker-compose build images - run: | - cd ./function-images/${{ matrix.image }} - docker-compose up -d - + DOCKER_BUILDKIT=1 docker build --file ./scripts/github_runner/Dockerfile.${{ matrix.image }} . \ No newline at end of file diff --git a/.github/workflows/uBench_whole_chain.yml b/.github/workflows/function-composition.yml similarity index 62% rename from .github/workflows/uBench_whole_chain.yml rename to .github/workflows/function-composition.yml index c87f1c1fb..2bfaa9dd8 100644 --- a/.github/workflows/uBench_whole_chain.yml +++ b/.github/workflows/function-composition.yml @@ -1,11 +1,10 @@ -name: Test the entire build and invokation chain of test examples. +name: Function composition tests on: workflow_dispatch: push: branches: [ main ] pull_request: - # The branches below must be a subset of the branches above branches: [ main ] env: @@ -13,29 +12,31 @@ env: GO111MODULE: on jobs: - compose_images: - name: Build and run chained functions serving + docker-compose: + name: Serving uBench (docker-compose) runs-on: ubuntu-18.04 strategy: fail-fast: false steps: - uses: actions/checkout@v2 - - name: go mod tidy + + - name: Setup grpcurl run: | - cd ./function-images/tests/chained-function-serving/ - go mod tidy + wget -qO- https://github.com/fullstorydev/grpcurl/releases/download/v1.8.1/grpcurl_1.8.1_linux_x86_64.tar.gz | sudo tar -C /usr/bin/ -xz grpcurl + - name: start multi-container program with docker-compose run: | cd ./function-images/tests/chained-function-serving/ - docker-compose up -d + docker-compose up &> log_file & sleep 15s - - name: invoke the client + - name: invoke the chain run: | - cd ./function-images/tests/chained-function-serving/ - go run ./client/client.go + grpcurl -plaintext localhost:3031 helloworld.Greeter.SayHello + - name: show docker-compose log + run: cat ./function-images/tests/chained-function-serving/log_file - knative_chain: - name: Start up and run the knative chain + knative: + name: Serving uBench (knative) env: GITHUB_RUN_ID: ${{ github.run_id }} LOGPATH: /tmp/uBench-logs/${{ github.run_id }} @@ -46,7 +47,7 @@ jobs: fail-fast: false steps: - - name: Set up Go 1.15 + - name: Set up Golang uses: actions/setup-go@v2 with: go-version: 1.15 @@ -63,36 +64,30 @@ jobs: - uses: actions/checkout@v2 - - name: start containerd + - name: Start containerd run: sudo containerd 1>$LOGPATH/uBench.out 2>$LOGPATH/uBench.err & - - name: start one node cluster + - name: Start one-node cluster run : | ./scripts/cluster/create_one_node_cluster.sh stock-only && sleep 2m - - name: check pods - run : KUBECONFIG=/etc/kubernetes/admin.conf kubectl get pods -A - - - name: start consumer + - name: Start consumer run: KUBECONFIG=/etc/kubernetes/admin.conf kn service apply -f ./function-images/tests/chained-function-serving/service-consumer.yaml && sleep 30s - - name: start producer + - name: Start producer run: KUBECONFIG=/etc/kubernetes/admin.conf kn service apply -f ./function-images/tests/chained-function-serving/service-producer.yaml && sleep 30s - - name: show services - run: KUBECONFIG=/etc/kubernetes/admin.conf kn service list - - - name: run client + - name: Run invoker client run: | - cd ./function-images/tests/chained-function-serving/client + echo "producer.default.192.168.1.240.sslip.io" > urls.txt + cd ./examples/invoker go build client.go - cd .. - ./client/client --addr producer.default.192.168.1.240.nip.io --pc 80 -s 3 - + cd ../.. + ./examples/invoker/client - name: Archive log artifacts uses: actions/upload-artifact@v2 with: - name: test_file + name: logs path: /tmp/uBench-logs/${{ github.run_id }} - name: Cleaning diff --git a/.github/workflows/image_build.yml b/.github/workflows/image_build.yml index ff4c24086..649cab275 100644 --- a/.github/workflows/image_build.yml +++ b/.github/workflows/image_build.yml @@ -46,3 +46,27 @@ jobs: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.VHIVE_GOLANG_VERSION }} + chained_serving: + name: Deploy chained serving images + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + steps: + + - uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + run: | + cd ./function-images/tests/chained-function-serving + make all-image + make all-image-push diff --git a/CHANGELOG.md b/CHANGELOG.md index d434446e0..cf506d372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added [script](./scripts/cloudlab/start_onenode_vhive_cluster.sh) to (re)start vHive single node cluster in a push-button. - CRI test logs are now stored as GitHub artifacts. - Added Knative Eventing Tutorial: [documentation](./docs/knative/eventing.md) and [example](./examples/knative-eventing-tutorial). +- Added a chained functions microbenchmark that uses Knative Serving. ### Changed diff --git a/configs/.wordlist.txt b/configs/.wordlist.txt index fc1d3d02d..d7c740d4e 100644 --- a/configs/.wordlist.txt +++ b/configs/.wordlist.txt @@ -228,6 +228,7 @@ Micheli Microarchitecting microarchitectural Microarchitecture +microbenchmark microVMs minio MinIO diff --git a/function-images/tests/chained-function-serving/Dockerfile b/function-images/tests/chained-function-serving/Dockerfile index 2088b55d7..c092085e2 100644 --- a/function-images/tests/chained-function-serving/Dockerfile +++ b/function-images/tests/chained-function-serving/Dockerfile @@ -20,50 +20,23 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -FROM amd64/golang:1.16.4-alpine3.13 as consumerBuilder +FROM vhiveease/golang:latest as builder WORKDIR /app -COPY go.mod /app/go.mod -COPY consumer/ /app/consumer/ -COPY proto/ /app/proto/ -RUN go mod download && \ - CGO_ENABLED=0 GOOS=linux go build -v -o /main /app/consumer/consumer.go +RUN apk add --no-cache make +# We use ARG and ENV to have a single Dockerfile for the all three programs. +# https://vsupalov.com/docker-build-pass-environment-variables/ +ARG target_arg +ENV target=$target_arg +COPY . ./ RUN mkdir /log - -FROM amd64/golang:1.16.4-alpine3.13 as consumer -WORKDIR / -COPY --from=consumerBuilder /main /main -COPY --from=consumerBuilder /log/ /log/ -ENTRYPOINT [ "/main" ] - -FROM amd64/golang:1.16.4-alpine3.13 as producerBuilder - -WORKDIR /app -COPY go.mod /app/go.mod -COPY producer/ /app/producer/ -COPY proto/ /app/proto/ RUN go mod download && \ - CGO_ENABLED=0 GOOS=linux go build -v -o /main /app/producer/producer.go -RUN mkdir /log - -FROM amd64/golang:1.16.4-alpine3.13 as producer -WORKDIR / -COPY --from=producerBuilder /main /main -COPY --from=producerBuilder /log/ /log/ -ENTRYPOINT [ "/main" ] - -FROM amd64/golang:1.16.4-alpine3.13 as lite-producerBuilder + CGO_ENABLED=0 GOOS=linux go build -v -o ./${target}-bin ./${target}/ +FROM scratch WORKDIR /app -COPY go.mod /app/go.mod -COPY lite-producer/ /app/lite-producer/ -COPY proto/ /app/proto/ -RUN go mod download && \ - CGO_ENABLED=0 GOOS=linux go build -v -o /main /app/lite-producer/lite-producer.go -RUN mkdir /log - -FROM amd64/golang:1.16.4-alpine3.13 as lite-producer -WORKDIR / -COPY --from=lite-producerBuilder /main /main -COPY --from=lite-producerBuilder /log/ /log/ -ENTRYPOINT [ "/main" ] \ No newline at end of file +ARG target_arg +ENV target=$target_arg +COPY --from=builder /log/ /app/log/ +COPY --from=builder /app/${target}-bin /app/exe +ENTRYPOINT [ "/app/exe" ] diff --git a/function-images/tests/chained-function-serving/service.yaml b/function-images/tests/chained-function-serving/Makefile similarity index 52% rename from function-images/tests/chained-function-serving/service.yaml rename to function-images/tests/chained-function-serving/Makefile index 0f716e039..146cb100e 100644 --- a/function-images/tests/chained-function-serving/service.yaml +++ b/function-images/tests/chained-function-serving/Makefile @@ -20,40 +20,34 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - name: consumer - namespace: default -spec: - template: - spec: - containers: - - image: docker.io/vhiveease/chained-functions-serving-consumer:latest - imagePullPolicy: Always - ports: - # For `h2c`, see https://knative.tips/networking/http2/ - - name: h2c - containerPort: 80 - - -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - name: producer - namespace: default -spec: - template: - spec: - containers: - - image: docker.io/vhiveease/chained-functions-serving-producer:latest - imagePullPolicy: Always - ports: - # For `h2c`, see https://knative.tips/networking/http2/ - - name: h2c - containerPort: 80 - env: - - name: ADDR - value: "localhost" - - name: PORT_CLIENT - value: "80" \ No newline at end of file +all: all-image + +all-image: producer-image consumer-image + +all-image-push: producer-image-push consumer-image-push + +clean: + rm -f ./producer-bin ./consumer-bin + + +producer-image: Dockerfile producer/producer.go proto/prodcon.pb.go proto/prodcon_grpc.pb.go + docker build --tag vhiveease/chained-functions-serving-producer:latest --build-arg target_arg=producer . + +producer-image-push: producer-image + docker push vhiveease/chained-functions-serving-producer:latest + + +consumer-image: Dockerfile consumer/consumer.go proto/prodcon.pb.go proto/prodcon_grpc.pb.go + docker build --tag vhiveease/chained-functions-serving-consumer:latest --build-arg target_arg=consumer . + +consumer-image-push: consumer-image + docker push vhiveease/chained-functions-serving-consumer:latest + + +cmd/server/tempReader_grpc.pb.go cmd/server/tempReader.pb.go: cmd/server/tempReader.proto + protoc \ + --go_out=. \ + --go_opt="paths=source_relative" \ + --go-grpc_out=. \ + --go-grpc_opt="paths=source_relative" \ + cmd/server/tempReader.proto \ No newline at end of file diff --git a/function-images/tests/chained-function-serving/client/client.go b/function-images/tests/chained-function-serving/client/client.go deleted file mode 100644 index c93fcc500..000000000 --- a/function-images/tests/chained-function-serving/client/client.go +++ /dev/null @@ -1,56 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 Michal Baczun and EASE lab -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package main - -import ( - "context" - "flag" - "fmt" - "log" - - "google.golang.org/grpc" - - pb "tests/chained-functions-serving/proto" -) - -func main() { - strings := flag.Int("s", 1, "Number of strings to send") - address := flag.String("addr", "localhost", "Server IP address") - clientPort := flag.Int("pc", 3031, "Client Port") - flag.Parse() - - fmt.Printf("Client using address: %v\n", *address) - - conn, err := grpc.Dial(fmt.Sprintf("%v:%v", *address, *clientPort), grpc.WithInsecure()) - if err != nil { - log.Fatalf("fail to dial: %s", err) - } - defer conn.Close() - - client := pb.NewClientProducerClient(conn) - empty, err := client.ProduceStrings(context.Background(), &pb.ProduceStringsRequest{Value: int32(*strings)}) - fmt.Printf("Client output: %v, %v\n",empty, err) - - fmt.Printf("client closing\n") - -} diff --git a/function-images/tests/chained-function-serving/consumer/consumer.go b/function-images/tests/chained-function-serving/consumer/consumer.go index 41c9f61cf..7c6b50ae2 100644 --- a/function-images/tests/chained-function-serving/consumer/consumer.go +++ b/function-images/tests/chained-function-serving/consumer/consumer.go @@ -30,7 +30,6 @@ import ( "log" "net" "os" - "strconv" "google.golang.org/grpc" @@ -60,31 +59,13 @@ func (s *consumerServer) ConsumeStream(stream pb.ProducerConsumer_ConsumeStreamS } func main() { - portFlag := flag.Int("p", 3030, "Port") + port := flag.Int("ps", 80, "Port") flag.Parse() - //get client port (from env of flag) - var port int - portStr, ok := os.LookupEnv("PORT") - if !ok { - port = *portFlag - } else { - var err error - port, err = strconv.Atoi(portStr) - if err != nil { - log.Fatalf("[producer] PORT_CLIENT env variable is not int: %v", err) - } - } - - //set up log file - file, err := os.OpenFile("log/logs.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - log.Fatal(err) - } - log.SetOutput(file) + log.SetOutput(os.Stdout) //set up server - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { log.Fatalf("[consumer] failed to listen: %v", err) } @@ -93,7 +74,7 @@ func main() { s := consumerServer{} pb.RegisterProducerConsumerServer(grpcServer, &s) - log.Println("[consumer] Server Started") + log.Printf("[consumer] Server Started on port %v\n", *port) if err := grpcServer.Serve(lis); err != nil { log.Fatalf("[consumer] failed to serve: %s", err) diff --git a/function-images/tests/chained-function-serving/docker-compose.yml b/function-images/tests/chained-function-serving/docker-compose.yml index 6836a8111..1186a76d7 100644 --- a/function-images/tests/chained-function-serving/docker-compose.yml +++ b/function-images/tests/chained-function-serving/docker-compose.yml @@ -24,23 +24,22 @@ version: "3.7" services: consumer: - build: - context: . - target: consumer + image: vhiveease/chained-functions-serving-consumer volumes: - log-volume:/log + command: + - -ps=3030 producer: - build: - context: . - target: producer + image: vhiveease/chained-functions-serving-producer ports: - "3031:3031" volumes: - log-volume:/log - environment: - - ADDR=consumer - # command: go run ./producer/producer.go --addr consumer + command: + - -addr=consumer + - -ps=3031 + - -pc=3030 depends_on: - consumer diff --git a/function-images/tests/chained-function-serving/go.mod b/function-images/tests/chained-function-serving/go.mod index 7e791bac3..4e93d6539 100644 --- a/function-images/tests/chained-function-serving/go.mod +++ b/function-images/tests/chained-function-serving/go.mod @@ -5,6 +5,7 @@ go 1.16 replace tests/chained-functions-serving/proto => ./proto require ( + github.com/ease-lab/vhive/examples/protobuf/helloworld v0.0.0-20210608114032-dab7e310da45 google.golang.org/grpc v1.38.0 google.golang.org/protobuf v1.26.0 ) diff --git a/function-images/tests/chained-function-serving/go.sum b/function-images/tests/chained-function-serving/go.sum index e90524b2d..2e0ad3fe0 100644 --- a/function-images/tests/chained-function-serving/go.sum +++ b/function-images/tests/chained-function-serving/go.sum @@ -2,16 +2,21 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/ease-lab/vhive/examples/protobuf/helloworld v0.0.0-20210608114032-dab7e310da45 h1:f8vS9Oq4p8TNAyfoO4ofU9WG89s2ZqcGoukaTAPqIUU= +github.com/ease-lab/vhive/examples/protobuf/helloworld v0.0.0-20210608114032-dab7e310da45/go.mod h1:bNnZ10sO0BckLSXqJApgv7acqM7xxTHtcHu95+/Myss= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -68,6 +73,7 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= diff --git a/function-images/tests/chained-function-serving/lite-producer/lite-producer.go b/function-images/tests/chained-function-serving/lite-producer/lite-producer.go deleted file mode 100644 index d7702553b..000000000 --- a/function-images/tests/chained-function-serving/lite-producer/lite-producer.go +++ /dev/null @@ -1,87 +0,0 @@ -// MIT License -// -// Copyright (c) 2021 Michal Baczun and EASE lab -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package main - -import ( - "context" - "flag" - "fmt" - "log" - "net" - "os" - "strconv" - - "google.golang.org/grpc" - - pb "tests/chained-functions-serving/proto" -) - -type producerServer struct { - pb.UnimplementedClientProducerServer -} - -func (ps *producerServer) ProduceStrings(c context.Context, count *pb.ProduceStringsRequest) (*pb.Empty, error) { - log.Println("client successful call") - return new(pb.Empty), nil -} - -func main() { - flagServerPort := flag.Int("ps", 3031, "Server Port") - flag.Parse() - - var serverPort int - serverPortStr, ok := os.LookupEnv("PORT") - if !ok { - serverPort = *flagServerPort - } else { - var err error - serverPort, err = strconv.Atoi(serverPortStr) - if err != nil { - log.Fatalf("[producer] PORT env variable is not int: %v", err) - } - } - - //set up log file - file, err := os.OpenFile("log/logs.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - log.Fatal(err) - } - log.SetOutput(file) - - //server setup - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", serverPort)) - if err != nil { - log.Fatalf("[producer] failed to listen: %v", err) - } - - grpcServer := grpc.NewServer() - s := producerServer{} - pb.RegisterClientProducerServer(grpcServer, &s) - - log.Println("[producer] Server Started") - - if err := grpcServer.Serve(lis); err != nil { - log.Fatalf("[producer] failed to serve: %s", err) - } - -} diff --git a/function-images/tests/chained-function-serving/producer/producer.go b/function-images/tests/chained-function-serving/producer/producer.go index 3c047cb95..ee4f4a3ed 100644 --- a/function-images/tests/chained-function-serving/producer/producer.go +++ b/function-images/tests/chained-function-serving/producer/producer.go @@ -27,134 +27,70 @@ import ( "flag" "fmt" "log" - "math/rand" "net" "os" - "strconv" "google.golang.org/grpc" - pb "tests/chained-functions-serving/proto" -) + "google.golang.org/grpc/reflection" -type producerServer struct { - producerClient pb.ProducerConsumerClient - pb.UnimplementedClientProducerServer -} + pb_client "tests/chained-functions-serving/proto" -func (ps *producerServer) ProduceStrings(c context.Context, count *pb.ProduceStringsRequest) (*pb.Empty, error) { - if count.Value <= 0 { - return new(pb.Empty), nil - } else if count.Value == 1 { - produceSingleString(ps.producerClient, fmt.Sprint(rand.Intn(1000))) - } else { - wordList := make([]string, int(count.Value)) - for i := 0; i < int(count.Value); i++ { - wordList[i] = fmt.Sprint(rand.Intn(1000)) - } - produceStreamStrings(ps.producerClient, wordList) - } - return new(pb.Empty), nil -} + pb "github.com/ease-lab/vhive/examples/protobuf/helloworld" +) -func produceSingleString(client pb.ProducerConsumerClient, s string) { - ack, err := client.ConsumeString(context.Background(), &pb.ConsumeStringRequest{Value: s}) - if err != nil { - log.Fatalf("[producer] client error in string consumption: %s", err) - } - log.Printf("[producer] (single) Ack: %v\n", ack.Value) +type producerServer struct { + consumerAddr string + consumerPort int + pb.UnimplementedGreeterServer } -func produceStreamStrings(client pb.ProducerConsumerClient, strings []string) { - //make stream - stream, err := client.ConsumeStream(context.Background()) +func (ps *producerServer) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.HelloReply, error) { + // establish a connection + conn, err := grpc.Dial(fmt.Sprintf("%v:%v", ps.consumerAddr, ps.consumerPort), grpc.WithInsecure()) if err != nil { - log.Fatalf("[producer] %v.RecordRoute(_) = _, %v", client, err) + log.Fatalf("[producer] fail to dial: %s", err) } + defer conn.Close() - //stream strings - for _, s := range strings { - if err := stream.Send(&pb.ConsumeStringRequest{Value: s}); err != nil { - log.Fatalf("[producer] %v.Send(%v) = %v", stream, s, err) - } - } + client := pb_client.NewProducerConsumerClient(conn) - //end transaction - ack, err := stream.CloseAndRecv() + // send message + ack, err := client.ConsumeString(context.Background(), &pb_client.ConsumeStringRequest{Value: "1"}) if err != nil { - log.Fatalf("[producer] %v.CloseAndRecv() got error %v, want %v", stream, err, nil) + log.Fatalf("[producer] client error in string consumption: %s", err) } - log.Printf("[producer] (stream) Ack: %v\n", ack.Value) + log.Printf("[producer] (single) Ack: %v\n", ack.Value) + return &pb.HelloReply{Message: "Success"}, err } func main() { - flagAddress := flag.String("addr", "localhost", "Server IP address") - flagClientPort := flag.Int("pc", 3030, "Client Port") - flagServerPort := flag.Int("ps", 3031, "Server Port") + flagAddress := flag.String("addr", "consumer.default.192.168.1.240.sslip.io", "Server IP address") + flagClientPort := flag.Int("pc", 80, "Client Port") + flagServerPort := flag.Int("ps", 80, "Server Port") flag.Parse() - //get address (from env or flag) - address, ok := os.LookupEnv("ADDR") - if !ok { - address = *flagAddress - } - var clientPort int - clientPortStr, ok := os.LookupEnv("PORT_CLIENT") - if !ok { - clientPort = *flagClientPort - } else { - var err error - clientPort, err = strconv.Atoi(clientPortStr) - if err != nil { - log.Fatalf("[producer] PORT_CLIENT env variable is not int: %v", err) - } - } - //get client port (from env of flag) - var serverPort int - serverPortStr, ok := os.LookupEnv("PORT") - if !ok { - serverPort = *flagServerPort - } else { - var err error - serverPort, err = strconv.Atoi(serverPortStr) - if err != nil { - log.Fatalf("[producer] PORT env variable is not int: %v", err) - } - } - - //set up log file - file, err := os.OpenFile("log/logs.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - log.Fatal(err) - } - log.SetOutput(file) + log.SetOutput(os.Stdout) - //client setup - log.Printf("[producer] Client using address: %v\n", address) + grpcServer := grpc.NewServer() - conn, err := grpc.Dial(fmt.Sprintf("%v:%v", address, clientPort), grpc.WithInsecure()) - if err != nil { - log.Fatalf("[producer] fail to dial: %s", err) - } - defer conn.Close() + reflection.Register(grpcServer) + // err = grpcServer.Serve(lis) - client := pb.NewProducerConsumerClient(conn) + //client setup + log.Printf("[producer] Client using address: %v\n", *flagAddress) - //produceSingleString(client, "hello") - //strings := []string{"Hello", "World", "one", "two", "three"} - //produceStreamStrings(client, strings) + s := producerServer{} + s.consumerAddr = *flagAddress + s.consumerPort = *flagClientPort + pb.RegisterGreeterServer(grpcServer, &s) //server setup - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", serverPort)) + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *flagServerPort)) if err != nil { log.Fatalf("[producer] failed to listen: %v", err) } - grpcServer := grpc.NewServer() - s := producerServer{} - s.producerClient = client - pb.RegisterClientProducerServer(grpcServer, &s) - log.Println("[producer] Server Started") if err := grpcServer.Serve(lis); err != nil { diff --git a/function-images/tests/chained-function-serving/service-lite-producer.yaml b/function-images/tests/chained-function-serving/service-lite-producer.yaml deleted file mode 100644 index 37cacd35d..000000000 --- a/function-images/tests/chained-function-serving/service-lite-producer.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - name: lite-producer - namespace: default -spec: - template: - spec: - containers: - - image: docker.io/vhiveease/chained-functions-serving-lite-producer:latest - imagePullPolicy: Always - ports: - # For `h2c`, see https://knative.tips/networking/http2/ - - name: h2c - containerPort: 8080 - env: - - name: TARGET - value: "Go Sample v1" \ No newline at end of file diff --git a/function-images/tests/chained-function-serving/service-producer.yaml b/function-images/tests/chained-function-serving/service-producer.yaml index 4327b8f73..42a2dbabe 100644 --- a/function-images/tests/chained-function-serving/service-producer.yaml +++ b/function-images/tests/chained-function-serving/service-producer.yaml @@ -34,9 +34,4 @@ spec: ports: # For `h2c`, see https://knative.tips/networking/http2/ - name: h2c - containerPort: 80 - env: - - name: ADDR - value: "consumer.default.192.168.1.240.nip.io" - - name: PORT_CLIENT - value: "80" \ No newline at end of file + containerPort: 80 \ No newline at end of file