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

feat: add support for opsgenie #73

Closed
wants to merge 37 commits into from
Closed

Conversation

JonasPf
Copy link
Contributor

@JonasPf JonasPf commented Nov 10, 2020

No description provided.

@codecov-io
Copy link

codecov-io commented Nov 10, 2020

Codecov Report

Merging #73 (f0c460d) into main (ce75958) will decrease coverage by 3.61%.
The diff coverage is 73.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
- Coverage   65.93%   62.32%   -3.62%     
==========================================
  Files          56       65       +9     
  Lines        1371     1858     +487     
==========================================
+ Hits          904     1158     +254     
- Misses        386      576     +190     
- Partials       81      124      +43     
Impacted Files Coverage Δ
pkg/format/format.go 0.00% <0.00%> (ø)
pkg/format/format_query.go 0.00% <0.00%> (ø)
pkg/services/opsgenie/opsgenie.go 69.38% <69.38%> (ø)
pkg/services/opsgenie/opsgenie_entity.go 71.42% <71.42%> (ø)
pkg/format/formatter.go 56.71% <74.52%> (ø)
pkg/services/opsgenie/opsgenie_config.go 85.71% <85.71%> (ø)
pkg/router/servicemap.go 100.00% <100.00%> (ø)
... and 6 more

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 ce75958...f0c460d. Read the comment docs.

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

Looks good, but I have added some feedback.

pkg/services/opsgenie/opsgenie_json.go Outdated Show resolved Hide resolved
pkg/services/opsgenie/opsgenie_test.go Outdated Show resolved Hide resolved
pkg/services/opsgenie/opsgenie_config.go Outdated Show resolved Hide resolved
@JonasPf
Copy link
Contributor Author

JonasPf commented Nov 12, 2020

Thanks for the feedback. I won't have time within the next 2 weeks but I'll get back to it after that to fix those things.

@simskij simskij self-requested a review November 15, 2020 10:26
Alexei Tighineanu and others added 10 commits December 10, 2020 20:52
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
JSON is too generic. OpsGenie uses the term "payload" in their
documentation so I've used that instead.
Shoutrrr uses the term `service` by convention
@JonasPf
Copy link
Contributor Author

JonasPf commented Dec 10, 2020

Hi All,

I pushed changes that address the issues mentioned above. Apparently I also rebased wrong or something like that because I see a few commits that probably shouldn't be in this branch. What's your general policy here? I can fix this if you are ok with a force-push to this branch. Alternatively I could open a new PR.

@piksel
Copy link
Member

piksel commented Dec 12, 2020

I would squash this anyway, so it should be fine!

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

A lot of great work has been put into this, but I'm not so sure about the raw JSON URLs.
Left some comments.

pkg/services/opsgenie/opsgenie_config.go Show resolved Hide resolved
docs/services/opsgenie.md Outdated Show resolved Hide resolved
pkg/services/opsgenie/opsgenie_json.go Show resolved Hide resolved
@simskij
Copy link
Member

simskij commented Dec 20, 2020

Alright, closing this for the time being then. We try to aim at only implementing services that people actually will use. If anyone actually wants/needs Opsgenie support, please open another ticket and let us know.

Thanks for your contributions!

@simskij simskij closed this Dec 20, 2020
@JonasPf
Copy link
Contributor Author

JonasPf commented Dec 24, 2020

Alright, closing this for the time being then. We try to aim at only implementing services that people actually will use. If anyone actually wants/needs Opsgenie support, please open another ticket and let us know.

Thanks for your contributions!

Well, I'm using it, that's why I implemented the integration in the first place ;-)

I'm happy to work on the remaining issues if you plan on merging it, just let me know. Until then, it works well enough for me as it is.

@simskij
Copy link
Member

simskij commented Dec 24, 2020

I must have mixed issues together! I closed this because I was under the impression that you abandoned the idea of using shoutrrr for your project.

Reopening.

@simskij simskij reopened this Dec 24, 2020
@JonasPf
Copy link
Contributor Author

JonasPf commented Dec 28, 2020

I must have mixed issues together! I closed this because I was under the impression that you abandoned the idea of using shoutrrr for your project.

Reopening.

No worries, I know I'm sometimes a bit slow to respond. Especially around Christmas :-)

@JonasPf
Copy link
Contributor Author

JonasPf commented Jan 6, 2021

I just pushed some changes. The service now works well with the generate and verify commands, has a couple more tests and I merged all the changes from master.

Next I'll be working on integrating PropKeyResolver and replacing the raw json fields with more human readable format as suggested by @piksel.

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

Great work overall! The suggested changes are optional, but will increase the test coverage a bit if nothing else :)
Also; I merged the send ArraySlice fix, so now you can correctly test using the CLI (if you rebase/merge main)

@JonasPf
Copy link
Contributor Author

JonasPf commented Feb 3, 2021

I merged the changes in master. Problem is that formatQuery.BuildQuery() got changed to use Values.Encode(). This breaks a test because it encode a comma. Same problem as mentioned above. I left the failing code in there for you to see it.


generate doesn't work with the Responders and VisibleTo fields. It keeps saying Invalid format for field Responders: field format is not supported which makes sense because formatter.go doesn't know how to deserialize entities.
I don't know how to solve that yet. Need to think about it. Any ideas?

Btw. I found two unrelated issues:

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

Nice work!

I will look into creating an interface for de-/serializing structs that the entities can implement.

If you move out the looping from the entity methods to a pair of:

(e *Entity) SetFromProp(propValue string) error {  }

and

(e *Entity) GetPropValue() (string, error) {  }

I will try to get it implemented ASAP

pkg/format/format_query.go Show resolved Hide resolved
pkg/services/opsgenie/opsgenie_config.go Show resolved Hide resolved
pkg/services/opsgenie/opsgenie_config.go Outdated Show resolved Hide resolved

When("generating a config from a url with query parameters", func() {
It("should populate the config fields with the query parameter values", func() {
queryParams := `alias=Life+is+too+short+for+no+alias&description=Every+alert+needs+a+description&actions=An+action&tags=tag1,tag2&details=key:value,key2:value2&entity=An+example+entity&source=The+source&priority=P1&user=Dracula&note=Here+is+a+note&responders=user:Test,team:NOC&visibleTo=user:A+User`
Copy link
Member

Choose a reason for hiding this comment

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

This would make the test work with the encoded query field values:

Suggested change
queryParams := `alias=Life+is+too+short+for+no+alias&description=Every+alert+needs+a+description&actions=An+action&tags=tag1,tag2&details=key:value,key2:value2&entity=An+example+entity&source=The+source&priority=P1&user=Dracula&note=Here+is+a+note&responders=user:Test,team:NOC&visibleTo=user:A+User`
queryParams := `alias=Life+is+too+short+for+no+alias&description=Every+alert+needs+a+description&actions=An+action&tags=tag1%2Ctag2&details=key%3Avalue%2Ckey2%3Avalue2&entity=An+example+entity&source=The+source&priority=P1&user=Dracula&note=Here+is+a+note&responders=user%3ATest%2Cteam%3ANOC&visibleTo=user%3AA+User`

The users won't have to escape all the characters, it will handle both, but the generated ones are at least ensured to always be valid URL query params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok fixed. I misunderstood and thought you wanted to preserve the commas, etc. when generating urls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you move out the looping from the entity methods to a pair of

Done, is that what you had in mind?

Copy link
Member

@piksel piksel Feb 4, 2021

Choose a reason for hiding this comment

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

If you move out the looping from the entity methods to a pair of:

That was one mess of a sentence. But yeah, exactly.

@JonasPf
Copy link
Contributor Author

JonasPf commented Feb 11, 2021

Hey, I'm still aware of this and want to finally test it, just haven't had the time yet. It's not forgotten!

@JonasPf
Copy link
Contributor Author

JonasPf commented Feb 16, 2021

Ok , so I merged #137 and tested everything again. generate and verify now work. One tiny thing I noticed: formatter lowercases all keys. What this means is that visibleTo becomes visibleto after running generate. This only seems to affect how the user sees the URL. It still gets send to OpsGenie as visibleTo.

I also manually tested sending a bunch of differently configured alerts to OpsGenie. That worked as expected.

Functionality wise I this is ready to be merged from my perspective.

@piksel
Copy link
Member

piksel commented Feb 17, 2021

Yeah, exactly. This is kind of the same deal as with the commas etc. The generated URLs have the query values in alphabetical order, uses lowercase keys and are escaped. This is mainly for testing purposes, if the format is uniform and known beforehand, black box tests for the serialization is easier to write and update when something changes.

I'll fix the CA issues and merge #137, hopefully this won't have any conflicts after that, in which case I'll merge this as well. Great job!

piksel added a commit that referenced this pull request Feb 21, 2021
@piksel
Copy link
Member

piksel commented Feb 21, 2021

Solved merge conflicts and merged as #140!

Great job! 🎉

@piksel piksel closed this Feb 21, 2021
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.

5 participants