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

Notifications chef client runs skip ignored failure #634

Merged
merged 3 commits into from
Jun 20, 2019

Conversation

lancewf
Copy link
Contributor

@lancewf lancewf commented Jun 19, 2019

🔩 Description

Notifications from failed CCRs should skip resource failures that are marked 'ignore_failure' = true. The bug was found in the gateway CCR parsing code. When trying to parse the boolean flag the error variable was checked incorrectly.

👟 Demo Script / Repro Steps

  1. start_all_services
  2. Create a requestbin URL to send notifications from http://requestbin.sjcmmsn.com/
  3. Create a Slack, 'Chef client run failures' notification with the webhook pointing to the URL created in the line above in Automate (https://a2-dev.test/settings/notifications).
  4. JSON_FILE=/src/inspec/a2-api-integration/files/fixtures/converge/converge-failure-report_with_ignored_failure_run_converge.json send_chef_run_example lb
  5. Check the requestbin notification to ensure that there is a "attachments" -> "fields" -> "value" with "insights-ignored::default"'. This is incorrect because the "insights-ignored" failure was marked "ignore_failure" = true.
  6. Now lets apply the bug fix, rebuild components/automate-gateway
  7. Send the Same CCR again JSON_FILE=/src/inspec/a2-api-integration/files/fixtures/converge/converge-failure-report_with_ignored_failure_run_converge.json send_chef_run_example lb
  8. Check the requestbin for the new notification and ensure that there is a "attachments" -> "fields" -> "value" with "insights-real::default"'.

⛓️ Related Resources

#529

✅ Checklist

  • Necessary tests added/updated?
  • Necessary docs added/updated?
  • Code actually executed?
  • Vetting performed (unit tests, lint, etc.)?

@lancewf lancewf added the WIP label Jun 19, 2019
@lancewf lancewf requested a review from a team as a code owner June 19, 2019 00:44
@lancewf lancewf force-pushed the lancewf/notifiction_skip_ignored_failure branch from f16f4e2 to b8a7343 Compare June 19, 2019 21:27
@lancewf lancewf added automate-gateway notifications This issue or pull request pertains to notifications in Automate labels Jun 19, 2019
@@ -385,7 +385,7 @@ func getBoolIfExists(fieldName string, body []byte) bool {
fieldBytes, _, _, err := jsonparser.Get(body, fieldName)
if err == nil {
b, err := jsonparser.ParseBoolean(fieldBytes)
if err != nil {
if err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change fixes the bug.

Choose a reason for hiding this comment

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

could you add a comment saying why we do the err == nil check here? i know you included some info about it in the pr, but i think our future selves might appreciate having a comment in the code there

@@ -169,7 +169,7 @@ func TestDataCollectorParseBytesToChefRunFailure(t *testing.T) {
assert.Equal(t, "", res1.Delta)
assert.Equal(t, "insights-test", res1.CookbookName)
assert.Equal(t, "0.1.1", res1.CookbookVersion)
assert.Equal(t, false, res1.IgnoreFailure.GetBoolValue())
assert.Equal(t, true, res1.IgnoreFailure.GetBoolValue())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only real change to this test. The other tests are the go simplification.

@@ -3127,7 +3127,7 @@
"before": {},
"duration": "0",
"delta": "",
"ignore_failure": false,
"ignore_failure": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows the above test to check if the valve is converted correctly.

Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf force-pushed the lancewf/notifiction_skip_ignored_failure branch from b8a7343 to 27a9ca9 Compare June 19, 2019 22:02
@lancewf lancewf changed the title WIP: Notifications chef client runs skip ignored failure Notifications chef client runs skip ignored failure Jun 19, 2019
@lancewf lancewf requested review from a team and removed request for a team June 19, 2019 22:03
@lancewf lancewf removed the WIP label Jun 19, 2019
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@@ -34,6 +34,24 @@
end
end

#converge-failure-with-ignored-failure-report_run_converge
let(:failed_ccr_message_with_ignored_failure) do
return @failed_ccr_json ||= begin
Copy link
Contributor

Choose a reason for hiding this comment

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

Memoizing with an instance variable inside a let block is redundant, and it is dangerous in this case since the instance variable will be set by the first let to be referenced.

expect(after_request_count).to eq(before_request_count + 1)

# get the last sent notification
notification = JSON.parse(request.body, symbolize_names: true)[:requests][before_request_count]
Copy link
Contributor

@phiggins phiggins Jun 19, 2019

Choose a reason for hiding this comment

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

Nitpick: instead of accessing this by indexing into the array, you could replace [before_request_count] with .last.

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 always forget how friendly Ruby is with lists.

Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf merged commit d85b992 into master Jun 20, 2019
@chef-ci chef-ci deleted the lancewf/notifiction_skip_ignored_failure branch June 20, 2019 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automate-gateway notifications This issue or pull request pertains to notifications in Automate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants