-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resource-util): add App Engine detector (#510)
- Loading branch information
Showing
9 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2023 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. | ||
|
||
steps: | ||
# Wait for the image to exist | ||
- name: "docker" | ||
id: wait-for-image | ||
entrypoint: "sh" | ||
timeout: 10m | ||
env: ["_TEST_SERVER_IMAGE=${_TEST_SERVER_IMAGE}"] | ||
args: | ||
- e2e-test-server/wait-for-image.sh | ||
|
||
# Run the test | ||
- name: $_TEST_RUNNER_IMAGE | ||
id: run-tests-gae | ||
dir: / | ||
env: ["PROJECT_ID=$PROJECT_ID"] | ||
args: | ||
- gae | ||
- --image=$_TEST_SERVER_IMAGE | ||
- --runtime=node | ||
|
||
logsBucket: gs://opentelemetry-ops-e2e-cloud-build-logs | ||
timeout: 20m | ||
substitutions: | ||
_TEST_RUNNER_IMAGE: gcr.io/${PROJECT_ID}/opentelemetry-operations-e2e-testing:0.15.0 | ||
_TEST_SERVER_IMAGE: gcr.io/${PROJECT_ID}/opentelemetry-operations-js-e2e-test-server:${SHORT_SHA} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2023 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. | ||
|
||
/** | ||
* Implementation in this file copied from | ||
* https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/v1.8.0/detectors/gcp/app_engine.go | ||
*/ | ||
|
||
import * as metadata from 'gcp-metadata'; | ||
import * as gce from './gce'; | ||
import * as faas from './faas'; | ||
|
||
const GAE_SERVICE_ENV = 'GAE_SERVICE'; | ||
const GAE_VERSION_ENV = 'GAE_VERSION'; | ||
const GAE_INSTANCE_ENV = 'GAE_INSTANCE'; | ||
const GAE_ENV = 'GAE_ENV'; | ||
const GAE_STANDARD = 'standard'; | ||
const ZONE_METADATA_ATTR = 'zone'; | ||
|
||
export async function onAppEngineStandard(): Promise<boolean> { | ||
return process.env[GAE_ENV] === GAE_STANDARD; | ||
} | ||
|
||
export async function onAppEngine(): Promise<boolean> { | ||
return process.env[GAE_SERVICE_ENV] !== undefined; | ||
} | ||
|
||
/** | ||
* The service name of the app engine service. Check that {@link onAppEngine()} is true before | ||
* calling this, or it may throw exceptions. | ||
*/ | ||
export async function serviceName(): Promise<string> { | ||
return lookupEnv(GAE_SERVICE_ENV); | ||
} | ||
|
||
/** | ||
* The service version of the app engine service. Check that {@link onAppEngine()} is true | ||
* before calling this, or it may throw exceptions. | ||
*/ | ||
export async function serviceVersion(): Promise<string> { | ||
return lookupEnv(GAE_VERSION_ENV); | ||
} | ||
|
||
/** | ||
* The service instance of the app engine service. Check that {@link onAppEngine()} is true | ||
* before calling this, or it may throw exceptions. | ||
*/ | ||
export async function serviceInstance(): Promise<string> { | ||
return lookupEnv(GAE_INSTANCE_ENV); | ||
} | ||
|
||
/** | ||
* The zone and region in which this program is running. Check that {@link onAppEngine()} is | ||
* true before calling this, or it may throw exceptions. | ||
*/ | ||
export async function flexAvailabilityZoneAndRegion(): Promise<{ | ||
zone: string; | ||
region: string; | ||
}> { | ||
return await gce.availabilityZoneAndRegion(); | ||
} | ||
|
||
/** | ||
* The zone the app engine service is running in. Check that {@link onAppEngineStandard()} is | ||
* true before calling this, or it may throw exceptions. | ||
*/ | ||
export async function standardAvailabilityZone(): Promise<string> { | ||
return await metadata.instance<string>(ZONE_METADATA_ATTR); | ||
} | ||
|
||
/** | ||
* The region the app engine service is running in. Check that {@link onAppEngineStandard()} is | ||
* true before calling this, or it may throw exceptions. | ||
*/ | ||
export async function standardCloudRegion(): Promise<string> { | ||
return await faas.faasCloudRegion(); | ||
} | ||
|
||
function lookupEnv(key: string): string { | ||
const val = process.env[key]; | ||
if (val === undefined) { | ||
throw new Error(`Environment variable ${key} not found`); | ||
} | ||
return val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.