Skip to content

Commit

Permalink
PMM-3298 Fix crash. (percona#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Nov 28, 2019
1 parent 6d64500 commit 7956cc9
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters-settings:
check-exported: true

unparam:
algo: rta
check-exported: true

linters:
Expand Down
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ matrix:
allow_failures:
- go: master

# skip non-trunk PMM-XXXX branch builds, but still build pull requests
branches:
except:
- /^PMM\-\d{4}/

cache:
directories:
- /home/travis/.cache/go-build
Expand All @@ -25,11 +30,10 @@ before_cache:

env:
global:
# Secure variables are not exposed for external pull requests: https://docs.travis-ci.com/user/pull-requests#Pull-Requests-and-Security-Restrictions
# AWS_ACCESS_KEY_ID
- secure: "yiT2b6FWyG2pUi8v2dHmCHG/6hgYqxnq+VGlR5OTvaaStj5oJOMAI4Jj4fVfEXVQOxuy9fWn+f1Q2ARlKkpZLO6rm6pfseXIAhkijcQ1dl8UjM5OV7s19egKeixKODD1WphBrKomOujyn6nuj71b8x1oIiZ5NOhgq9w51jdMAOI/aijz8BSBfmooARr2urNMlus8v59Y3t259ACTp+hAco8mR96BbFq7a33nQ0qgYLdro1FTdwel9EWvspMNhTSmi8I54zt0QVAeSqJ+DuqeYEudq01ZN+ya9HG/H2JvEnWPh1XO642tNh0Asg7dmtxsPp9XEHkEf8N/GUT6boQyagHsTmlo1TS9RjHMOtBK5Oa/HQ3lQ2Dqxpg1vnbBtYS2fgg6b/YEySv1ERV3kVvBc1N77YgnSdTrtMLopp3HbcA2xoRv0wv7IGn1uM8KBYDwBVOySjtXcAcCvNRVW+gnuVrqTA9z7GUREn1Rn8G38YcnYBDC7QkZTBM+Fh9ttAiD9J+DfdEg8tZ+0fhCfEBkAVkvAqtY+K/aNHBkcK0bE5KhLdcjORyQ4Q/vg9mEyqSyeN03mF5tCSIaljGWU/M/NWODzMC+0kSX2oLCWNiMLwNJqSzNS3OYTlnKLOUhtfNew7Qku10GtAI8zSOgjPPsqGTk3ZrRcRpqwXc7PGSJIKM="
# AWS_SECRET_ACCESS_KEY
- secure: "YsGaMb91LxFFrZa1+bfRQCM0LhKY1FDQKaBOegfMqhoOAe5skms9apYkum8/8GjEAn1I+zVfKQ69oTzRSxIIdt+in5I/wFpDp35PW3O56zS2E5jWBb6yIm3mv1aHBOYw3UB1prj/TDwsNs+UKNPMVGYob8lx5wri5NFVU7XTqUBSB1fRuxKYkadixlzBiN9aHO8Bz4pfPS0YE+9VZbmMgjGCOxnRWroBAQLhGxbJmhjreYmQ4xmpHYgAotAo9QjPiOHE1PiJyIPGOf6rQlWYYzW9dRfwqGmApoZKzF+xaG9IpGj+/zmrMUYov3ROsp0+X4vVeGXfbPqUdToVfE1m5ET+DfC59+V0tAyrfJoZjtQTplxKI4UN9TPtBKXqjhISiavViYlDyncAg4zBe6Mza8uTOog5phZhBVwq431IfKAIrJbKa58kblv4j7uzj/pwYPO9Vxhuzn6xM95I/7GAlPTUs1ARUMxkIDKXb2z/vQ5mmptJRHeC7d7vBqiuvc0juJ8BrGzmAVtNL3lDSH7HtrZuM0nxt+Vp9sL7cc4Biywi66HY8DV/MBzPCb3TC+qqMQ72NC5ZZC8zbb7O3P1x4e/uIs3qGDsS8Wq2QxlEMDV16f5p1tMnUJNloD6XQnu0IMWHs4lYX3vUcco9uBxc7uUuyxcCr0LMt6fUSuvR3eE="
# AWS - PMM Autotest account. TODO https://jira.percona.com/browse/PMM-4896
# Travis secrets are not exposed to pull requests from forks: https://docs.travis-ci.com/user/pull-requests#pull-requests-and-security-restrictions
- AWS_ACCESS_KEY=AKIAZPBRO3QWINUW4BHY
- secure: "cIBRl4mgANxn6XPIO2SODBuNiLMraqH7yJ21vMmLUpjPxEsTGTUtlhNU/fBcb7F62SXsV3MgyahslhCU/62SyQccuICzkP4V9gtfE8GCSG4upWA5ka1CwWPFNCTQz0xU01oXkNe9V4WLbe0cRYlR4SI0b4TRZrYy5pt4WkBKEXDBn3RYqCcNEFjL9sPYTMOZKGc1mYtIJHNjwEYtv+7rAm0YRvvPmQnVeMXK2uZZcvmhxhHJfqUuKJYeyuC7CtTVh3QKdm7FpmXFVmFRFpcEQNqBwEE6W2mWnByKt/P8seBkcuVsYWAHDtN9JmbCN7/VhVm4pb/sFHuAJ3lm4PM9Q15r7GVmwEurVhNsi9S0oai/n4tbC9U63HPKLcq04UeXYp/K6tv6uGBL7+GTfFLnkG+YsM3Npj+O4NozTniX9vvvd3irbgXl8B5LzTz+/ypv4DV69eweoG1+xlME7iOrBMz/lQPDB9lIn8P9KEAiKpnnBbjJulBLVcG8j3WUqRw8rQFQA94UfqWL3g5FBxkQXoNNoRxFz0lXUA2nPw2maxQBThs4Awzg/yhm15ipAE49/wefLf+ZnEyfhOUHkQTzb7lj3RN7Mh7lfj7l6XR8YnHIkzWXXTp2sfVoDqQIVV2jRr4uBNOGIoXzXn6QEvxjy5ou0MlBbivU6usL7i0Y+yE="

script:
- make travis
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ instances:
If `aws_access_key` and `aws_secret_key` are present, they are used for that instance.
Otherwise, [default credential provider chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
is used, which includes `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables, `~/.aws/credentials` file,
is used, which includes `AWS_ACCESS_KEY_ID`/`AWS_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY`/`AWS_SECRET_KEY` environment variables, `~/.aws/credentials` file,
and IAM role for EC2.


Expand Down
10 changes: 8 additions & 2 deletions basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
for _, instance := range instances {
instance := instance
go func() {
NewScraper(&instance, e, ch).Scrape()
wg.Done()
defer wg.Done()

s := NewScraper(&instance, e, ch)
if s == nil {
e.l.Errorf("No scraper for %s, skipping.", instance)
return
}
s.Scrape()
}()
}
}
Expand Down
3 changes: 3 additions & 0 deletions basic/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Scraper struct {
func NewScraper(instance *config.Instance, exporter *Exporter, ch chan<- prometheus.Metric) *Scraper {
// Create CloudWatch client
sess, _ := exporter.sessions.GetSession(instance.Region, instance.Instance)
if sess == nil {
return nil
}
svc := cloudwatch.New(sess)

// Create labels for all metrics
Expand Down
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ type Instance struct {
AWSSecretKey string `yaml:"aws_secret_key"` // may be empty
}

func (i Instance) String() string {
res := i.Region + "/" + i.Instance
if i.AWSAccessKey != "" {
res += " (" + i.AWSAccessKey + ")"
}

return res
}

// Config contains configuration file information.
type Config struct {
Instances []Instance `yaml:"instances"`
Expand Down
2 changes: 1 addition & 1 deletion sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func New(instances []config.Instance, client *http.Client, trace bool) (*Session
newInstances := make([]Instance, 0, len(instances))
for _, instance := range instances {
if instance.ResourceID == "" {
logger.Errorf("Skipping instance %s/%s - can't determine resourceID.", instance.Region, instance.Instance)
logger.Errorf("Skipping %s - can't determine resourceID.", instance, instance)
continue
}
newInstances = append(newInstances, instance)
Expand Down
4 changes: 2 additions & 2 deletions sessions/sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func TestSession(t *testing.T) {
{
Region: "us-east-1",
Instance: "rds-aurora57",
AWSAccessKey: os.Getenv("AWS_ACCESS_KEY_ID"),
AWSSecretKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
AWSAccessKey: os.Getenv("AWS_ACCESS_KEY"),
AWSSecretKey: os.Getenv("AWS_SECRET_KEY"),
},
{
Region: "us-east-1",
Expand Down

0 comments on commit 7956cc9

Please sign in to comment.