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

Adding ability to automatically close incident in PagerDuty #486

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

tantra35
Copy link

Adding ability to automatically close incident in PagerDuty when moira decided that alert is resolved(send OK status).

This change conform incident lifecycle, that described in https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

For playing with api link below can be used:
https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

…ra decided that alert is resolved(send OK status).

This change conform incident lifecycle, that described in https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2
@tantra35 tantra35 requested a review from a team as a code owner January 16, 2020 13:24
senders/pagerduty/send.go Outdated Show resolved Hide resolved
senders/pagerduty/send.go Outdated Show resolved Hide resolved
Copy link
Contributor

@litleleprikon litleleprikon left a comment

Choose a reason for hiding this comment

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

Please, fix tests to pass CI

senders/pagerduty/send.go Outdated Show resolved Hide resolved
@litleleprikon
Copy link
Contributor

You have failing tests. Please fix it before we can merge your PR into master. CI log:

=== RUN   TestBuildEvent

  Build pagerduty event tests 
    Build pagerduty event with one moira event ✘
    Build pagerduty event with one moira event and plot ✘
    Build pagerduty event with one event and throttled ✘
    Build pagerduty event with 10 events and throttled ✘


Failures:

  * /home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go 
  Line 69:
  Expected: 'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  Actual:   'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"TriggerID", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  (Should resemble)!
  Diff:     'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"�[32mTriggerID�[0m", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  goroutine 8 [running]:
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:143 +0x6d
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:103 +0x6c
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:176 +0xec
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:125 +0x63
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1.1()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:69 +0x47b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:163 +0x48
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId(0xc000106960)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:19 +0x111
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106900, 0xc00000f200)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:162 +0x1bf
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:77 +0x92
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:59 +0x54c
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:110 +0xfb
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId.func1()
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0x2e
  github.com/jtolds/gls._m(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:108 +0x31
  github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:56 +0x35
  github.com/jtolds/gls.addStackTag(...)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:49
  github.com/jtolds/gls.EnsureGoroutineId(0xc0001067e0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0xdf
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106780, 0xc00000f140)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:105 +0x227
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:75 +0xbe
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent(0xc0000ee400)
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:23 +0x352
  testing.tRunner(0xc0000ee400, 0x7bc878)
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:909 +0xc9
  created by testing.(*T).Run
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:960 +0x350
  

  * /home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go 
  Line 91:
  Expected: 'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"", Images:[]interface{}{map[string]string{"alt":"Plot", "src":"test"}}, Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  Actual:   'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"TriggerID", Images:[]interface{}{map[string]string{"alt":"Plot", "src":"test"}}, Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  (Should resemble)!
  Diff:     'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"�[32mTriggerID�[0m", Images:[]interface{}{map[string]string{"alt":"Plot", "src":"test"}}, Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  goroutine 8 [running]:
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:143 +0x6d
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:103 +0x6c
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:176 +0xec
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:125 +0x63
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1.2()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:91 +0x6e2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:163 +0x48
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId(0xc000106f30)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:19 +0x111
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106ed0, 0xc00000f540)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:162 +0x1bf
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:77 +0x92
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:72 +0x6c7
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:110 +0xfb
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId.func1()
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0x2e
  github.com/jtolds/gls._m(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:108 +0x31
  github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:56 +0x35
  github.com/jtolds/gls.addStackTag(...)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:49
  github.com/jtolds/gls.EnsureGoroutineId(0xc0001067e0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0xdf
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106780, 0xc00000f140)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:105 +0x227
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:75 +0xbe
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent(0xc0000ee400)
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:23 +0x352
  testing.tRunner(0xc0000ee400, 0x7bc878)
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:909 +0xc9
  created by testing.(*T).Run
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:960 +0x350
  

  * /home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go 
  Line 105:
  Expected: 'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  Actual:   'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"TriggerID", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  (Should resemble)!
  Diff:     'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"�[32mTriggerID�[0m", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  goroutine 8 [running]:
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:143 +0x6d
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:103 +0x6c
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:176 +0xec
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:125 +0x63
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1.3()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:105 +0x4d4
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:163 +0x48
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId(0xc0001073b0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:19 +0x111
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000107350, 0xc00000f840)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:162 +0x1bf
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:77 +0x92
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:94 +0x839
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:110 +0xfb
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId.func1()
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0x2e
  github.com/jtolds/gls._m(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:108 +0x31
  github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:56 +0x35
  github.com/jtolds/gls.addStackTag(...)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:49
  github.com/jtolds/gls.EnsureGoroutineId(0xc0001067e0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0xdf
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106780, 0xc00000f140)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:105 +0x227
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:75 +0xbe
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent(0xc0000ee400)
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:23 +0x352
  testing.tRunner(0xc0000ee400, 0x7bc878)
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:909 +0xc9
  created by testing.(*T).Run
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:960 +0x350
  

  * /home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go 
  Line 133:
  Expected: 'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  Actual:   'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"TriggerID", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  (Should resemble)!
  Diff:     'pagerduty.V2Event{RoutingKey:"mock routing key", Action:"trigger", DedupKey:"�[32mTriggerID�[0m", Images:[]interface{}(nil), Client:"", ClientURL:"", Payload:(*pagerduty.V2Payload){Summary:"NODATA Trigger Name [tag1][tag2]", Source:"moira", Severity:"warning", Timestamp:"1974-10-03T02:40:00Z", Component:"", Group:"", Class:"", Details:map[string]interface{}{"Description":"bold text italics code regular", "Events":"\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)\n02:40: Metric name = 97.4458331200185 (OK to NODATA)", "Message":"Please, fix your system or tune this trigger to generate less events.", "Trigger Name":"Trigger Name", "Trigger URI":"http://moira.url/trigger/TriggerID"}}}'
  goroutine 8 [running]:
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:143 +0x6d
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/reporting/reports.go:103 +0x6c
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:176 +0xec
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:125 +0x63
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1.4()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:133 +0x601
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:163 +0x48
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId(0xc000107680)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:19 +0x111
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000107620, 0xc00000f9e0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:162 +0x1bf
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:77 +0x92
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent.func1()
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:108 +0x9a1
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/discovery.go:80 +0x24
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:261 +0x1b2
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:110 +0xfb
  github.com/jtolds/gls.(*ContextManager).SetValues.func1(0x0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:97 +0x466
  github.com/jtolds/gls.EnsureGoroutineId.func1()
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0x2e
  github.com/jtolds/gls._m(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:108 +0x31
  github.com/jtolds/gls.github_com_jtolds_gls_markS(0x0, 0xc00000f180)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:56 +0x35
  github.com/jtolds/gls.addStackTag(...)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/stack_tags.go:49
  github.com/jtolds/gls.EnsureGoroutineId(0xc0001067e0)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/gid.go:24 +0xdf
  github.com/jtolds/gls.(*ContextManager).SetValues(0xc000033500, 0xc000106780, 0xc00000f140)
  	/home/travis/gopath/pkg/mod/github.com/jtolds/[email protected]+incompatible/context.go:63 +0x14b
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/context.go:105 +0x227
  	/home/travis/gopath/pkg/mod/github.com/smartystreets/[email protected]/convey/doc.go:75 +0xbe
  github.com/moira-alert/moira/senders/pagerduty.TestBuildEvent(0xc0000ee400)
  	/home/travis/gopath/src/github.com/moira-alert/moira/senders/pagerduty/send_test.go:23 +0x352
  testing.tRunner(0xc0000ee400, 0x7bc878)
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:909 +0xc9
  created by testing.(*T).Run
  	/home/travis/.gimme/versions/go1.13.1.linux.amd64/src/testing/testing.go:960 +0x350
  


13 total assertions

--- FAIL: TestBuildEvent (0.01s)
FAIL
coverage: 79.7% of statements
exit status 1
FAIL	github.com/moira-alert/moira/senders/pagerduty	0.010s
FAIL

@litleleprikon
Copy link
Contributor

@tantra35 Would you like to fix tests for this PR?

@tantra35
Copy link
Author

@litleleprikon we will try

@tantra35
Copy link
Author

@litleleprikon how we can launch make lint? if it reports tons of erross like this

goroutine 2545 [semacquire, 76 minutes]:
sync.runtime_SemacquireMutex(0xc000fb4054, 0x0, 0x1)
        /usr/local/go/src/runtime/sema.go:71 +0x47
sync.(*Mutex).lockSlow(0xc000fb4050)
        /usr/local/go/src/sync/mutex.go:138 +0xfc
sync.(*Mutex).Lock(...)
        /usr/local/go/src/sync/mutex.go:81
sync.(*Once).doSlow(0xc000fb404c, 0xc001c68f68)
        /usr/local/go/src/sync/once.go:62 +0x122
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:57
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyzeRecursive(0xc000fb4000, 0x2, 0xc000eee120)
        /Users/denis/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:987 +0x7e
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyzeRecursive.func1.1(0x2, 0xc000eee120, 0xc000772900, 0xc000fb4000)
        /Users/denis/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:993 +0x3f
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyzeRecursive.func1
        /Users/denis/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner.go:992 +0x113

@coveralls
Copy link

coveralls commented Feb 18, 2020

Coverage Status

Coverage decreased (-0.01%) to 80.477% when pulling 093c90d on tantra35:pagerduty-autoresolve into ac13c29 on moira-alert:master.

@litleleprikon
Copy link
Contributor

@tantra35 which version of go are you using?

@tantra35
Copy link
Author

@litleleprikon we use 1.13

@litleleprikon
Copy link
Contributor

@tantra35 I do not know why you are not able to run linter but my general advice will be to use docker container to run linter

@@ -61,10 +62,16 @@ func (sender *Sender) buildEvent(events moira.NotificationEvents, contact moira.
Details: details,
}

action := "trigger"
Copy link
Contributor

Choose a reason for hiding this comment

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

May we move this string literals to constants?

Copy link
Author

Choose a reason for hiding this comment

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

Hm, I doesn't understand, why this needed? In official library which you use (https://github.com/PagerDuty/go-pagerduty), those doesn't defined as constants, so it's very strange to invent abstractions if the authors of official library did not provide them themselves

Copy link
Contributor

Choose a reason for hiding this comment

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

I just do not like string literals and magic numbers placed in random places in the code. The reason to place this values in constants is that it will be easier to change values in one place if pagerduty will change their API. I know that right now this values are placed only in two places but in future we can have more complex condition of action choose.

@@ -43,6 +43,7 @@ func TestBuildEvent(t *testing.T) {
baseExpected := pagerduty.V2Event{
RoutingKey: contact.Value,
Action: "trigger",
DedupKey: "TriggerID",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to see more complex example of switching states between trigger and resolved in tests

Copy link
Author

Choose a reason for hiding this comment

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

@litleleprikon Sorry but i can't imagine wthat you want:-), can you clarify? Dedupkey is simple trigger id, it doesn't add additional logic

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not about the DeduceKey it's about whole tests I just found a first change in tests file to add my comment. My point is that we want to see that action set correctly and this lead us to this additional tests:

  • with trigger in ERROR state and action set to trigger
  • with trigger in OK state and action set to resolve
  • with trigger in NODATA state
  • with trigger in WARN state

In two last cases the action will be trigger but is it the right state?

@@ -61,10 +62,16 @@ func (sender *Sender) buildEvent(events moira.NotificationEvents, contact moira.
Details: details,
}

action := "trigger"
Copy link
Contributor

Choose a reason for hiding this comment

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

I just do not like string literals and magic numbers placed in random places in the code. The reason to place this values in constants is that it will be easier to change values in one place if pagerduty will change their API. I know that right now this values are placed only in two places but in future we can have more complex condition of action choose.

@litleleprikon
Copy link
Contributor

Hi @tantra35 this PR is almost ready to be merged into master. Would you like to rebase on a new master and fix issues?

@b17k0
Copy link

b17k0 commented Apr 30, 2020

@tantra35 please complete this PR. Personally, we are really looking forward to the appearance of this PR in the master branch. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants