Skip to content

Conversation

@AlekSi
Copy link

@AlekSi AlekSi commented Dec 12, 2019

No description provided.

@AlekSi AlekSi self-assigned this Dec 12, 2019
// set explicit keys to first instance to test grouping
cfg.Instances[0].AWSAccessKey = os.Getenv("AWS_ACCESS_KEY")
cfg.Instances[0].AWSSecretKey = os.Getenv("AWS_SECRET_KEY")
if cfg.Instances[0].AWSAccessKey == "" || cfg.Instances[0].AWSSecretKey == "" {

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 if statement (from wsl)

if am56s == p10s {
assert.Fail(t, "autotest-aurora-mysql-56 and autotest-psql-10 should not share session - different keys (implicit and explicit)")
}
if p10s == m57s {

Choose a reason for hiding this comment

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

if statements should only be cuddled with assignments (from wsl)

}
if a1s != m56s {
assert.Fail(t, "rds-aurora1 and rds-mysql56 should share session")
if m57s != ap11s {

Choose a reason for hiding this comment

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

if statements should only be cuddled with assignments (from wsl)

}
if m57s != nil {
assert.Fail(t, "rds-mysql57 should be skipped")
if ns != nil {

Choose a reason for hiding this comment

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

if statements should only be cuddled with assignments (from wsl)

Swap swap `json:"swap"`
Tasks tasks `json:"tasks"`

// TODO Handle this: https://jira.percona.com/browse/PMM-3835

Choose a reason for hiding this comment

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

enhanced/metrics.go:41: Line contains TODO/BUG/FIXME: "TODO Handle this: https://jira.percona.c..." (from godox)

TGID int `json:"tgid" help:"The thread group identifier, which is a number representing the process ID to which a thread belongs. This identifier is used to group threads from the same process."`
VSS int `json:"vss" help:"The amount of virtual memory allocated to the process, in kilobytes."`

// TODO Handle this.

Choose a reason for hiding this comment

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

enhanced/metrics.go:140: Line contains TODO/BUG/FIXME: "TODO Handle this." (from godox)

func parseOSMetrics(b []byte) (*osMetrics, error) {
func parseOSMetrics(b []byte, disallowUnknownFields bool) (*osMetrics, error) {
d := json.NewDecoder(bytes.NewReader(b))
if disallowUnknownFields {

Choose a reason for hiding this comment

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

if statements should only be cuddled with assignments used in the if statement itself (from wsl)

for i := 0; i < t.NumField(); i++ {
tags := t.Field(i).Tag
name, help := tags.Get("json"), tags.Get("help")
if help == "-" {

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 if statement (from wsl)


var (
golden = flag.Bool("golden", false, "update both golden .json and .txt files")
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)

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

func readTestDataJSON(t *testing.T, instance string) []byte {

Choose a reason for hiding this comment

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

func readTestDataJSON is unused (from unused)

require.NoError(t, err)
}

func readTestDataMetrics(t *testing.T, instance string) []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)

)

var (
golden = flag.Bool("golden", false, "update both golden .json and .txt files")

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)

return bytes.TrimSpace(b)
}

func writeTestDataJSON(t *testing.T, instance string, b []byte) {

Choose a reason for hiding this comment

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

func writeTestDataJSON is unused (from unused)

if allMessages[instance.ResourceID] == nil {
allMessages[instance.ResourceID] = make(map[time.Time]string)
}
allMessages[instance.ResourceID][timestamp] = *event.Message

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)

resMessages[resourceID] = allMessages[resourceID][timestamp]
}
return res
return resMetrics, resMessages

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)


b, err := ioutil.ReadFile(filepath.Join("testdata", instance+".json")) //nolint:gosec
require.NoError(t, err)
return bytes.TrimSpace(b)

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)


b, err := ioutil.ReadFile(filepath.Join("testdata", instance+".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)

// if JSON was updated, update metrics too
if !t.Failed() && *golden {
*goldenTXT = true
TestParse(t)

Choose a reason for hiding this comment

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

only cuddled expressions if assigning variable or using from line above (from wsl)

return strings.Split(string(bytes.TrimSpace(b)), "\n")
}

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)


var (
golden = flag.Bool("golden", false, "does nothing; exists only for compatibility with other packages")
goldenTXT = flag.Bool("golden-txt", 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 goldenTXT is unused (from unused)


var (
golden = flag.Bool("golden", false, "does nothing; exists only for compatibility with other packages")
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 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)

)

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")
)

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)

)

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)

@codecov
Copy link

codecov bot commented Dec 13, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@03bab8a). Click here to learn what that means.
The diff coverage is 74.28%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #34   +/-   ##
=========================================
  Coverage          ?   81.59%           
=========================================
  Files             ?        9           
  Lines             ?      739           
  Branches          ?        0           
=========================================
  Hits              ?      603           
  Misses            ?      118           
  Partials          ?       18
Impacted Files Coverage Δ
enhanced/collector.go 0% <0%> (ø)
enhanced/metrics.go 94.86% <77.77%> (ø)
enhanced/scraper.go 76.85% <79.16%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03bab8a...c4e189b. Read the comment docs.


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)

@AlekSi AlekSi marked this pull request as ready for review December 13, 2019 20:02
@AlekSi AlekSi requested a review from BupycHuk December 13, 2019 20:02
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)

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)

for _, m := range expectedMetrics {
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)

osMetrics, err := parseOSMetrics([]byte(*event.Message), s.testDisallowUnknownFields)
if err != nil {
// only for tests
if s.testDisallowUnknownFields {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need it? How can it help with tests?

Copy link
Author

Choose a reason for hiding this comment

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

This field is set to true in tests. When there are new metrics in CloudWatch Logs, tests will fail.
See discussion at https://jira.percona.com/browse/PMM-3835 for some more background.

t.Run(fmt.Sprint(instances), func(t *testing.T) {
// test that there are no new metrics
s := newScraper(session, instances)
s.testDisallowUnknownFields = true
Copy link
Author

Choose a reason for hiding this comment

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

@BupycHuk there

@AlekSi AlekSi merged commit ade0b0a into master Dec 17, 2019
@AlekSi AlekSi deleted the PMM-1772-use-stable-instances-for-tests branch December 17, 2019 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants