Skip to content
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

Fix golint warnings #170

Merged
merged 20 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions awsplugins/beanstalk/beanstalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"github.com/aws/aws-xray-sdk-go/internal/plugins"
)

// Origin is the type of AWS resource that runs your application.
const Origin = "AWS::ElasticBeanstalk::Environment"

// Init activates ElasticBeanstalkPlugin at runtime.
func Init() {
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.BeanstalkMetadata == nil {
addPluginMetadata(plugins.InstancePluginMetadata)
Expand Down
2 changes: 2 additions & 0 deletions awsplugins/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/aws/aws-xray-sdk-go/internal/plugins"
)

// Origin is the type of AWS resource that runs your application.
const Origin = "AWS::EC2::Instance"

// Init activates EC2Plugin at runtime.
func Init() {
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.EC2Metadata == nil {
addPluginMetadata(plugins.InstancePluginMetadata)
Expand Down
2 changes: 2 additions & 0 deletions awsplugins/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/aws/aws-xray-sdk-go/internal/plugins"
)

// Origin is the type of AWS resource that runs your application.
const Origin = "AWS::ECS::Container"

// Init activates ECSPlugin at runtime.
func Init() {
if plugins.InstancePluginMetadata != nil && plugins.InstancePluginMetadata.ECSMetadata == nil {
addPluginMetadata(plugins.InstancePluginMetadata)
Expand Down
21 changes: 11 additions & 10 deletions daemoncfg/daemon_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// 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 daemoncfg

import (
Expand All @@ -21,12 +22,12 @@ var addressDelimiter = " " // delimiter between tcp and udp addresses
var udpKey = "udp"
var tcpKey = "tcp"

/// DaemonEndpoints stores X-Ray daemon configuration about the ip address and port for UDP and TCP port. It gets the address
/// string from "AWS_TRACING_DAEMON_ADDRESS" and then from recorder's configuration for DaemonAddr.
/// A notation of '127.0.0.1:2000' or 'tcp:127.0.0.1:2000 udp:127.0.0.2:2001' or 'udp:127.0.0.1:2000 tcp:127.0.0.2:2001'
/// are both acceptable. The first one means UDP and TCP are running at the same address.
/// Notation 'hostname:2000' or 'tcp:hostname:2000 udp:hostname:2001' or 'udp:hostname:2000 tcp:hostname:2001' are also acceptable.
/// By default it assumes a X-Ray daemon running at 127.0.0.1:2000 listening to both UDP and TCP traffic.
// DaemonEndpoints stores X-Ray daemon configuration about the ip address and port for UDP and TCP port. It gets the address
// string from "AWS_TRACING_DAEMON_ADDRESS" and then from recorder's configuration for DaemonAddr.
// A notation of '127.0.0.1:2000' or 'tcp:127.0.0.1:2000 udp:127.0.0.2:2001' or 'udp:127.0.0.1:2000 tcp:127.0.0.2:2001'
// are both acceptable. The first one means UDP and TCP are running at the same address.
// Notation 'hostname:2000' or 'tcp:hostname:2000 udp:hostname:2001' or 'udp:hostname:2000 tcp:hostname:2001' are also acceptable.
// By default it assumes a X-Ray daemon running at 127.0.0.1:2000 listening to both UDP and TCP traffic.
type DaemonEndpoints struct {
// UDPAddr represents UDP endpoint for segments to be sent by emitter.
UDPAddr *net.UDPAddr
Expand Down Expand Up @@ -93,13 +94,13 @@ func GetDaemonEndpointsFromString(dAddr string) (*DaemonEndpoints, error) {

func resolveAddress(dAddr string) (*DaemonEndpoints, error) {
addr := strings.Split(dAddr, addressDelimiter)
if len(addr) == 1 {
switch len(addr) {
case 1:
return parseSingleForm(addr[0])
} else if len(addr) == 2 {
case 2:
return parseDoubleForm(addr)
} else {
return nil, errors.New("invalid daemon address: " + dAddr)
}
return nil, errors.New("invalid daemon address: " + dAddr)
}

func parseDoubleForm(addr []string) (*DaemonEndpoints, error) {
Expand Down
16 changes: 9 additions & 7 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ const (
)

func samplingDecision(s string) SamplingDecision {
if s == string(Sampled) {
switch s {
case string(Sampled):
return Sampled
} else if s == string(NotSampled) {
case string(NotSampled):
return NotSampled
} else if s == string(Requested) {
case string(Requested):
return Requested
}
return Unknown
Expand All @@ -84,13 +85,14 @@ func FromString(s string) *Header {
p := strings.TrimSpace(parts[i])
value, valid := valueFromKeyValuePair(p)
if valid {
if strings.HasPrefix(p, RootPrefix) {
switch {
case strings.HasPrefix(p, RootPrefix):
ret.TraceID = value
} else if strings.HasPrefix(p, ParentPrefix) {
case strings.HasPrefix(p, ParentPrefix):
ret.ParentID = value
} else if strings.HasPrefix(p, SampledPrefix) {
case strings.HasPrefix(p, SampledPrefix):
ret.SamplingDecision = samplingDecision(p)
} else if !strings.HasPrefix(p, SelfPrefix) {
case !strings.HasPrefix(p, SelfPrefix):
key, valid := keyFromKeyValuePair(p)
if valid {
ret.AdditionalData[key] = value
Expand Down
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// This internal package hides the actual logging functions from the user.

// The Logger instance used by xray to log. Set via xray.SetLogger().
// Logger instance used by xray to log. Set via xray.SetLogger().
var Logger xraylog.Logger = xraylog.NewDefaultLogger(os.Stdout, xraylog.LogLevelInfo)

func Debugf(format string, args ...interface{}) {
Expand Down
7 changes: 6 additions & 1 deletion internal/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
package plugins

const (
EBServiceName = "elastic_beanstalk"
// EBServiceName is the key name for metadata of ElasticBeanstalkPlugin.
EBServiceName = "elastic_beanstalk"

// EC2ServiceName is the key name for metadata of EC2Plugin.
EC2ServiceName = "ec2"

// ECSServiceName is the key name for metadata of ECSPlugin.
ECSServiceName = "ecs"
)

Expand Down
44 changes: 25 additions & 19 deletions pattern/search_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ package pattern
import "strings"

// WildcardMatchCaseInsensitive returns true if text matches pattern (case-insensitive); returns false otherwise.
func WildcardMatchCaseInsensitive(pattern string, text string) bool {
func WildcardMatchCaseInsensitive(pattern, text string) bool {
return WildcardMatch(pattern, text, true)
}

// WildcardMatch returns true if text matches pattern at the given case-sensitivity; returns false otherwise.
func WildcardMatch(pattern string, text string, caseInsensitive bool) bool {
func WildcardMatch(pattern, text string, caseInsensitive bool) bool {
patternLen := len(pattern)
textLen := len(text)
if 0 == patternLen {
return 0 == textLen
if patternLen == 0 {
return textLen == 0
}

if pattern == "*" {
Expand All @@ -41,23 +41,29 @@ func WildcardMatch(pattern string, text string, caseInsensitive bool) bool {
pStar := 0

for i < textLen {
if p < patternLen && pattern[p] == text[i] {
i++
p++
} else if p < patternLen && '?' == pattern[p] {
i++
p++
} else if p < patternLen && pattern[p] == '*' {
iStar = i
pStar = p
p++
} else if iStar != textLen {
iStar++
i = iStar
p = pStar + 1
} else {
if p < patternLen {
switch pattern[p] {
case text[i]:
i++
p++
continue
case '?':
i++
p++
continue
case '*':
iStar = i
pStar = p
p++
continue
}
}
if iStar == textLen {
return false
}
iStar++
i = iStar
p = pStar + 1
}

for p < patternLen && pattern[p] == '*' {
Expand Down
2 changes: 1 addition & 1 deletion pattern/search_pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMatchExactNegative(t *testing.T) {
assert.False(t, WildcardMatchCaseInsensitive("foo", "bar"))
}

func TestSignleWildcardPositive(t *testing.T) {
func TestSingleWildcardPositive(t *testing.T) {
assert.True(t, WildcardMatchCaseInsensitive("fo?", "foo"))
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/beanstalk/beanstalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package beanstalk

import "github.com/aws/aws-xray-sdk-go/awsplugins/beanstalk"

const Origin = "AWS::ElasticBeanstalk::Environment"
// Origin is the type of AWS resource that runs your application.
const Origin = beanstalk.Origin

func init() {
beanstalk.Init()
Expand Down
3 changes: 2 additions & 1 deletion plugins/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package ec2

import "github.com/aws/aws-xray-sdk-go/awsplugins/ec2"

const Origin = "AWS::EC2::Instance"
// Origin is the type of AWS resource that runs your application.
const Origin = ec2.Origin

func init() {
ec2.Init()
Expand Down
3 changes: 2 additions & 1 deletion plugins/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ package ecs

import "github.com/aws/aws-xray-sdk-go/awsplugins/ecs"

const Origin = "AWS::ECS::Container"
// Origin is the type of AWS resource that runs your application.
const Origin = ecs.Origin

func init() {
ecs.Init()
Expand Down
2 changes: 1 addition & 1 deletion strategy/sampling/centralized.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (ss *CentralizedStrategy) ShouldTrace(request *Request) *Decision {
logger.Debugf(
"Determining ShouldTrace decision for:\n\thost: %s\n\tpath: %s\n\tmethod: %s\n\tservicename: %s\n\tservicetype: %s",
request.Host,
request.Url,
request.URL,
request.Method,
request.ServiceName,
request.ServiceType,
Expand Down
16 changes: 8 additions & 8 deletions strategy/sampling/centralized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestShouldTracePositive1(t *testing.T) {

sr := &Request{
Host: host1,
Url: url1,
URL: url1,
Method: method1,
ServiceName: serviceName1,
ServiceType: servType1,
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestShouldTracePositive2(t *testing.T) {
// serviceType missing
sr := &Request{
Host: host1,
Url: url1,
URL: url1,
Method: method1,
ServiceName: serviceName1,
}
Expand Down Expand Up @@ -238,12 +238,12 @@ func TestShouldTracePositive2(t *testing.T) {
clock: clock,
}

startegy, _ := NewLocalizedStrategy()
strategy, _ := NewLocalizedStrategy()
s := &CentralizedStrategy{
manifest: m,
clock: clock,
rand: rand,
fallback: startegy,
fallback: strategy,
}

// Make positive sampling decision against 'r1'
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestShouldTraceDefaultPositive(t *testing.T) {

sr := &Request{
Host: "www.foo.bar.com",
Url: "/resource/bat",
URL: "/resource/bat",
Method: "GET",
}

Expand Down Expand Up @@ -415,7 +415,7 @@ func TestShouldTraceExpiredManifest(t *testing.T) {

sr := &Request{
Host: "www.foo.bar.com",
Url: "/resource/bar",
URL: "/resource/bar",
Method: "POST",
}

Expand Down Expand Up @@ -2597,7 +2597,7 @@ func TestLoadDaemonEndpoints1(t *testing.T) {

sr := &Request{
Host: host1,
Url: url1,
URL: url1,
Method: method1,
ServiceName: serviceName1,
ServiceType: servType1,
Expand All @@ -2622,7 +2622,7 @@ func TestLoadDaemonEndpoints2(t *testing.T) {

sr := &Request{
Host: host1,
Url: url1,
URL: url1,
Method: method1,
ServiceName: serviceName1,
ServiceType: servType1,
Expand Down
4 changes: 2 additions & 2 deletions strategy/sampling/localized.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func NewLocalizedStrategyFromJSONBytes(b []byte) (*LocalizedStrategy, error) {
// ShouldTrace consults the LocalizedStrategy's rule set to determine
// if the given request should be traced or not.
func (lss *LocalizedStrategy) ShouldTrace(rq *Request) *Decision {
logger.Debugf("Determining ShouldTrace decision for:\n\thost: %s\n\tpath: %s\n\tmethod: %s", rq.Host, rq.Url, rq.Method)
logger.Debugf("Determining ShouldTrace decision for:\n\thost: %s\n\tpath: %s\n\tmethod: %s", rq.Host, rq.URL, rq.Method)
if nil != lss.manifest.Rules {
for _, r := range lss.manifest.Rules {
if r.AppliesTo(rq.Host, rq.Url, rq.Method) {
if r.AppliesTo(rq.Host, rq.URL, rq.Method) {
logger.Debugf("Applicable rule:\n\tfixed_target: %d\n\trate: %f\n\thost: %s\n\turl_path: %s\n\thttp_method: %s", r.FixedTarget, r.Rate, r.Host, r.URLPath, r.HTTPMethod)
return r.Sample()
}
Expand Down
3 changes: 2 additions & 1 deletion strategy/sampling/reservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// 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.

// Reservoirs allow a specified (`perSecond`) amount of `Take()`s per second.
package sampling

import "github.com/aws/aws-xray-sdk-go/utils"

// Reservoirs allow a specified (`perSecond`) amount of `Take()`s per second.

// reservoir is a set of properties common to all reservoirs
type reservoir struct {
// Total size of reservoir
Expand Down
3 changes: 2 additions & 1 deletion strategy/sampling/sampling_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// 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 sampling

// Decision contains sampling decision and the rule matched for an incoming request
Expand All @@ -17,7 +18,7 @@ type Decision struct {
type Request struct {
Host string
Method string
Url string
URL string
ServiceName string
ServiceType string
}
5 changes: 3 additions & 2 deletions strategy/sampling/sampling_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *Properties) AppliesTo(host, path, method string) bool {
// Assumes lock is already held, if required.
func (r *CentralizedRule) AppliesTo(request *Request) bool {
return (request.Host == "" || pattern.WildcardMatchCaseInsensitive(r.Host, request.Host)) &&
(request.Url == "" || pattern.WildcardMatchCaseInsensitive(r.URLPath, request.Url)) &&
(request.URL == "" || pattern.WildcardMatchCaseInsensitive(r.URLPath, request.URL)) &&
(request.Method == "" || pattern.WildcardMatchCaseInsensitive(r.HTTPMethod, request.Method)) &&
(request.ServiceName == "" || pattern.WildcardMatchCaseInsensitive(r.ServiceName, request.ServiceName)) &&
(request.ServiceType == "" || pattern.WildcardMatchCaseInsensitive(r.serviceType, request.ServiceType))
Expand Down Expand Up @@ -190,7 +190,7 @@ func (r *CentralizedRule) snapshot() *xraySvc.SamplingStatisticsDocument {
return s
}

// Local Sampling Rule
// Rule is local sampling rule.
type Rule struct {
reservoir *Reservoir

Expand All @@ -201,6 +201,7 @@ type Rule struct {
*Properties
}

// Sample is ...
shogo82148 marked this conversation as resolved.
Show resolved Hide resolved
func (r *Rule) Sample() *Decision {
var sd Decision

Expand Down
Loading