-
Notifications
You must be signed in to change notification settings - Fork 83
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
Feature: Add silence datasource #403
base: main
Are you sure you want to change the base?
Feature: Add silence datasource #403
Conversation
Hey @dannyswebb thank you for your PR :) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
===========================================
+ Coverage 45.46% 70.64% +25.17%
===========================================
Files 21 11 -10
Lines 2228 1468 -760
Branches 437 326 -111
===========================================
+ Hits 1013 1037 +24
+ Misses 1174 257 -917
- Partials 41 174 +133
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
b9fa5e5
to
539d502
Compare
Please use ruff and black for code linting/formatting. |
89f2e39
to
1dcea66
Compare
fragment added, working through the failed workflows now. Sorry, been a couple years since I've touched mock tests and I'm a bit rusty. |
ruff and black linting done, working through the unit findings now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few suggestions. If grafana is defined as the default alertmanager in the documentation area, this must also be set in the code. I also made a few renaming changes. My code suggestions are not tested.
@@ -69,6 +69,12 @@ | |||
type: list | |||
elements: dict | |||
required: true | |||
alertmanager_datasource: | |||
description: | |||
- Which alertmanager datasource to target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Which alertmanager datasource to target | |
- Which alertmanager datasource to target. |
@@ -352,6 +387,7 @@ def setup_module_object(): | |||
org_name=dict(type="str"), | |||
skip_version_check=dict(type="bool", default=False), | |||
starts_at=dict(type="str", required=True), | |||
alertmanager_datasource=dict(type=str), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alertmanager_datasource=dict(type=str), | |
alertmanager_datasource=dict(type=str, default="grafana"), |
if module.params.get("alertmanager_datasource", None): | ||
self.alertmanager_path = self.datasource_by_name( | ||
module.params["alertmanager_datasource"] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if module.params.get("alertmanager_datasource", None): | |
self.alertmanager_path = self.datasource_by_name( | |
module.params["alertmanager_datasource"] | |
) | |
if module.params.get("alertmanager_datasource") != "grafana": | |
self.alertmanager_id = self.datasource_by_name( | |
module.params["alertmanager_datasource"] | |
) |
# Default here because you can't look up "grafana" DS via API | ||
self.alertmanager_path = "grafana" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Default here because you can't look up "grafana" DS via API | |
self.alertmanager_path = "grafana" | |
self.alertmanager_id = module.params["alertmanager_datasource"] |
@@ -280,7 +319,7 @@ def get_version(self): | |||
raise GrafanaError("Failed to retrieve version from '%s'" % url) | |||
|
|||
def create_silence(self, comment, created_by, starts_at, ends_at, matchers): | |||
url = "/api/alertmanager/grafana/api/v2/silences" | |||
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" | |
url = f"/api/alertmanager/{self.alertmanager_id}/api/v2/silences" |
@@ -297,7 +336,7 @@ def create_silence(self, comment, created_by, starts_at, ends_at, matchers): | |||
return response | |||
|
|||
def get_silence(self, comment, created_by, starts_at, ends_at, matchers): | |||
url = "/api/alertmanager/grafana/api/v2/silences" | |||
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" | |
url = f"/api/alertmanager/{self.alertmanager_id}/api/v2/silences" |
url = "/api/alertmanager/grafana/api/v2/silence/{SilenceId}".format( | ||
SilenceId=silence_id | ||
) | ||
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silence/{silence_id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silence/{silence_id}" | |
url = f"/api/alertmanager/{self.alertmanager_id}/api/v2/silence/{silence_id}" |
response = self._send_request(url, headers=self.headers, method="GET") | ||
return response | ||
|
||
def get_silences(self): | ||
url = "/api/alertmanager/grafana/api/v2/silences" | ||
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silences" | |
url = f"/api/alertmanager/{self.alertmanager_id}/api/v2/silences" |
url = "/api/alertmanager/grafana/api/v2/silence/{SilenceId}".format( | ||
SilenceId=silence_id | ||
) | ||
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silence/{silence_id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url = f"/api/alertmanager/{self.alertmanager_path}/api/v2/silence/{silence_id}" | |
url = f"/api/alertmanager/{self.alertmanager_id}/api/v2/silence/{silence_id}" |
SUMMARY
Grafana has the ability to support multiple alertmanager datasources. Add the ability for grafana_silence to use user defined datasources (or default to grafana if none supplied).
ISSUE TYPE
COMPONENT NAME
grafana_silence
ADDITIONAL INFORMATION
n/a