interop/observability: add GCP Observability Testing Client/Server (#5979)

This commit is contained in:
Stanley Cheung 2023-03-03 15:00:20 -08:00 committed by GitHub
parent f31168468f
commit b46bdef165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1392 additions and 0 deletions

View File

@ -0,0 +1,53 @@
# Copyright 2022 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Stage 1: Build the interop test client and server
#
FROM golang:1.17.13-bullseye as build
WORKDIR /grpc-go
COPY . .
WORKDIR /grpc-go/interop/observability
RUN go build -o server/ server/server.go && \
go build -o client/ client/client.go
#
# Stage 2:
#
# - Copy only the necessary files to reduce Docker image size.
# - Have an ENTRYPOINT script which will launch the interop test client or server
# with the given parameters.
#
FROM golang:1.17.13-bullseye
ENV GRPC_GO_LOG_SEVERITY_LEVEL info
ENV GRPC_GO_LOG_VERBOSITY_LEVEL 2
WORKDIR /grpc-go/interop/observability/server
COPY --from=build /grpc-go/interop/observability/server/server .
WORKDIR /grpc-go/interop/observability/client
COPY --from=build /grpc-go/interop/observability/client/client .
WORKDIR /grpc-go/interop/observability
COPY --from=build /grpc-go/interop/observability/run.sh .
ENTRYPOINT ["/grpc-go/interop/observability/run.sh"]

View File

@ -0,0 +1,26 @@
#!/bin/bash
# Copyright 2022 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
cd "$(dirname "$0")"/../..
# Environment Variables:
#
# TAG_NAME: the docker image tag name
#
echo Building ${TAG_NAME}
docker build --no-cache -t ${TAG_NAME} -f ./interop/observability/Dockerfile .

View File

@ -0,0 +1,78 @@
/*
*
* Copyright 2022 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package main
import (
"context"
"flag"
"log"
"net"
"strconv"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/gcp/observability"
"google.golang.org/grpc/interop"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
)
var (
serverHost = flag.String("server_host", "localhost", "The server host name")
serverPort = flag.Int("server_port", 10000, "The server port number")
testCase = flag.String("test_case", "large_unary", "The action to perform")
numTimes = flag.Int("num_times", 1, "Number of times to run the test case")
)
func main() {
err := observability.Start(context.Background())
if err != nil {
log.Fatalf("observability start failed: %v", err)
}
defer observability.End()
flag.Parse()
serverAddr := *serverHost
if *serverPort != 0 {
serverAddr = net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
}
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Fail to dial: %v", err)
}
defer conn.Close()
tc := testgrpc.NewTestServiceClient(conn)
for i := 0; i < *numTimes; i++ {
if *testCase == "ping_pong" {
interop.DoPingPong(tc)
} else if *testCase == "large_unary" {
interop.DoLargeUnaryCall(tc)
} else if *testCase == "custom_metadata" {
interop.DoCustomMetadata(tc)
} else {
log.Fatalf("Invalid test case: %s", *testCase)
}
}
// TODO(stanleycheung): remove this once the observability exporter plugin is able to
// gracefully flush observability data to cloud at shutdown
// TODO(stanleycheung): see if we can reduce the number 65
const exporterSleepDuration = 65 * time.Second
log.Printf("Sleeping %v before closing...", exporterSleepDuration)
time.Sleep(exporterSleepDuration)
}

View File

@ -0,0 +1,46 @@
module google.golang.org/grpc/interop/observability
go 1.17
require (
google.golang.org/grpc v1.53.0
google.golang.org/grpc/gcp/observability v0.0.0-20230214181353-f4feddb37523
)
require (
cloud.google.com/go v0.107.0 // indirect
cloud.google.com/go/compute v1.15.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/logging v1.6.1 // indirect
cloud.google.com/go/longrunning v0.3.0 // indirect
cloud.google.com/go/monitoring v1.8.0 // indirect
cloud.google.com/go/trace v1.4.0 // indirect
contrib.go.opencensus.io/exporter/stackdriver v0.13.12 // indirect
github.com/aws/aws-sdk-go v1.44.162 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/prometheus/prometheus v2.5.0+incompatible // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc/stats/opencensus v0.0.0-20230221205128-8702a2ebf4b0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
replace google.golang.org/grpc => ../..
replace google.golang.org/grpc/gcp/observability => ../../gcp/observability
replace google.golang.org/grpc/stats/opencensus => ../../stats/opencensus

1093
interop/observability/go.sum Normal file

File diff suppressed because it is too large Load Diff

41
interop/observability/run.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
# Copyright 2022 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
cd "$(dirname "$0")"/../..
# TODO(stanleycheung): replace positional parameters with explicit parameters
#
# $1: server | client
#
# For server: $2: server_port
#
# For client: $2: server_host
# $3: server_port
# $4: test_case
# $5: num_times
if [ "$1" = "server" ] ; then
/grpc-go/interop/observability/server/server --port $2
elif [ "$1" = "client" ] ; then
/grpc-go/interop/observability/client/client \
--server_host=$2 --server_port=$3 \
--test_case=$4 --num_times=$5
else
echo "Invalid action: $1"
exit 1
fi

View File

@ -0,0 +1,55 @@
/*
*
* Copyright 2022 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package main
import (
"context"
"flag"
"fmt"
"log"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/gcp/observability"
"google.golang.org/grpc/interop"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
)
var (
port = flag.Int("port", 10000, "The server port")
)
func main() {
err := observability.Start(context.Background())
if err != nil {
log.Fatalf("observability start failed: %v", err)
}
defer observability.End()
flag.Parse()
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
server := grpc.NewServer()
defer server.Stop()
testgrpc.RegisterTestServiceServer(server, interop.NewTestServer())
log.Printf("Observability interop server listening on %v", lis.Addr())
server.Serve(lis)
}