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

Onboard command extension for Azure Managed Grafana service #4495

Merged
merged 36 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0d142ab
POC: update with command list to implement
yugangw-msft Jan 7, 2022
86a327c
consolidate control plane and dashboard commands
yugangw-msft Jan 8, 2022
f6f0398
half done: make resource group and location optional
yugangw-msft Jan 9, 2022
9f1d64a
more commands and code style fixes
yugangw-msft Jan 15, 2022
118d7c1
add a validator to workspace https://bugs.python.org/issue9334
yugangw-msft Jan 16, 2022
efb83c6
catch up a few TODOs
yugangw-msft Jan 16, 2022
a0e4c6c
Consolidate data source CRUD commands with bug fixes and samples
yugangw-msft Jan 17, 2022
00776b1
add help
yugangw-msft Jan 17, 2022
bff5d4e
bug fixes on data source commands
yugangw-msft Jan 19, 2022
8ea48c2
fix style errors
yugangw-msft Jan 22, 2022
055a128
fix bugs in data-source commands
yugangw-msft Jan 23, 2022
542bc1a
clean up command help
yugangw-msft Jan 23, 2022
fc77db4
upload whl file for tempoaray measures, before we publish it officially
yugangw-msft Jan 24, 2022
5b896a9
update readme and bug fixes
yugangw-msft Jan 24, 2022
ef61108
update get_start doc
yugangw-msft Jan 27, 2022
3cfa442
Update get_start,md
yugangw-msft Jan 25, 2022
22ecfcd
fix typos in get_start.md
yugangw-msft Jan 27, 2022
fa4679e
add vendor SDK
yugangw-msft Mar 5, 2022
3ccce00
new extension
yugangw-msft Mar 5, 2022
7e605bb
new extension built from azdev
yugangw-msft Mar 5, 2022
a439200
rename from ags to amg
yugangw-msft Mar 6, 2022
c2eda5d
add tag support
yugangw-msft Mar 6, 2022
4c97ebd
Update readme.rst
yugangw-msft Mar 6, 2022
4586d2d
undo non related changes
yugangw-msft Mar 6, 2022
f168b98
rename readme to markdown
yugangw-msft Mar 6, 2022
73a4e15
address lint error
yugangw-msft Mar 8, 2022
8b58a18
address linter error
yugangw-msft Mar 8, 2022
db45158
more fix towards command lint error
yugangw-msft Mar 8, 2022
e4d5a62
register the command module in a few common file
yugangw-msft Mar 8, 2022
5c501d8
add import
yugangw-msft Mar 11, 2022
cf46859
support gallery import
yugangw-msft Mar 12, 2022
4242517
use deep copy
yugangw-msft Mar 12, 2022
1a30dc7
address review feedback
yugangw-msft Mar 13, 2022
aa7b87e
set the minimum cli core version
yugangw-msft Mar 18, 2022
c5f3832
fix a bug in 'az grafana user show'
yugangw-msft Mar 19, 2022
8f1c5a1
Remove the 'id' on creating dashboard to prevent 'Not Found' error
yugangw-msft Mar 22, 2022
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
Prev Previous commit
Next Next commit
support gallery import
  • Loading branch information
yugangw-msft committed Mar 12, 2022
commit cf46859c78898e6bafd95ca3976988e64789d334
2 changes: 1 addition & 1 deletion src/amg/azext_amg/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_arguments(self, _):

with self.argument_context("grafana dashboard") as c:
c.argument("uid", options_list=["--dashboard"], help="dashboard uid")
c.argument("definition", help="The complete dashboard model in json string, or a path to a file with such json string")
c.argument("definition", help="The complete dashboard model in json string, a file path/url or Grafana gallery id")
c.argument("title", help="title of a dashboard")
c.argument('overwrite', arg_type=get_three_state_flag(), help='Overwrite a dashboard with same uid')

Expand Down
39 changes: 35 additions & 4 deletions src/amg/azext_amg/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def list_dashboards(cmd, grafana_name, resource_group_name=None):


def create_dashboard(cmd, grafana_name, definition, title=None, folder=None, resource_group_name=None, overwrite=None):
definition = _try_load_file_content(definition)
data = json.loads(definition)
data = _try_load_dashboard_definition(cmd, resource_group_name, grafana_name, definition)
if "dashboard" in data:
payload = data
else:
Expand Down Expand Up @@ -169,8 +168,7 @@ def update_dashboard(cmd, grafana_name, definition, folder=None, resource_group_


def import_dashboard(cmd, grafana_name, definition, folder=None, resource_group_name=None, overwrite=None):
definition = _try_load_file_content(definition)
data = json.loads(definition)
data = _try_load_dashboard_definition(cmd, resource_group_name, grafana_name, definition)
if "dashboard" in data:
payload = data
else:
Expand All @@ -184,11 +182,44 @@ def import_dashboard(cmd, grafana_name, definition, folder=None, resource_group_

payload["overwrite"] = overwrite or False

payload["inputs"] = []

data_sources = list_data_sources(cmd, grafana_name, resource_group_name)
for parameter in payload["dashboard"].get('__inputs', []):
if parameter.get("type") == "datasource":
match = next((d for d in data_sources if d["type"] == parameter["pluginId"]), None)
if match:
clone = parameter.copy()
clone["value"] = match["uid"]
payload["inputs"].append(clone)
else:
logger.warning("No data source was found matching required input of %s", parameter['pluginId'])

response = _send_request(cmd, resource_group_name, grafana_name, "post", "/api/dashboards/import",
payload)
return json.loads(response.content)


def _try_load_dashboard_definition(cmd, resource_group_name, grafana_name, definition):
try: # see whether it is a gallery id
_ = int(definition)
response = _send_request(cmd, resource_group_name, grafana_name, "get", "/api/gnet/dashboards/" + definition)
return json.loads(response.content)["json"]
except ValueError:
pass

if definition.lower().startswith("https://"):
response = requests.get(definition, verify=(not should_disable_connection_verify()))
if response.status_code == 200:
definition = json.loads(response.content.decode())
else:
raise CLIError(f"Failed to dashboard definition from '{definition}'. Error: '{response}'.")
else:
definition = json.loads(_try_load_file_content(definition))

return definition


def delete_dashboard(cmd, grafana_name, uid, resource_group_name=None):
_send_request(cmd, resource_group_name, grafana_name, "delete", "/api/dashboards/uid/" + uid)

Expand Down
Binary file modified src/amg/dist/amg-0.1.0-py3-none-any.whl
Binary file not shown.