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
fix style errors
  • Loading branch information
yugangw-msft committed Mar 8, 2022
commit 8ea48c2841f7cf3a6b40018d02359f239582dc00
1 change: 1 addition & 0 deletions src/ags/azext_ags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, cli_ctx=None):
ags_custom = CliCommandType(
operations_tmpl='azext_ags.custom#{}',
client_factory=cf_ags)
# pylint: disable=super-with-arguments
super(AgsCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=ags_custom)

Expand Down
6 changes: 3 additions & 3 deletions src/ags/azext_ags/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# --------------------------------------------------------------------------------------------

def cf_ags(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
# pylint: disable=unused-argument
# from azure.cli.core.commands.client_factory import get_mgmt_service_client
# TODO: Replace CONTOSO with the appropriate label and uncomment
# from azure.mgmt.CONTOSO import CONTOSOManagementClient
# return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient)
return None
pass
41 changes: 35 additions & 6 deletions src/ags/azext_ags/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
type: command
short-summary: Create a data source.
examples:
- name: create a data source using Managed Service Identity
- name: create a data source using Managed Service Identity
text: |
az grafana data-source create --definition '{
"access": "proxy",
Expand All @@ -68,7 +68,7 @@
"type": "geneva-datasource",
"withCredentials": false
}'
- name: create a data source using Service Principal
- name: create a data source using Service Principal
text: |
az grafana data-source create --definition '{
"access": "proxy",
Expand All @@ -87,14 +87,32 @@
"name": "Geneva Datasource using Service principal",
"type": "geneva-datasource"
}'
- name: create a data source of Azure SQL
text: |
az grafana data-source create --definition '{
"access": "proxy",
"database": "mySqlDB",
"jsonData": {
"authenticationType": "SQL Server Authentication",
"encrypt": "false"
},
"secureJsonFields": {
"password": true
},
"name": "Microsoft SQL Server",
"password": "verySecretPasssword!",
"type": "mssql",
"url": "mySqlServer.database.windows.net",
"user": "testuser1"
}'
"""


helps['grafana data-source update'] = """
type: command
short-summary: Update a data source.
examples:
- name: update a data source's credentials (make sure either set "version" to the latest version to bump to a new version, or omit it to overwrite the existing version)
- name: update a data source's credentials (make sure either set "version" to the latest version, or omit it to overwrite the existing version)
text: |
az grafana data-source create --data-source "Geneva Datasource" --definition '{
"access": "proxy",
Expand Down Expand Up @@ -146,7 +164,19 @@
examples:
- name: Create a dashboard with definition in a json file. For quick start, clone from the output of "az grafana dashboard show", remove "id" and "uid", and apply changes.
text: |
az grafana dashboard create -g MyResourceGroup -n MyGrafana --dashboard-definition @c:\\temp\\dashboard.json
az grafana dashboard create -g MyResourceGroup -n MyGrafana --definition '{
"dashboard": {
"annotations": {
...
},
"panels": {
...
}
"title": "TestDashboard"
},
"folderId": <folder id or skip to default to "General">,
"message": "Create a new test dashboard"
}'
"""

helps['grafana dashboard update'] = """
Expand All @@ -156,7 +186,7 @@
- name: Update a dashboard with definition in a json file. For quick start, get existing configuration from "az grafana dashboard show", and apply changes.
"version" field need to be updated, and "overwrite" field should be true.
text: |
az grafana dashboard update -g MyResourceGroup -n MyGrafana --dashboard-definition @c:\\temp\\dashboard.json
az grafana dashboard update -g MyResourceGroup -n MyGrafana --definition @c:\\temp\\dashboard.json
"""

helps['grafana dashboard list'] = """
Expand Down Expand Up @@ -238,4 +268,3 @@
type: command
short-summary: show detail of a user.
"""

11 changes: 3 additions & 8 deletions src/ags/azext_ags/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
def load_arguments(self, _):

from knack.arguments import CLIArgumentType
from azure.cli.core.commands.parameters import tags_type, get_three_state_flag, resource_group_name_type
from azure.cli.core.commands.parameters import tags_type, get_three_state_flag
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from ._validators import process_missing_resource_group_parameter, process_leading_hyphen
from ._validators import process_missing_resource_group_parameter

grafana_name_type = CLIArgumentType(options_list="--grafana-name",
help="Name of the Azure Managed Dashboard for Grafana.",
Expand All @@ -19,12 +19,6 @@ def load_arguments(self, _):
c.argument("tags", tags_type)
c.argument("location", validator=get_default_location_from_resource_group)
c.argument("grafana_name", grafana_name_type, options_list=["--name", "-n"], validator=process_missing_resource_group_parameter)
c.argument("uid", options_list=["--unique-identifier", "--uid"],
help=("The unique identifier (uid) of a dashboard can be used for uniquely identifying a dashboard or data source "
"between multiple Grafana installs. It’s automatically generated if not provided on creating. "
"The uid allows having consistent URLs for accessing dashboards or data sources when syncing "
"between multiple Grafana installs. For uid with leading hyphen, please prepend whitespace to workaround https://bugs.python.org/issue9334"),
validator=process_leading_hyphen)
c.argument("id", help=("The identifier (id) of a dashboard/data source is an auto-incrementing "
"numeric value and is only unique per Grafana install."))

Expand All @@ -36,6 +30,7 @@ def load_arguments(self, _):
c.argument('yes', options_list=['--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')

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")

with self.argument_context("grafana dashboard show") as c:
Expand Down
6 changes: 0 additions & 6 deletions src/ags/azext_ags/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ def process_missing_resource_group_parameter(cmd, namespace):
raise CLIError(("Not able to find the Grafana workspace: '{}'. Please "
"correct the name, or provide resource group name, or set CLI "
"subscription the workspace belongs to").format(namespace.grafana_name))


def process_leading_hyphen(cmd, namespace): # TODO: find a common solution
if namespace.uid:
namespace.uid=namespace.uid.lstrip()

12 changes: 6 additions & 6 deletions src/ags/azext_ags/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def query_data_source(cmd, grafana_name, data_source, time_from=None, time_to=No
else:
time_from = right_now - datetime.timedelta(hours=1)
time_from_epoch = time.mktime(time_from.timetuple()) * 1000

if time_to:
time_to = parser.parse(time_to)
else:
Expand Down Expand Up @@ -257,7 +257,7 @@ def _send_request(cmd, resource_group_name, grafana_name, http_method, path, bod
profile = Profile(cli_ctx=cmd.cli_ctx)
# this might be a cross tenant scenario, so pass subscription to get_raw_token
subscription = get_subscription_id(cmd.cli_ctx)
ags_first_party_app = ("7f525cdc-1f08-4afa-af7c-84709d42f5d3"
ags_first_party_app = ("7f525cdc-1f08-4afa-af7c-84709d42f5d3"
if "-ppe." in cmd.cli_ctx.cloud.endpoints.active_directory
else "ce34e7e5-485f-4d76-964f-b3d2b16d1e4f")
creds, _, _ = profile.get_raw_token(subscription=subscription,
Expand All @@ -270,10 +270,10 @@ def _send_request(cmd, resource_group_name, grafana_name, http_method, path, bod

# TODO: handle re-try on 429
response = requests.request(http_method,
url=endpoint + path,
headers=headers,
json=body,
verify=(not should_disable_connection_verify()))
url=endpoint + path,
headers=headers,
json=body,
verify=(not should_disable_connection_verify()))
if response.status_code >= 400:
if raise_for_error_status:
logger.warning(str(response.content))
Expand Down