Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
.git/

This file was deleted.

13 changes: 7 additions & 6 deletions function-images/tests/chained-function-eventing/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

FROM vhiveease/golang:latest AS builder
FROM golang:1.16-buster AS builder
WORKDIR /app
RUN apk add --no-cache make
# 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 . ./
COPY . .
WORKDIR /app/function-images/tests/chained-function-eventing
# This is required if the final image is FROM scratch
# See https://forums.docker.com/t/standard-init-linux-go-195-exec-user-process-caused-no-such-file-or-directory/43777/7
ENV CGO_ENABLED=0
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN make bin/${target}

FROM scratch
FROM golang:1.16-buster
WORKDIR /app
ARG target_arg
COPY --from=builder /app/bin/${target_arg} /app/exe
COPY --from=builder /app/function-images/tests/chained-function-eventing/bin/${target_arg} /app/exe
ENTRYPOINT [ "/app/exe" ]
4 changes: 2 additions & 2 deletions function-images/tests/chained-function-eventing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bin/producer: producer/* producer/helloworld_grpc.pb.go producer/helloworld.pb.g

TAG_PRODUCER = vhiveease/chained-functions-eventing-producer:latest
image-producer: Dockerfile bin/producer
docker build --tag ${TAG_PRODUCER} --build-arg target_arg=producer .
docker build --tag ${TAG_PRODUCER} --build-arg target_arg=producer -f ./Dockerfile ../../..

push-producer: image-producer
docker push ${TAG_PRODUCER}
Expand All @@ -48,7 +48,7 @@ bin/consumer: consumer/*

TAG_CONSUMER = vhiveease/chained-functions-eventing-consumer:latest
image-consumer: Dockerfile bin/consumer
docker build --tag ${TAG_CONSUMER} --build-arg target_arg=consumer .
docker build --tag ${TAG_CONSUMER} --build-arg target_arg=consumer -f ./Dockerfile ../../..

push-consumer: image-consumer
docker push ${TAG_CONSUMER}
Expand Down
4 changes: 2 additions & 2 deletions function-images/tests/chained-function-eventing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Manifests are split into separate files and are enumerated in the order of their
**On the master node**, execute the following instructions below:
1. Start a TimeseriesDB experiment:
```bash
./bin/grpcurl -plaintext 10.96.0.84:90 -d @ Timeseries.StartExperiment < ./function-images/tests/chained-function-eventing/ts-experiment.json
./bin/grpcurl -plaintext -d @ 10.96.0.84:90 Timeseries.StartExperiment < ./function-images/tests/chained-function-eventing/ts-experiment.json
```
1. Make a gRPC request:
```bash
./bin/grpcurl -d '{"name": "Bora"}' -plaintext producer.chained-functions-eventing.192.168.1.240.sslip.io:80 helloworld.Greeter.SayHello
./bin/grpcurl -plaintext -d '{"name": "Bora"}' producer.chained-functions-eventing.192.168.1.240.sslip.io:80 helloworld.Greeter.SayHello
```

### Inspecting
Expand Down
47 changes: 46 additions & 1 deletion function-images/tests/chained-function-eventing/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,50 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"reflect"
"unsafe"

cloudevents "github.com/cloudevents/sdk-go/v2"

. "eventing/eventschemas"
tracing "github.com/ease-lab/vhive/utils/tracing/go"
)

func callback(_ context.Context, event cloudevents.Event) (*cloudevents.Event, cloudevents.Result) {
func printContextInternals(ctx interface{}, inner bool) {
contextValues := reflect.ValueOf(ctx).Elem()
contextKeys := reflect.TypeOf(ctx).Elem()

if !inner {
fmt.Printf("\nFields for %s.%s\n", contextKeys.PkgPath(), contextKeys.Name())
}

if contextKeys.Kind() == reflect.Struct {
for i := 0; i < contextValues.NumField(); i++ {
reflectValue := contextValues.Field(i)
reflectValue = reflect.NewAt(reflectValue.Type(), unsafe.Pointer(reflectValue.UnsafeAddr())).Elem()

reflectField := contextKeys.Field(i)

if reflectField.Name == "Context" {
printContextInternals(reflectValue.Interface(), true)
} else {
fmt.Printf("field name: %+v\n", reflectField.Name)
fmt.Printf("value: %+v\n", reflectValue.Interface())
}
}
} else {
fmt.Printf("context is empty (int)\n")
}
}

func callback(ctx context.Context, event cloudevents.Event) (*cloudevents.Event, cloudevents.Result) {
span := tracing.Span{SpanName: "SayHello", TracerName: "consumer"}
ctx = span.StartSpan(ctx)
defer span.EndSpan()

var body GreetingEventBody
if err := event.DataAs(&body); err != nil {
log.Fatalf("failed to extract CloudEvent data: %s", err)
Expand All @@ -48,10 +84,19 @@ func callback(_ context.Context, event cloudevents.Event) (*cloudevents.Event, c
}

func main() {
zipkinURL := flag.String("zipkin", "http://zipkin.istio-system.svc.cluster.local:9411/api/v2/spans", "zipkin url")
flag.Parse()

log.SetPrefix("Consumer: ")
log.SetFlags(log.Lmicroseconds | log.LUTC)
log.Println("started")

shutdown, err := tracing.InitBasicTracer(*zipkinURL, "consumer")
if err != nil {
log.Fatalln(err)
}
defer shutdown()

ceClient, err := cloudevents.NewClientHTTP()
if err != nil {
log.Fatalf("failed to create a CloudEvents client, %s", err)
Expand Down
7 changes: 6 additions & 1 deletion function-images/tests/chained-function-eventing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ module eventing

go 1.16

replace github.com/ease-lab/vhive/utils/tracing/go => ../../../utils/tracing/go

require (
github.com/cloudevents/sdk-go/observability/opencensus/v2 v2.4.1
github.com/cloudevents/sdk-go/v2 v2.4.1
github.com/containerd/containerd v1.5.2
github.com/golang/protobuf v1.5.2
github.com/ease-lab/vhive/utils/tracing/go v0.0.0-00010101000000-000000000000
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.2.0
github.com/kelseyhightower/envconfig v1.4.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
)
Loading