-
Notifications
You must be signed in to change notification settings - Fork 243
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
Priority field should be optional according to API spec #135
Comments
I don't think this is a bug in the API, but a bug introduced in this go-pagerduty library. I say that because it's possible to roll back and use an earlier version of this library and have things work. I have not tracked down exactly what is causing it, but I suspect related to this commit: So... via Go modules I can have this in module stuff
require (
github.com/google/go-querystring v1.0.0
github.com/pagerduty/go-pagerduty v0.0.0-20180528123509-b4a4067bdbde
) And then (difficult to communicate this via snippets of code, but...) I have some code which we use for batch resolving alerts: type incident struct {
id, summary string
}
[...]
incidents := make([]incident, 0)
[...]
inctoresolve := pagerduty.Incident{
APIObject: pagerduty.APIObject{
ID: incidents[i].id,
Type: "incident_reference",
},
Status: "resolved",
}
[...]
batchIncs = append(batchIncs, incstoresolve)
for b := range batchIncs {
if err := client.ManageIncidents(*email, batchIncs[b]); err != nil {
log.Println(err)
} else {
log.Println("Resolving incidents...")
}
} And this works fine. But if I use a recent version of this library:
then I hit the same inctoresolve := pagerduty.Incident{
APIObject: pagerduty.APIObject{
ID: incidents[i].id,
Type: "incident_reference",
},
Priority: pagerduty.Priority{
APIObject: pagerduty.APIObject{
ID: "blah",
Type: "priority_reference",
},
},
Status: "resolved", Then I get rid of all the priority warnings but end up getting a I thought that might have been because I don't actually have a Priority ID of So I think what happens is that this library now inadvertently sets a I could be wrong. Anyway... just leaving that in case it helps anyone else figure it out. Will continue digging. |
I don't understand why |
Ended up doing this to func (c *Client) put(path string, payload interface{}, headers *map[string]string) (*http.Response, error) {
if payload != nil {
data, err := json.Marshal(payload)
fmt.Println(string(data))
[...] So I could see what gets sent:
I'm really not the best with Go, but seems like it's something like this: https://stackoverflow.com/questions/33447334/golang-json-marshal-how-to-omit-empty-nested-struct |
For my use case, changing Priority *Priority `json:"priority,omitempty"` Works. But unsure if PRing just that is enough. Might do it though, at least for discussion. |
Due to the changes to the Incident struct the library now inadvertently sends an empty priority to the API (`"priority":{}`) and for ManageIncidents this results in a response of: Priority id cannot be empty To prevent sending an empty priority we can use a pointer to Priority. Seems like a super simple fix for this - and as such I'm worried I've missed something else. Full discussion of this in this issue: References: PagerDuty#135
PR ^ fwiw. |
Thanks for digging into this @atomicules ❤️ Using a pointer should fix this |
This affects also other field: sapcc@304f7ea |
Appears #164 addressed this. Closing Issue. Please reopen if this is still a problem. |
Managing an incident should not require the
priority
field according to the API spec. It's marked as optional.However, trying to manage an incident without this field returns:
Moreover, the incident priority feature is disabled in our Pagerduty.
Can you confirm that's a bug? Kindly asking for help here @mattstratton 🙏
The text was updated successfully, but these errors were encountered: