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

use AddError everywhere #2372

Merged
merged 1 commit into from
Apr 24, 2017
Merged

use AddError everywhere #2372

merged 1 commit into from
Apr 24, 2017

Conversation

phemmer
Copy link
Contributor

@phemmer phemmer commented Feb 7, 2017

Required for all PRs:

  • CHANGELOG.md updated (we recommend not updating this until the PR has been approved by a maintainer)
  • Sign CLA (if not already signed)

Closes #1446

Also addressed some of the issues described in #2326 (comment) by cleaning up some of the fmt.Printf() and log.Print() statements to use acc.AddError().

return a.Errors[0]
}
return nil
}
Copy link
Contributor Author

@phemmer phemmer Feb 7, 2017

Choose a reason for hiding this comment

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

I'm open to feedback on this method. I just wrote it as it made adjusting the tests a lot easier by not having to check both the return value of Gather() and any errors added by AddError().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I would prefer to accept a telegraf.Input interface, and then call the Gather() method on that interface instead of accepting the Gather function signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, but it's not critical, we can improve this latter

Copy link
Contributor Author

@phemmer phemmer Apr 22, 2017

Choose a reason for hiding this comment

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

Another improvement might be to add an acc.AddErrorf(). The majority of the usage is nesting an fmt.Errorf() inside acc.AddError(). Would just be a convenience.

Copy link
Contributor

Choose a reason for hiding this comment

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

Long term I think we need to allow access to log level as well, probably using a good logging library that allows control at a per logger basis (and one logger per plugin).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I proposed this a few times, but was always declined by your predecessor. Not sure what the reasons were though.
#1446 (comment)
#2326 (comment)

@@ -175,7 +175,7 @@ func TestHttpJsonOn404(t *testing.T) {

var acc testutil.Accumulator
acc.SetDebug(true)
err := jolokia.Gather(&acc)
err := acc.GatherError(jolokia.Gather)

assert.Nil(t, err)
Copy link
Contributor Author

@phemmer phemmer Feb 7, 2017

Choose a reason for hiding this comment

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

This test is failing because of a similar situation to the cassandra one. The code was previously printing an error, but is now being passed to AddError(). The problem here is that this test doesn't make much sense. It generates a stub that returns valid response JSON, but with a http 404 status code. Jolokia will not do this, thus the test seems bogus.

Given that the cassandra code seems to be based off the jolokia code, I'm betting the cassandra test that I previously commented on is bogus too.

@sparrc sparrc added this to the 1.3.0 milestone Feb 7, 2017
@@ -197,24 +197,25 @@ func TestHttpJsonJavaMultiType(t *testing.T) {
}

// Test that the proper values are ignored or collected
func TestHttpJsonOn404(t *testing.T) {
func TestHttp404(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a resolution to the earlier comment on this test, I'm changing the test to look for the error that is now passed via AddError(). Previous behavior of the plugin was that it was ignoring http-404 errors, and instead printing (not returning) an error when it failed to parse the response body. New behavior calls AddError() on both non-http-200 responses, as well as parse errors.

The cassandra plugin test was modified for the same reason.

@phemmer
Copy link
Contributor Author

phemmer commented Feb 8, 2017

CircleCI test is failing due to #2382 . Just keep running it. Eventually it'll pass.

Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

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

I'm going to push most of the remaining 1.3 features out and try to get the next release ready soon, but I'd like to merge this. Do you have time to rebase?

return a.Errors[0]
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, but it's not critical, we can improve this latter

@phemmer
Copy link
Contributor Author

phemmer commented Apr 20, 2017

I'm going to push most of the remaining 1.3 features out and try to get the next release ready soon, but I'd like to merge this. Do you have time to rebase?

Yeah, I doubt it'll be hard. When do you need it by? Hopefully I'll take care of it tonight.

@danielnelson
Copy link
Contributor

That will be good, probably try to branch for the release sometime early next week.

@phemmer
Copy link
Contributor Author

phemmer commented Apr 22, 2017

Rebased. Tests passing.

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.

3 participants