Skip to content

Commit 8cf89b1

Browse files
Michal Baczunustiugov
authored andcommitted
Adds tracing module
Updates chained serving producer and consumer to use module (temporary) Adds client, modification to the dockerfile and updated main makefile Signed-off-by: Michal Baczun <[email protected]>
1 parent cea81c4 commit 8cf89b1

File tree

13 files changed

+785
-160
lines changed

13 files changed

+785
-160
lines changed

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,22 @@ test-cri:
138138

139139
test-cri-travis: # Testing in travis is deprecated
140140
$(MAKE) -C cri test-travis
141+
142+
serving-all-image: serving-producer-image serving-consumer-image
143+
144+
serving-all-image-push: serving-producer-image-push serving-consumer-image-push
145+
146+
serving-producer-image: ./function-images/tests/chained-function-serving/Dockerfile ./function-images/tests/chained-function-serving/producer/producer.go ./function-images/tests/chained-function-serving/proto/prodcon.pb.go ./function-images/tests/chained-function-serving/proto/prodcon_grpc.pb.go
147+
docker build --tag vhiveease/chained-functions-serving-producer:latest --build-arg target_arg=producer -f ./function-images/tests/chained-function-serving/Dockerfile .
148+
149+
serving-producer-image-push: serving-producer-image
150+
docker push vhiveease/chained-functions-serving-producer:latest
151+
152+
153+
serving-consumer-image: ./function-images/tests/chained-function-serving/Dockerfile ./function-images/tests/chained-function-serving/consumer/consumer.go ./function-images/tests/chained-function-serving/proto/prodcon.pb.go ./function-images/tests/chained-function-serving/proto/prodcon_grpc.pb.go
154+
docker build --tag vhiveease/chained-functions-serving-consumer:latest --build-arg target_arg=consumer -f ./function-images/tests/chained-function-serving/Dockerfile .
155+
156+
serving-consumer-image-push: serving-consumer-image
157+
docker push vhiveease/chained-functions-serving-consumer:latest
141158

142159
.PHONY: test-orch $(SUBDIRS) test-subdirs

function-images/tests/chained-function-serving/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ RUN apk add --no-cache make
2828
# https://vsupalov.com/docker-build-pass-environment-variables/
2929
ARG target_arg
3030
ENV target=$target_arg
31-
COPY . ./
31+
COPY ./function-images/tests/chained-function-serving/ ./
32+
COPY ./utils/tracing/go ./utils/tracing
3233
RUN mkdir /log
3334
RUN go mod download && \
3435
CGO_ENABLED=0 GOOS=linux go build -v -o ./${target}-bin ./${target}/
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2021 Michal Baczun and EASE lab
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package main
24+
25+
import (
26+
"context"
27+
"flag"
28+
"fmt"
29+
"log"
30+
"os"
31+
32+
"google.golang.org/grpc"
33+
34+
pb "github.com/ease-lab/vhive/examples/protobuf/helloworld"
35+
36+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
37+
"go.opentelemetry.io/otel"
38+
"go.opentelemetry.io/otel/attribute"
39+
"go.opentelemetry.io/otel/exporters/trace/zipkin"
40+
"go.opentelemetry.io/otel/propagation"
41+
"go.opentelemetry.io/otel/sdk/resource"
42+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
43+
"go.opentelemetry.io/otel/semconv"
44+
)
45+
46+
const (
47+
serviceName = "client"
48+
id = 3
49+
)
50+
51+
var logger = log.New(os.Stderr, "zipkin-example", log.Ldate|log.Ltime|log.Llongfile)
52+
53+
// initTracer creates a new trace provider instance and registers it as global trace provider.
54+
func initTracer(url string) func() {
55+
// Create Zipkin Exporter and install it as a global tracer.
56+
//
57+
// For demoing purposes, always sample. In a production application, you should
58+
// configure the sampler to a trace.ParentBased(trace.TraceIDRatioBased) set at the desired
59+
// ratio.
60+
exporter, err := zipkin.NewRawExporter(
61+
url,
62+
zipkin.WithLogger(logger),
63+
zipkin.WithSDKOptions(sdktrace.WithSampler(sdktrace.AlwaysSample())),
64+
)
65+
if err != nil {
66+
log.Fatal(err)
67+
}
68+
tp := sdktrace.NewTracerProvider(
69+
sdktrace.WithSampler(sdktrace.AlwaysSample()),
70+
sdktrace.WithSyncer(exporter),
71+
sdktrace.WithResource(resource.NewWithAttributes(
72+
semconv.ServiceNameKey.String(serviceName),
73+
attribute.Int64("ID", id),
74+
)),
75+
)
76+
otel.SetTracerProvider(tp)
77+
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
78+
return func() {
79+
_ = tp.Shutdown(context.Background())
80+
}
81+
}
82+
83+
func main() {
84+
//strings := flag.Int("s", 1, "Number of strings to send")
85+
address := flag.String("addr", "localhost", "Server IP address")
86+
clientPort := flag.Int("pc", 3031, "Client Port")
87+
url := flag.String("zipkin", "http://localhost:9411/api/v2/spans", "zipkin url")
88+
flag.Parse()
89+
90+
shutdown := initTracer(*url)
91+
defer shutdown()
92+
93+
fmt.Printf("Client using address: %v\n", *address)
94+
95+
conn, err := grpc.Dial(fmt.Sprintf("%v:%v", *address, *clientPort), grpc.WithInsecure(), grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()))
96+
if err != nil {
97+
log.Fatalf("fail to dial: %s", err)
98+
}
99+
defer conn.Close()
100+
101+
client := pb.NewGreeterClient(conn)
102+
empty, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "client"})
103+
fmt.Printf("Client output: %v, %v\n", empty, err)
104+
if err != nil {
105+
log.Fatalf("Failed to produce strings: %s", err)
106+
}
107+
fmt.Printf("client closing\n")
108+
109+
}

function-images/tests/chained-function-serving/consumer/consumer.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ import (
3030
"log"
3131
"net"
3232
"os"
33+
"time"
3334

3435
"google.golang.org/grpc"
3536

3637
pb "tests/chained-functions-serving/proto"
38+
39+
tracing "github.com/ease-lab/vhive/utils/tracing/go"
40+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
3741
)
3842

3943
type consumerServer struct {
@@ -60,17 +64,21 @@ func (s *consumerServer) ConsumeStream(stream pb.ProducerConsumer_ConsumeStreamS
6064

6165
func main() {
6266
port := flag.Int("ps", 80, "Port")
67+
url := flag.String("zipkin", "http://zipkin.istio-system.svc.cluster.local:9411/api/v2/spans", "zipkin url")
6368
flag.Parse()
6469

6570
log.SetOutput(os.Stdout)
6671

72+
shutdown := tracing.InitBasicTracer(*url, "consumer")
73+
defer shutdown()
74+
6775
//set up server
6876
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
6977
if err != nil {
7078
log.Fatalf("[consumer] failed to listen: %v", err)
7179
}
7280

73-
grpcServer := grpc.NewServer()
81+
grpcServer := grpc.NewServer(grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()))
7482
s := consumerServer{}
7583
pb.RegisterProducerConsumerServer(grpcServer, &s)
7684

function-images/tests/chained-function-serving/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
version: "3.7"
2424

2525
services:
26+
zipkin:
27+
image: openzipkin/zipkin
28+
ports:
29+
- 9411:9411
2630
consumer:
2731
image: vhiveease/chained-functions-serving-consumer
2832
volumes:
2933
- log-volume:/log
3034
command:
3135
- -ps=3030
36+
- -zipkin=http://zipkin:9411/api/v2/spans
37+
depends_on:
38+
- zipkin
3239

3340
producer:
3441
image: vhiveease/chained-functions-serving-producer
@@ -40,8 +47,10 @@ services:
4047
- -addr=consumer
4148
- -ps=3031
4249
- -pc=3030
50+
- -zipkin=http://zipkin:9411/api/v2/spans
4351
depends_on:
4452
- consumer
53+
- zipkin
4554

4655
volumes:
4756
log-volume:

function-images/tests/chained-function-serving/go.mod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ module tests/chained-functions-serving
22

33
go 1.16
44

5-
replace tests/chained-functions-serving/proto => ./proto
5+
replace (
6+
github.com/ease-lab/vhive/utils/tracing/go => /app/utils/tracing
7+
tests/chained-functions-serving/proto => ./proto
8+
)
69

710
require (
811
github.com/ease-lab/vhive/examples/protobuf/helloworld v0.0.0-20210608114032-dab7e310da45
12+
github.com/ease-lab/vhive/utils/tracing/go v0.0.0-00010101000000-000000000000
13+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0
14+
go.opentelemetry.io/otel v0.20.0
15+
go.opentelemetry.io/otel/exporters/trace/zipkin v0.20.0
16+
go.opentelemetry.io/otel/sdk v0.20.0
917
google.golang.org/grpc v1.38.0
1018
google.golang.org/protobuf v1.26.0
1119
)

0 commit comments

Comments
 (0)