This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto detect GCE, GKE and AWS EC2 resources (#312)
* add gcp resource * fix review comments
- Loading branch information
1 parent
77eada8
commit 9414faf
Showing
6 changed files
with
651 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
/** | ||
* Copyright 2019, OpenCensus 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. | ||
*/ | ||
|
||
import {CoreResource, Resource} from '@opencensus/core'; | ||
import {getAwsEC2Resource, getComputerEngineResource, getKubernetesEngineResource, getResourceType, ResourceType} from './resource-utils'; | ||
|
||
/** | ||
* Returns a Resource. Detector sequentially runs resource detection from | ||
* environment variables, K8S, GCE and AWS. | ||
*/ | ||
export async function detectResource(): Promise<Resource> { | ||
const resources = [CoreResource.createFromEnvironmentVariables()]; | ||
|
||
const resourceType = await getResourceType(); | ||
if (resourceType === ResourceType.GCP_GKE_CONTAINER) { | ||
resources.push(await getKubernetesEngineResource()); | ||
} else if (resourceType === ResourceType.GCP_GCE_INSTANCE) { | ||
resources.push(await getComputerEngineResource()); | ||
} | ||
if (resourceType === ResourceType.AWS_EC2_INSTANCE) { | ||
resources.push(await getAwsEC2Resource()); | ||
} | ||
|
||
return CoreResource.mergeResources(resources); | ||
} |
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.