-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add explicit-load versions of plugins The existing aws plugins install their metadata at package load time. They aren't meant to be loaded in test/development environments, but there is no good way to only load them in production since you can't conditionally load a package. - move the plugins under a new /awsplugins path and change init() to Init() so user must explicitly call a method to load the plugin. - leave the old plugins in place, delegating to the new plugins. i also left the "Origin" constants since those are part of the packages' public APIs. * Add myself to contributors * Add README.md note about new plugins
- Loading branch information
Showing
8 changed files
with
154 additions
and
79 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
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,45 @@ | ||
// Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 beanstalk | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
|
||
"github.com/aws/aws-xray-sdk-go/internal/plugins" | ||
log "github.com/cihub/seelog" | ||
) | ||
|
||
const Origin = "AWS::ElasticBeanstalk::Environment" | ||
|
||
func Init() { | ||
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.BeanstalkMetadata == nil { | ||
addPluginMetadata(plugins.InstancePluginMetadata) | ||
} | ||
} | ||
|
||
func addPluginMetadata(pluginmd *plugins.PluginMetadata) { | ||
ebConfigPath := "/var/elasticbeanstalk/xray/environment.conf" | ||
|
||
rawConfig, err := ioutil.ReadFile(ebConfigPath) | ||
if err != nil { | ||
log.Errorf("Unable to read Elastic Beanstalk configuration file %s: %v", ebConfigPath, err) | ||
return | ||
} | ||
|
||
config := &plugins.BeanstalkMetadata{} | ||
err = json.Unmarshal(rawConfig, config) | ||
if err != nil { | ||
log.Errorf("Unable to unmarshal Elastic Beanstalk configuration file %s: %v", ebConfigPath, err) | ||
return | ||
} | ||
|
||
pluginmd.BeanstalkMetadata = config | ||
pluginmd.Origin = Origin | ||
} |
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,41 @@ | ||
// Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 ec2 | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/ec2metadata" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-xray-sdk-go/internal/plugins" | ||
log "github.com/cihub/seelog" | ||
) | ||
|
||
const Origin = "AWS::EC2::Instance" | ||
|
||
func Init() { | ||
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.EC2Metadata == nil { | ||
addPluginMetadata(plugins.InstancePluginMetadata) | ||
} | ||
} | ||
|
||
func addPluginMetadata(pluginmd *plugins.PluginMetadata) { | ||
session, e := session.NewSession() | ||
if e != nil { | ||
log.Errorf("Unable to create a new ec2 session: %v", e) | ||
return | ||
} | ||
client := ec2metadata.New(session) | ||
doc, err := client.GetInstanceIdentityDocument() | ||
if err != nil { | ||
log.Errorf("Unable to read EC2 instance metadata: %v", err) | ||
return | ||
} | ||
|
||
pluginmd.EC2Metadata = &plugins.EC2Metadata{InstanceID: doc.InstanceID, AvailabilityZone: doc.AvailabilityZone} | ||
pluginmd.Origin = Origin | ||
} |
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,36 @@ | ||
// Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file 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 ecs | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/aws/aws-xray-sdk-go/internal/plugins" | ||
log "github.com/cihub/seelog" | ||
) | ||
|
||
const Origin = "AWS::ECS::Container" | ||
|
||
func Init() { | ||
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.ECSMetadata == nil { | ||
addPluginMetadata(plugins.InstancePluginMetadata) | ||
} | ||
} | ||
|
||
func addPluginMetadata(pluginmd *plugins.PluginMetadata) { | ||
hostname, err := os.Hostname() | ||
|
||
if err != nil { | ||
log.Errorf("Unable to retrieve hostname from OS. %v", err) | ||
return | ||
} | ||
|
||
pluginmd.ECSMetadata = &plugins.ECSMetadata{ContainerName: hostname} | ||
pluginmd.Origin = Origin | ||
} |
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