Skip to content

Commit

Permalink
Make collecting Prometheus data optional through annotation
Browse files Browse the repository at this point in the history
Currently we automatically collect Prometheus data for PSM
related tests, now some regular tests (same scenario as PSM
test) are also part of the PSM tests, we may want to collect
Prometheus data for those regular tests too. The current method
for checking if a rest is a PSM test to check the existence of
xds-server and sidecar containers.
It is hard to apply the same mechanism for PSM related regular
tests,  the simplest way is to add an annotation like
`enablePrometheus:true` to control if we want to use Prometheus
for a given test.
  • Loading branch information
wanlin31 committed Jun 29, 2022
1 parent e2d63ef commit b5036e9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const (
// DriverPortEnv specifies the name of the env variable that contains driver port.
DriverPortEnv = "DRIVER_PORT"

// EnablePrometheusEnv specifies the name of the env variable that indicates if the
// Prometheus data is collected.
EnablePrometheusEnv = "ENABLE_PROMETHEUS"

// PoolLabel is the key for a label which will have the name of a pool as
// the value.
PoolLabel = "pool"
Expand Down
2 changes: 1 addition & 1 deletion containers/runtime/driver/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if [ -n "${BQ_RESULT_TABLE}" ]; then
fi
if [ -r "${NODE_INFO_OUTPUT_FILE}" ]; then
cp "${NODE_INFO_OUTPUT_FILE}" node_info.json
if [ -n "${SERVER_TARGET_OVERRIDE}" ]; then
if [ -n "${SERVER_TARGET_OVERRIDE}" ] || [ -n "${ENABLE_PROMETHEUS}" ]; then
python3 /src/code/tools/run_tests/performance/prometheus.py \
--url=http://prometheus.test-infra-system.svc.cluster.local:9090 \
--pod_type=clients --container_name=main \
Expand Down
2 changes: 1 addition & 1 deletion kubehelpers/psm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/grpc/test-infra/config"
)

//IsPSMTest checks if a given LoadTest is a (proxied or proxyless) service
// IsPSMTest checks if a given LoadTest is a (proxied or proxyless) service
// mesh test. This test must be performed after validating the client specs.
func IsPSMTest(clients *[]grpcv1.Client) bool {
for _, c := range *clients {
Expand Down
9 changes: 9 additions & 0 deletions podbuilder/podbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package podbuilder

import (
"fmt"
"strings"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -240,6 +241,14 @@ func (pb *PodBuilder) PodForDriver(driver *grpcv1.Driver) (*corev1.Pod, error) {
}
}

usePrometheus, ok := pb.test.Annotations["enablePrometheus"]
if ok && strings.ToLower(usePrometheus) == "true" {
runContainer.Env = append(runContainer.Env,
corev1.EnvVar{
Name: config.EnablePrometheusEnv,
Value: "true"})
}

return pod, nil
}

Expand Down
2 changes: 1 addition & 1 deletion status/missing_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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
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,
Expand Down

0 comments on commit b5036e9

Please sign in to comment.