Skip to content

Commit b46bdef

Browse files
interop/observability: add GCP Observability Testing Client/Server (#5979)
1 parent f311684 commit b46bdef

File tree

7 files changed

+1392
-0
lines changed

7 files changed

+1392
-0
lines changed

interop/observability/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2022 gRPC authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
#
17+
# Stage 1: Build the interop test client and server
18+
#
19+
20+
FROM golang:1.17.13-bullseye as build
21+
22+
WORKDIR /grpc-go
23+
COPY . .
24+
25+
WORKDIR /grpc-go/interop/observability
26+
RUN go build -o server/ server/server.go && \
27+
go build -o client/ client/client.go
28+
29+
30+
31+
#
32+
# Stage 2:
33+
#
34+
# - Copy only the necessary files to reduce Docker image size.
35+
# - Have an ENTRYPOINT script which will launch the interop test client or server
36+
# with the given parameters.
37+
#
38+
39+
FROM golang:1.17.13-bullseye
40+
41+
ENV GRPC_GO_LOG_SEVERITY_LEVEL info
42+
ENV GRPC_GO_LOG_VERBOSITY_LEVEL 2
43+
44+
WORKDIR /grpc-go/interop/observability/server
45+
COPY --from=build /grpc-go/interop/observability/server/server .
46+
47+
WORKDIR /grpc-go/interop/observability/client
48+
COPY --from=build /grpc-go/interop/observability/client/client .
49+
50+
WORKDIR /grpc-go/interop/observability
51+
COPY --from=build /grpc-go/interop/observability/run.sh .
52+
53+
ENTRYPOINT ["/grpc-go/interop/observability/run.sh"]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Copyright 2022 gRPC authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -ex
17+
cd "$(dirname "$0")"/../..
18+
19+
# Environment Variables:
20+
#
21+
# TAG_NAME: the docker image tag name
22+
#
23+
24+
echo Building ${TAG_NAME}
25+
26+
docker build --no-cache -t ${TAG_NAME} -f ./interop/observability/Dockerfile .
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
*
3+
* Copyright 2022 gRPC authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package main
20+
21+
import (
22+
"context"
23+
"flag"
24+
"log"
25+
"net"
26+
"strconv"
27+
"time"
28+
29+
"google.golang.org/grpc"
30+
"google.golang.org/grpc/credentials/insecure"
31+
"google.golang.org/grpc/gcp/observability"
32+
"google.golang.org/grpc/interop"
33+
34+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
35+
)
36+
37+
var (
38+
serverHost = flag.String("server_host", "localhost", "The server host name")
39+
serverPort = flag.Int("server_port", 10000, "The server port number")
40+
testCase = flag.String("test_case", "large_unary", "The action to perform")
41+
numTimes = flag.Int("num_times", 1, "Number of times to run the test case")
42+
)
43+
44+
func main() {
45+
err := observability.Start(context.Background())
46+
if err != nil {
47+
log.Fatalf("observability start failed: %v", err)
48+
}
49+
defer observability.End()
50+
flag.Parse()
51+
serverAddr := *serverHost
52+
if *serverPort != 0 {
53+
serverAddr = net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
54+
}
55+
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
56+
if err != nil {
57+
log.Fatalf("Fail to dial: %v", err)
58+
}
59+
defer conn.Close()
60+
tc := testgrpc.NewTestServiceClient(conn)
61+
for i := 0; i < *numTimes; i++ {
62+
if *testCase == "ping_pong" {
63+
interop.DoPingPong(tc)
64+
} else if *testCase == "large_unary" {
65+
interop.DoLargeUnaryCall(tc)
66+
} else if *testCase == "custom_metadata" {
67+
interop.DoCustomMetadata(tc)
68+
} else {
69+
log.Fatalf("Invalid test case: %s", *testCase)
70+
}
71+
}
72+
// TODO(stanleycheung): remove this once the observability exporter plugin is able to
73+
// gracefully flush observability data to cloud at shutdown
74+
// TODO(stanleycheung): see if we can reduce the number 65
75+
const exporterSleepDuration = 65 * time.Second
76+
log.Printf("Sleeping %v before closing...", exporterSleepDuration)
77+
time.Sleep(exporterSleepDuration)
78+
}

interop/observability/go.mod

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module google.golang.org/grpc/interop/observability
2+
3+
go 1.17
4+
5+
require (
6+
google.golang.org/grpc v1.53.0
7+
google.golang.org/grpc/gcp/observability v0.0.0-20230214181353-f4feddb37523
8+
)
9+
10+
require (
11+
cloud.google.com/go v0.107.0 // indirect
12+
cloud.google.com/go/compute v1.15.1 // indirect
13+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
14+
cloud.google.com/go/logging v1.6.1 // indirect
15+
cloud.google.com/go/longrunning v0.3.0 // indirect
16+
cloud.google.com/go/monitoring v1.8.0 // indirect
17+
cloud.google.com/go/trace v1.4.0 // indirect
18+
contrib.go.opencensus.io/exporter/stackdriver v0.13.12 // indirect
19+
github.com/aws/aws-sdk-go v1.44.162 // indirect
20+
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
21+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
22+
github.com/golang/protobuf v1.5.2 // indirect
23+
github.com/google/go-cmp v0.5.9 // indirect
24+
github.com/google/uuid v1.3.0 // indirect
25+
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
26+
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
27+
github.com/jmespath/go-jmespath v0.4.0 // indirect
28+
github.com/prometheus/prometheus v2.5.0+incompatible // indirect
29+
go.opencensus.io v0.24.0 // indirect
30+
golang.org/x/net v0.5.0 // indirect
31+
golang.org/x/oauth2 v0.4.0 // indirect
32+
golang.org/x/sync v0.1.0 // indirect
33+
golang.org/x/sys v0.4.0 // indirect
34+
golang.org/x/text v0.6.0 // indirect
35+
google.golang.org/api v0.103.0 // indirect
36+
google.golang.org/appengine v1.6.7 // indirect
37+
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
38+
google.golang.org/grpc/stats/opencensus v0.0.0-20230221205128-8702a2ebf4b0 // indirect
39+
google.golang.org/protobuf v1.28.1 // indirect
40+
)
41+
42+
replace google.golang.org/grpc => ../..
43+
44+
replace google.golang.org/grpc/gcp/observability => ../../gcp/observability
45+
46+
replace google.golang.org/grpc/stats/opencensus => ../../stats/opencensus

0 commit comments

Comments
 (0)