-
Notifications
You must be signed in to change notification settings - Fork 8
addpanel method in grafana wrapper #91
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
Open
isabelfaulds
wants to merge
1
commit into
SCE-Development:master
Choose a base branch
from
isabelfaulds:grafana-wrapper-addpanel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,10 +48,11 @@ class ExpressionAndLegendPair: | |
| class SceGrafanalibWrapper: | ||
| MAX_WIDTH: Final[int] = 24 | ||
|
|
||
| def __init__(self, title, panel_width=12, panel_height=8): | ||
| def __init__(self, title, description="", panel_width=12, panel_height=8): | ||
| self.rows = [] | ||
| self.panels = [] | ||
| self.title = title | ||
| self.description = description | ||
| self.current_x = 0 | ||
| self.current_y = 0 | ||
| self.panel_width = min(panel_width, self.MAX_WIDTH) | ||
|
|
@@ -79,8 +80,7 @@ def DefineTemplating( | |
| ) | ||
| ) | ||
|
|
||
| def AddPanel( | ||
| self, | ||
| def CreatePanel(self, | ||
| title, | ||
| queries: list[ExpressionAndLegendPair], | ||
| unit="", | ||
|
|
@@ -90,8 +90,8 @@ def AddPanel( | |
| fillOpacity=None, | ||
| showPoints=None, | ||
| stacking=None, | ||
| extraJson=None, | ||
| ): | ||
| extraJson=None): | ||
|
|
||
| targets = [] | ||
| iterator = RefIdGenerator() | ||
| for query in queries: | ||
|
|
@@ -160,18 +160,109 @@ def AddPanel( | |
| panel.unit = unit | ||
| elif hasattr(panel, "format"): | ||
| panel.format = unit | ||
| return panel | ||
|
|
||
| def AddPanel( | ||
| self, | ||
| title, | ||
| queries: list[ExpressionAndLegendPair], | ||
| unit="", | ||
| dydt=False, | ||
| panel_type_enum=PanelType.TIME_SERIES, | ||
| lineWidth=None, | ||
| fillOpacity=None, | ||
| showPoints=None, | ||
| stacking=None, | ||
| extraJson=None, | ||
| ): | ||
| ''' | ||
| Add panel to latest defined row | ||
|
|
||
| :param title: panel title | ||
| :param queries: Description | ||
| :type queries: list[ExpressionAndLegendPair] | ||
| :param unit: Y-axis unit/format 'percent' , 'bytes/sec', 'short' | ||
| :param dydt: if true aluto-generates two targets per query | ||
| :param panel_type_enum: panel visualization PanelType.TIME_SERIES , PanelType.GAUGE , PanelType.BARGAUGE , PanelType.STAT | ||
| :param lineWidth: line thickness 1-10 | ||
| :param fillOpacity: area fill transparency 0.0-1.0 | ||
| :param showPoints: point visibility "never" , "auto" , "always" | ||
| :param stacking: stacking mode "off" , "normal" , "100%" | ||
| :param extraJson: dict of raw JSON for panel constructor | ||
| ''' | ||
|
|
||
| panel = self.CreatePanel( | ||
| title, | ||
| queries, | ||
| unit, | ||
| dydt, | ||
| panel_type_enum, | ||
| lineWidth, | ||
| fillOpacity, | ||
| showPoints, | ||
| stacking, | ||
| extraJson) | ||
|
|
||
| # add the new panel as a new Row | ||
| row = Row(title=title, panels=[panel]) | ||
| self.rows.append(row) | ||
| self.current_y += self.panel_height | ||
|
|
||
| def AddPanelToRow( | ||
| self, | ||
| title, | ||
| queries: list[ExpressionAndLegendPair], | ||
| unit="", | ||
| dydt=False, | ||
| panel_type_enum=PanelType.TIME_SERIES, | ||
| lineWidth=None, | ||
| fillOpacity=None, | ||
| showPoints=None, | ||
| stacking=None, | ||
| extraJson=None, | ||
| ): | ||
| ''' | ||
| Add panel to latest defined row | ||
|
|
||
| :param title: panel title | ||
| :param queries: Description | ||
| :type queries: list[ExpressionAndLegendPair] | ||
| :param unit: Y-axis unit/format 'percent' , 'bytes/sec', 'short' | ||
| :param dydt: if true aluto-generates two targets per query | ||
| :param panel_type_enum: panel visualization PanelType.TIME_SERIES , PanelType.GAUGE , PanelType.BARGAUGE , PanelType.STAT | ||
| :param lineWidth: line thickness 1-10 | ||
| :param fillOpacity: area fill transparency 0.0-1.0 | ||
| :param showPoints: point visibility "never" , "auto" , "always" | ||
| :param stacking: stacking mode "off" , "normal" , "100%" | ||
| :param extraJson: dict of raw JSON for panel constructor | ||
| ''' | ||
| if not self.rows: | ||
| raise ValueError("No rows defined for this dashboard") | ||
|
|
||
| panel = self.CreatePanel( | ||
| title, | ||
| queries, | ||
| unit, | ||
| dydt, | ||
| panel_type_enum, | ||
| lineWidth, | ||
| fillOpacity, | ||
| showPoints, | ||
| stacking, | ||
| extraJson) | ||
|
|
||
| row_or_panel = self.rows[-1].panels if self.rows else self.panels | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assuming this new update doesn't allow for standalone panels w/o rows, we can probably simplify this to just self.rows[-1].panels.append(panel) |
||
| row_or_panel.append(panel) | ||
| self.current_x += self.panel_width | ||
| if self.current_x >= self.MAX_WIDTH: | ||
| self.current_y += self.panel_height | ||
| self.current_x = 0 | ||
|
|
||
| def Render(self): | ||
| valid_rows = [r for r in self.rows if r.panels] | ||
| return Dashboard( | ||
| title=self.title, | ||
| rows=self.rows, | ||
| panels=self.panels, | ||
| rows=valid_rows, | ||
| timezone="browser", | ||
| templating=Templating(list=self.templates), | ||
| ).auto_panel_ids() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe change this to "Add panel under a new defined row" for more clarity