-
Notifications
You must be signed in to change notification settings - Fork 7
New collector based tests #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
ed87d23
b010a62
fdf8252
eb41c1b
d05d754
111cb1b
205f3fb
3b971f4
fd01572
cc05ccd
a94495e
dd63fd1
dbf9706
2c26c6e
1f866f5
fcc6f3a
9c2b884
987270c
1fa4c13
d99f031
786483f
9595b8d
06061fd
129896e
03a5386
736e529
a5e96dd
507e6b1
f9d61e2
1bfd252
96ac727
5425796
bd55c46
c953c4f
7f04bb6
d6a140e
791466d
87adcd3
9e2bd1d
b4c914e
dfad8fb
4d4f576
d726d0d
c8dda88
34eeee6
e7a2421
4c0dc78
0bb203f
e2b96d2
4710e0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # 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. | ||
|
|
||
| # Builds a docker image, tagging it as _DOCKER_TAG (substitution must be | ||
| # provided) and latest. | ||
|
|
||
| steps: | ||
| - name: docker | ||
| env: | ||
| - DOCKER_BUILDKIT=1 | ||
| args: | ||
| - build | ||
| - --tag=${_TEST_RUNNER_IMAGE_NAME}:${_DOCKER_TAG} | ||
| - --tag=${_TEST_RUNNER_IMAGE_NAME}:latest | ||
| - --build-arg=BUILDKIT_INLINE_CACHE=1 | ||
| - --build-arg=BUILD_TAGS=e2ecollector | ||
| - --cache-from=${_TEST_RUNNER_IMAGE_NAME}:latest | ||
| - . | ||
|
|
||
| images: ["${_TEST_RUNNER_IMAGE_NAME}"] | ||
| options: | ||
| dynamic_substitutions: true | ||
| substitutions: | ||
| _TEST_RUNNER_IMAGE_NAME: us-central1-docker.pkg.dev/${PROJECT_ID}/e2e-testing/opentelemetry-operations-e2e-testing |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //go:build e2ecollector | ||
|
|
||
| package e2etestrunner_collector | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util/setuptf" | ||
| "log" | ||
| "math/rand" | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/alexflint/go-arg" | ||
| ) | ||
|
|
||
| var ( | ||
| args util.Args | ||
| resourceType string | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| rand.New(rand.NewSource(time.Now().UnixNano())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are lines 26..57 the same as in |
||
| p := arg.MustParse(&args) | ||
| if p.Subcommand() == nil { | ||
| p.Fail("missing command") | ||
| } | ||
| // Need a logger just for TestMain() before testing.T is available | ||
| logger := log.New(os.Stdout, "TestMain: ", log.LstdFlags|log.Lshortfile) | ||
| ctx := context.Background() | ||
|
|
||
| // Handle special case of just creating persistent resources | ||
| if args.ApplyPersistent != nil { | ||
| err := setuptf.ApplyPersistentCollector(ctx, args.ProjectID, args.ApplyPersistent.AutoApprove, logger) | ||
| if err != nil { | ||
| logger.Panic(err) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| // hacky but works | ||
| os.Args = append([]string{os.Args[0]}, strings.Fields(args.GoTestFlags)...) | ||
| flag.Parse() | ||
|
|
||
| // handle any complex defaults | ||
| if args.TestRunID == "" { | ||
| hex, err := util.RandomHex(6) | ||
| if err != nil { | ||
| logger.Fatalf("error generating random hex string: %v\n", err) | ||
| } | ||
| args.TestRunID = hex | ||
| } | ||
|
|
||
| var setupFunc util.SetupCollectorFunc | ||
| switch { | ||
| case args.GceCollector != nil: | ||
| setupFunc = SetupGceCollector | ||
| resourceType = "gce_instance" | ||
| case args.GkeCollector != nil: | ||
| setupFunc = SetupGkeCollector | ||
| resourceType = "k8s_container" | ||
| case args.GkeOperatorCollector != nil: | ||
| setupFunc = SetupGkeOperatorCollector | ||
| resourceType = "k8s_container" | ||
| case args.CloudRunCollector != nil: | ||
| setupFunc = SetupCloudRunCollector | ||
| resourceType = "generic_task" | ||
| } | ||
| cleanup, err := setupFunc(ctx, &args, logger) | ||
|
|
||
| defer cleanup() | ||
| if err != nil { | ||
| logger.Panic(err) | ||
| } | ||
|
|
||
| // wait for instrumented test server to be healthy | ||
| logger.Printf("Waiting for health check on (will timeout after %v)\n", args.HealthCheckTimeout) | ||
| time.Sleep(args.HealthCheckTimeout) | ||
| // Run tests | ||
| logger.Print(util.BeginOutputArt) | ||
| m.Run() | ||
| logger.Print(util.EndOutputArt) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2021 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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 e2etestrunner_collector | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util/setuptf" | ||
| "log" | ||
| ) | ||
|
|
||
| const gceCollectorTfDir string = "tf/gce-collector" | ||
|
|
||
| // SetupGceCollector Set up the collector to run in GCE container. Creates a new | ||
| // GCE VM resources, and runs the specified container image. The | ||
| // returned cleanup function tears down the VM. | ||
| func SetupGceCollector( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do any of these setup functions differ in any way other than the terraform they are running? |
||
| ctx context.Context, | ||
| args *util.Args, | ||
| logger *log.Logger, | ||
| ) (util.Cleanup, error) { | ||
| _, cleanupTf, err := setuptf.SetupTf( | ||
| ctx, | ||
| args.ProjectID, | ||
| args.TestRunID, | ||
| gceCollectorTfDir, | ||
| map[string]string{ | ||
| "image": args.GceCollector.Image, | ||
| }, | ||
| logger, | ||
| ) | ||
| if err != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 44..48 is equivalent to return cleanupTf, errThis comment applies to all the setups here it looks like |
||
| return cleanupTf, err | ||
| } | ||
|
|
||
| return cleanupTf, err | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2021 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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 e2etestrunner_collector | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util/setuptf" | ||
| "log" | ||
| ) | ||
|
|
||
| const cloudRunCollectorTfDir string = "tf/cloud-run-collector" | ||
|
|
||
| // SetupCloudRunCollector sets up the collector to run in Cloud Run. | ||
| // Creates a new service and runs the specified container image as a revision. | ||
| // The returned cleanup function tears down everything. | ||
| func SetupCloudRunCollector( | ||
| ctx context.Context, | ||
| args *util.Args, | ||
| logger *log.Logger, | ||
| ) (util.Cleanup, error) { | ||
| _, cleanupTf, err := setuptf.SetupTf( | ||
| ctx, | ||
| args.ProjectID, | ||
| args.TestRunID, | ||
| cloudRunCollectorTfDir, | ||
| map[string]string{ | ||
| "image": args.CloudRunCollector.Image, | ||
| }, | ||
| logger, | ||
| ) | ||
| if err != nil { | ||
| return cleanupTf, err | ||
| } | ||
|
|
||
| return cleanupTf, err | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package e2etestrunner_collector | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util/setuptf" | ||
| "log" | ||
| ) | ||
|
|
||
| const gkeCollectorTfDir string = "tf/gke-collector" | ||
|
|
||
| // SetupGkeCollector Set up the collector to run in GKE. | ||
| // Creates a new pod and runs the specified container image in a pod. | ||
| // The returned cleanup function tears down the whole cluster. | ||
| func SetupGkeCollector( | ||
| ctx context.Context, | ||
| args *util.Args, | ||
| logger *log.Logger, | ||
| ) (util.Cleanup, error) { | ||
| _, cleanupTf, err := setuptf.SetupTf( | ||
| ctx, | ||
| args.ProjectID, | ||
| args.TestRunID, | ||
| gkeCollectorTfDir, | ||
| map[string]string{ | ||
| "image": args.GkeCollector.Image, | ||
| }, | ||
| logger, | ||
| ) | ||
| if err != nil { | ||
| return cleanupTf, err | ||
| } | ||
|
|
||
| return cleanupTf, err | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package e2etestrunner_collector | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util" | ||
| "github.com/GoogleCloudPlatform/opentelemetry-operations-e2e-testing/util/setuptf" | ||
| "log" | ||
| ) | ||
|
|
||
| const gkeOperatorCollectorTfDir string = "tf/gke-operator-collector" | ||
|
|
||
| // SetupGkeOperatorCollector Set up the collector to run in GKE. | ||
| // Creates a new pod and runs the specified container image in a pod. | ||
| // The returned cleanup function tears down the whole cluster. | ||
| func SetupGkeOperatorCollector( | ||
| ctx context.Context, | ||
| args *util.Args, | ||
| logger *log.Logger, | ||
| ) (util.Cleanup, error) { | ||
| _, cleanupTf, err := setuptf.SetupTf( | ||
| ctx, | ||
| args.ProjectID, | ||
| args.TestRunID, | ||
| gkeOperatorCollectorTfDir, | ||
| map[string]string{ | ||
| "image": args.GkeOperatorCollector.Image, | ||
| }, | ||
| logger, | ||
| ) | ||
| if err != nil { | ||
| return cleanupTf, err | ||
| } | ||
|
|
||
| return cleanupTf, err | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The folder should be named the same as the package, i.e. the folder should be renamed to
e2etestrunner_collector