Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.idea/
/.vscode/
rds_exporter
config.yml
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
tarball:
files:
- LICENSE
- config.yml
# - config.yml
crossbuild:
platforms:
- linux/amd64
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ before_cache:

env:
global:
# AWS - PMM Autotest account. TODO https://jira.percona.com/browse/PMM-4896
# AWS - PMM Autotest account.
# 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=AKIAZPBRO3QWKASXOQEZ
- secure: "ZsqWjlnthwiHrMCytHeYLzC6pasDzBYZAL4vPdx7+viGiahIoYDeN+FkoXASYP4Z9RachE3GKquXeTPKCjAJ0elvYKHe1PC6+BsZrQWVOIMMqa1vMOuPVAMk7ohDsE4JqzjxdWYAErxE/GgcE7+7F/s79d+x+zpg0c0DVkNiprFWYnz2liKX0Ya926anDUAfT1fsHfSjDETufrNs06jfNMroFbEN22ebxiKL8Xbip6f3fY2SEasmiQ5MhmjMreDTY1zemnTvsaMNzjzSou3z+zqV6Z/Xt/FrS4t42vmo37w9wLYUlREPR0FJ6Z+c5PI4l/+RdBKQfvlilZDIq60ZeF3uHE2tVlSMXaOtNS7EVO9vJjxWb2qSLWeh8kmGsT87sBocUVILFG3ibmnbPiGtW4rDxqgtYPnAaxDU8yQL72K1EDkuJytQIXXDefHZ/FA5/+UTzv3cCIF2OviIVx2oEHrnkbq+YPvyjLGzp+eg8/In8m5Mc63UoepknLvlz5JrUKYePj2IUuyI2Dvl7+O4qm5o+SvNutoeYJYsWrKkPiaDXfAJ+J4QMerO2qbF2AWCQHHfeTRK8Sn6geK0ZK8SXEVeIty5IA95Bt/pBZJ4ZCn8ehK3nvepLOwhy/gGyejrjMlG9rcAvAyvnSN8aT1cHJJaKkAlF22chLVQ1pIcukE="
- AWS_ACCESS_KEY=AKIAZPBRO3QWGCO72MJZ
- secure: "X8jXCbsnCkyEsZN11AQ5NgF5Wl84ZTWxr8LuWXgVZ/3QwRvY7rK25FZVwf8TQqF3wch92WFnSwF9jQ37cz0H6SOa+tQ0NHDhUGIqEfdIlIfb8lGvEEPsD3OPenqRZWDRFFoywgkqu+PZU2uuFW5gC93RbClgBGv4oy+NrJF+Etkikv6E+mMZQc0O/UtEZUyXvRnfKY0/zPAHPsSNtEBvk3Q2lAIsl31pfMn6m1rBxPmuHShsigo+smMZTGXkijIa/aXUNOxz5lXppjvMmbNAg4/3+46MHTDXLmX7irGaUMvKKi4Ya6Hvu9+6UGjInrothVN98Y2k2J+ERZooM7ND7kv3vn3RilYbBhnpsdmmpL0nEQYTsJBvaaWKRZMIxS0Xd21CKOSGN+8Omq9iBgiW1L87xKxYD78OF+2Z9VwzHHk+Oaq2ky3LT/z3WGtnMWpURSxvjw76neFIxoIMHFVIZh0kywrmObZy3mgF0zzC/jRU2PK/ie9k0LJhxuHoEeb4b55f1PmUfhCJ7KblE3x13SlUUQqnvIL7qscKL1nEtFl/kidHtBYJAZzi0ctb2mHduzi89VYKqu6w3S93HpQQLkqpg9+i+i890mQrpytFGrcGVj4SikIE1fwlv/V8MS9zZukvizSV9l/Z0hV5YDqqHPX0UICrf7w/u9vkZSsz45g="

script:
- make travis
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:latest

COPY rds_exporter /bin/
COPY config.yml /etc/rds_exporter/config.yml
# COPY config.yml /etc/rds_exporter/config.yml

RUN apk update && \
apk add ca-certificates && \
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 22 additions & 33 deletions basic/collector_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package basic

import (
"sort"
"testing"

"github.com/percona/exporter_shared/helpers"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -13,47 +13,36 @@ import (
"github.com/percona/rds_exporter/sessions"
)

func getCollector(t *testing.T) *Collector {
t.Helper()

func TestCollector(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func TestCollector is unused (from unused)

cfg, err := config.Load("../config.tests.yml")
require.NoError(t, err)
client := client.New()
sess, err := sessions.New(cfg.Instances, client.HTTP(), false)
require.NoError(t, err)
return New(cfg, sess)
}

func TestCollector_Describe(t *testing.T) {
c := getCollector(t)
ch := make(chan *prometheus.Desc)
go func() {
c.Describe(ch)
close(ch)
}()

const expected = 50
descs := make([]*prometheus.Desc, 0, expected)
for d := range ch {
descs = append(descs, d)
c := New(cfg, sess)

actualMetrics := helpers.ReadMetrics(helpers.CollectMetrics(c))
sort.Slice(actualMetrics, func(i, j int) bool { return actualMetrics[i].Less(actualMetrics[j]) })
actualLines := helpers.Format(helpers.WriteMetrics(actualMetrics))

if *goldenTXT {
writeTestDataMetrics(t, actualLines)
}

assert.Equal(t, expected, len(descs), "%+v", descs)
}
for _, m := range actualMetrics {
m.Value = 0
}
actualLines = helpers.Format(helpers.WriteMetrics(actualMetrics))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assignments should only be cuddled with other assignments (from wsl)


func TestCollector_Collect(t *testing.T) {
c := getCollector(t)
ch := make(chan prometheus.Metric)
go func() {
c.Collect(ch)
close(ch)
}()

const expected = 101
metrics := make([]helpers.Metric, 0, expected)
for m := range ch {
metrics = append(metrics, *helpers.ReadMetric(m))
expectedMetrics := helpers.ReadMetrics(helpers.Parse(readTestDataMetrics(t)))
sort.Slice(expectedMetrics, func(i, j int) bool { return expectedMetrics[i].Less(expectedMetrics[j]) })
for _, m := range expectedMetrics {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one cuddle assignment allowed before range statement (from wsl)

m.Value = 0
}
expectedLines := helpers.Format(helpers.WriteMetrics(expectedMetrics))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assignments should only be cuddled with other assignments (from wsl)


assert.Equal(t, expected, len(metrics), "%+v", metrics)
// compare both to try to avoid go-difflib bug
assert.Equal(t, expectedLines, actualLines)
assert.Equal(t, expectedMetrics, actualMetrics)
}
33 changes: 33 additions & 0 deletions basic/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package basic

import (
"bytes"
"flag"
"io/ioutil"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

var (
golden = flag.Bool("golden", false, "does nothing; exists only for compatibility with other packages")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var golden is unused (from unused)

goldenTXT = flag.Bool("golden-txt", false, "update golden .txt files")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var goldenTXT is unused (from unused)

)

func readTestDataMetrics(t *testing.T) []string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func readTestDataMetrics is unused (from unused)

t.Helper()

b, err := ioutil.ReadFile(filepath.Join("testdata", "all.txt")) //nolint:gosec
require.NoError(t, err)
return strings.Split(string(bytes.TrimSpace(b)), "\n")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return statements should not be cuddled if block has more than two lines (from wsl)

}

func writeTestDataMetrics(t *testing.T, metrics []string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func writeTestDataMetrics is unused (from unused)

t.Helper()

b := []byte(strings.TrimSpace(strings.Join(metrics, "\n")) + "\n")
err := ioutil.WriteFile(filepath.Join("testdata", "all.txt"), b, 0666)
require.NoError(t, err)
}
Loading