Skip to content

Commit febe966

Browse files
authored
Add GAE standard support to test runner (#41)
1 parent 3635d1f commit febe966

6 files changed

Lines changed: 160 additions & 0 deletions

File tree

e2e_testing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ type GaeCmd struct {
6262
Runtime string `arg:"required" help:"The language runtime for the instrumented test server, used in naming the service"`
6363
}
6464

65+
type GaeStandardCmd struct {
66+
Runtime string `arg:"required" help:"The language runtime for the instrumented test server, used in naming the service"`
67+
AppSource string `arg:"required" help:"The full path of the zip file that contains the source code to run in GAE"`
68+
}
69+
6570
type CloudRunCmd struct {
6671
CmdWithImage
6772
}
@@ -85,6 +90,7 @@ type Args struct {
8590
Gke *GkeCmd `arg:"subcommand:gke" help:"Deploy the test server on GKE and execute tests"`
8691
Gce *GceCmd `arg:"subcommand:gce" help:"Deploy the test server on GCE and execute tests"`
8792
Gae *GaeCmd `arg:"subcommand:gae" help:"Deploy the test server on GAE and execute tests"`
93+
GaeStandard *GaeStandardCmd `arg:"subcommand:gae-standard" help:"Deploy the test server on GAE standard and execute tests"`
8894
CloudRun *CloudRunCmd `arg:"subcommand:cloud-run" help:"Deploy the test server on Cloud Run and execute tests"`
8995
CloudFunctionsGen2 *CloudFunctionsGen2Cmd `arg:"subcommand:cloud-functions-gen2" help:"Deploy the test server on Cloud Function (2nd Gen) and execute tests"`
9096

main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ func TestMain(m *testing.M) {
8080
setupFunc = SetupCloudFunctionsGen2
8181
case args.Gae != nil:
8282
setupFunc = SetupGae
83+
case args.GaeStandard != nil:
84+
setupFunc = SetupGaeStandard
8385
}
8486
client, cleanup, err := setupFunc(ctx, &args, logger)
8587

setupgaestandard.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2024 Google LLC
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+
// https://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+
package e2e_testing
16+
17+
import (
18+
"context"
19+
"log"
20+
21+
"github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/setuptf"
22+
"github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/testclient"
23+
)
24+
25+
const gaeStandardTfDir string = "tf/gae-standard"
26+
27+
func SetupGaeStandard(
28+
ctx context.Context,
29+
args *Args,
30+
logger *log.Logger,
31+
) (*testclient.Client, Cleanup, error) {
32+
pubsubInfo, cleanupTf, err := setuptf.SetupTf(
33+
ctx,
34+
args.ProjectID,
35+
args.TestRunID,
36+
gaeStandardTfDir,
37+
map[string]string{
38+
"runtime": args.GaeStandard.Runtime,
39+
"appsource": args.GaeStandard.AppSource,
40+
},
41+
logger,
42+
)
43+
if err != nil {
44+
return nil, cleanupTf, err
45+
}
46+
47+
client, err := testclient.New(ctx, args.ProjectID, pubsubInfo)
48+
return client, cleanupTf, err
49+
}

tf/gae-standard/gae-standard.tf

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2024 Google LLC
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+
# https://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+
# Not enabling the permissions on the default service account here Since the permissions
16+
# bindings specified here will be removed when the terraform cleanup happens, that causes
17+
# failures in app engine environment. These permissions should be granted through the latch-key
18+
# configurations.
19+
20+
resource "google_app_engine_standard_app_version" "test_service" {
21+
22+
version_id = "v1"
23+
project = var.project_id
24+
service = "test-standard-service-${var.runtime}-${terraform.workspace}"
25+
runtime = var.runtime
26+
27+
deployment {
28+
zip {
29+
// The object's media_link does not work, GAE requires this format
30+
// https://cloud.google.com/appengine/docs/admin-api/reference/rpc/google.appengine.v1#zipinfo
31+
source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"
32+
}
33+
}
34+
35+
// Required, but leave empty to fall back to the runtime default
36+
entrypoint {
37+
shell = ""
38+
}
39+
40+
env_variables = {
41+
"PUSH_PORT" = "8080",
42+
"REQUEST_SUBSCRIPTION_NAME" = module.pubsub.info.request_topic.subscription_name,
43+
"RESPONSE_TOPIC_NAME" = module.pubsub.info.response_topic.topic_name,
44+
"PROJECT_ID" = var.project_id,
45+
"SUBSCRIPTION_MODE" = "push"
46+
}
47+
48+
noop_on_destroy = false
49+
delete_service_on_destroy = true
50+
}
51+
52+
resource "google_storage_bucket" "bucket" {
53+
name = "${terraform.workspace}-appsource" # Every bucket name must be globally unique
54+
location = "US"
55+
uniform_bucket_level_access = true
56+
}
57+
58+
resource "google_storage_bucket_object" "object" {
59+
name = "appsource.zip"
60+
bucket = google_storage_bucket.bucket.name
61+
# Add path to the zipped function source code, source file zip should be in the bucket
62+
source = var.appsource
63+
}
64+
65+
module "pubsub" {
66+
source = "../modules/pubsub"
67+
68+
project_id = var.project_id
69+
}
70+
71+
module "pubsub-push-subscription" {
72+
source = "../modules/pubsub-push-subscription"
73+
74+
project_id = var.project_id
75+
topic = module.pubsub.info.request_topic.topic_name
76+
push_endpoint = "https://${google_app_engine_standard_app_version.test_service.service}-dot-${var.project_id}.uc.r.appspot.com/"
77+
}
78+
79+
variable "appsource" {
80+
type = string
81+
}
82+
83+
variable "runtime" {
84+
type = string
85+
}
86+
87+
output "pubsub_info" {
88+
value = module.pubsub.info
89+
description = "Info about the request/response pubsub topics and subscription to use in the test"
90+
}

tf/gae-standard/main-common.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../common/main-common.tf

trace_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,18 @@ func TestResourceDetectionTrace(t *testing.T) {
277277
labelExpectation{expectKey: "faas.instance", expectRe: `.*`},
278278
labelExpectation{expectKey: "faas.version", expectRe: `.*`},
279279
)
280+
case args.GaeStandard != nil:
281+
labelCases = append(labelCases,
282+
labelExpectation{expectKey: "cloud.provider", expectRe: `gcp`},
283+
labelExpectation{expectKey: "cloud.platform", expectRe: `gcp_app_engine`},
284+
// GAE standard zones do not use the regular consistent GCP public zone names, but
285+
// this regex verifies that the "/" characters are stripped away
286+
labelExpectation{expectKey: "cloud.availability_zone", expectRe: `[\w\-]+`},
287+
labelExpectation{expectKey: "cloud.region", expectRe: `.*-.*`},
288+
labelExpectation{expectKey: "faas.name", expectRe: `.*`},
289+
labelExpectation{expectKey: "faas.instance", expectRe: `.*`},
290+
labelExpectation{expectKey: "faas.version", expectRe: `.*`},
291+
)
280292
default:
281293
t.Logf("Unexpected GCP environment provided. Make sure to add handling for all expected GCP environments.")
282294
t.FailNow()

0 commit comments

Comments
 (0)