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

Refine API wrapper for "Plugins" #114

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

* Refine API wrapper for "Plugins"


## 3.8.0 (2023-09-15)

Expand Down
44 changes: 25 additions & 19 deletions grafana_client/elements/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
self.client = client
self.logger = logging.getLogger(__name__)

def health_check_plugin(self, pluginId):
"""
:return:
"""
path = "/plugins/%s/health" % pluginId
r = self.client.GET(path)
return r

def get_installed_plugins(self):
"""
:return:
Expand All @@ -25,7 +17,7 @@
r = self.client.GET(path)
return r

def install_plugin(self, pluginId, version):
def install_plugin(self, pluginId, version, errors="raise"):
"""
: return:
"""
Expand All @@ -34,10 +26,15 @@
r = self.client.POST(path, json={"version": version})
return r
except Exception as ex:
self.logger.info("Skipped installing %s and err = %s", pluginId, ex)
if errors == "raise":
Copy link
Contributor

Choose a reason for hiding this comment

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

Great one, thanks for helping raise the quality.

raise
elif errors == "ignore":
self.logger.info(f"Skipped installing plugin {pluginId}: {ex}")

Check warning on line 32 in grafana_client/elements/plugin.py

View check run for this annotation

Codecov / codecov/patch

grafana_client/elements/plugin.py#L29-L32

Added lines #L29 - L32 were not covered by tests
else:
raise ValueError(f"error={errors} is invalid")

Check warning on line 34 in grafana_client/elements/plugin.py

View check run for this annotation

Codecov / codecov/patch

grafana_client/elements/plugin.py#L34

Added line #L34 was not covered by tests
return None

def uninstall_plugin(self, pluginId):
def uninstall_plugin(self, pluginId, errors="raise"):
"""
: return:
"""
Expand All @@ -46,17 +43,26 @@
r = self.client.POST(path)
return r
except Exception as ex:
self.logger.info("Skipped uninstalling %s and error = %s", pluginId, ex)
if errors == "raise":
raise
elif errors == "ignore":
self.logger.info(f"Skipped uninstalling plugin {pluginId}: {ex}")

Check warning on line 49 in grafana_client/elements/plugin.py

View check run for this annotation

Codecov / codecov/patch

grafana_client/elements/plugin.py#L46-L49

Added lines #L46 - L49 were not covered by tests
else:
raise ValueError(f"error={errors} is invalid")

Check warning on line 51 in grafana_client/elements/plugin.py

View check run for this annotation

Codecov / codecov/patch

grafana_client/elements/plugin.py#L51

Added line #L51 was not covered by tests
return None

def health_check_plugin(self, pluginId):
"""
:return:
"""
path = "/plugins/%s/health" % pluginId
r = self.client.GET(path)
return r

def get_plugin_metrics(self, pluginId):
"""
: return:
"""
try:
path = "/plugins/%s/metrics" % pluginId
r = self.client.GET(path)
return r
except Exception as ex:
self.logger.info("Got error in fetching metrics for plugin %s and error = %s", pluginId, ex)
return None
path = "/plugins/%s/metrics" % pluginId
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for refactoring. I should have put more focus here since that was my local logging to help identify if plugin does not have metrics endpoint.

r = self.client.GET(path)
return r
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = [
"pip>=20.0",
"setuptools>=40.0",
"setuptools_scm[toml]>=4.0",
"setuptools_scm[toml]>=4.0,<8",
"wheel"
]
build-backend = "setuptools.build_meta"
Expand Down
Loading