From 676b80ebda1edc424227e50a0d32c029a01cafb7 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 22 Jun 2021 18:22:20 -0700 Subject: [PATCH] Regenerate monitor code (#19375) * Regenrate code * statistics * Update sdk/monitor/azure-monitor-query/tests/test_logs_client.py * ci fix * Apply suggestions from code review * lint * Update sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py * ci --- .../azure/monitor/query/__init__.py | 2 - .../query/_generated/models/__init__.py | 14 +- .../query/_generated/models/_models.py | 179 ++++++--------- .../query/_generated/models/_models_py3.py | 206 +++++++----------- .../models/_monitor_query_client_enums.py | 12 + .../azure/monitor/query/_log_query_client.py | 4 +- .../azure/monitor/query/_models.py | 80 +++---- .../samples/sample_batch_query.py | 9 +- .../swagger/README.PYTHON.md | 42 +++- .../tests/async/test_logs_client_async.py | 2 + .../tests/test_logs_client.py | 44 +++- 11 files changed, 290 insertions(+), 304 deletions(-) diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py index 5d3104f2d801..3339edcdbfb1 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py @@ -15,7 +15,6 @@ LogsBatchResultError, LogsQueryRequest, LogsBatchResults, - LogsErrorDetails, MetricNamespace, MetricDefinition, MetricsMetadataValue, @@ -35,7 +34,6 @@ "LogsQueryResultColumn", "LogsQueryResultTable", "LogsQueryRequest", - "LogsErrorDetails", "MetricsQueryClient", "MetricNamespace", "MetricDefinition", diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/__init__.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/__init__.py index 39e7db918318..4f1b1146bd3b 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/__init__.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/__init__.py @@ -9,17 +9,15 @@ try: from ._models_py3 import BatchRequest from ._models_py3 import BatchResponse - from ._models_py3 import BatchResponseError - from ._models_py3 import BatchResponseErrorInnerError from ._models_py3 import Column from ._models_py3 import ErrorDetail - from ._models_py3 import ErrorDetails from ._models_py3 import ErrorInfo from ._models_py3 import ErrorResponse from ._models_py3 import ErrorResponseAutoGenerated from ._models_py3 import LocalizableString from ._models_py3 import LogQueryRequest from ._models_py3 import LogQueryResponse + from ._models_py3 import LogQueryResult from ._models_py3 import MetadataApplication from ._models_py3 import MetadataApplicationRelated from ._models_py3 import MetadataCategory @@ -59,17 +57,15 @@ except (SyntaxError, ImportError): from ._models import BatchRequest # type: ignore from ._models import BatchResponse # type: ignore - from ._models import BatchResponseError # type: ignore - from ._models import BatchResponseErrorInnerError # type: ignore from ._models import Column # type: ignore from ._models import ErrorDetail # type: ignore - from ._models import ErrorDetails # type: ignore from ._models import ErrorInfo # type: ignore from ._models import ErrorResponse # type: ignore from ._models import ErrorResponseAutoGenerated # type: ignore from ._models import LocalizableString # type: ignore from ._models import LogQueryRequest # type: ignore from ._models import LogQueryResponse # type: ignore + from ._models import LogQueryResult # type: ignore from ._models import MetadataApplication # type: ignore from ._models import MetadataApplicationRelated # type: ignore from ._models import MetadataCategory # type: ignore @@ -109,6 +105,7 @@ from ._monitor_query_client_enums import ( AggregationType, + ColumnDataType, MetadataColumnDataType, ResultType, Unit, @@ -117,17 +114,15 @@ __all__ = [ 'BatchRequest', 'BatchResponse', - 'BatchResponseError', - 'BatchResponseErrorInnerError', 'Column', 'ErrorDetail', - 'ErrorDetails', 'ErrorInfo', 'ErrorResponse', 'ErrorResponseAutoGenerated', 'LocalizableString', 'LogQueryRequest', 'LogQueryResponse', + 'LogQueryResult', 'MetadataApplication', 'MetadataApplicationRelated', 'MetadataCategory', @@ -165,6 +160,7 @@ 'Table', 'TimeSeriesElement', 'AggregationType', + 'ColumnDataType', 'MetadataColumnDataType', 'ResultType', 'Unit', diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models.py index fa6f78ce7625..30613f0fc7b2 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models.py @@ -34,13 +34,10 @@ class BatchResponse(msrest.serialization.Model): :param responses: An array of responses corresponding to each individual request in a batch. :type responses: list[~monitor_query_client.models.LogQueryResponse] - :param error: Error response for a batch request. - :type error: ~monitor_query_client.models.BatchResponseError """ _attribute_map = { 'responses': {'key': 'responses', 'type': '[LogQueryResponse]'}, - 'error': {'key': 'error', 'type': 'BatchResponseError'}, } def __init__( @@ -49,72 +46,25 @@ def __init__( ): super(BatchResponse, self).__init__(**kwargs) self.responses = kwargs.get('responses', None) - self.error = kwargs.get('error', None) - - -class BatchResponseError(msrest.serialization.Model): - """Error response for a batch request. - - :param message: The error message describing the cause of the error. - :type message: str - :param code: The error code. - :type code: str - :param inner_error: - :type inner_error: ~monitor_query_client.models.BatchResponseErrorInnerError - """ - - _attribute_map = { - 'message': {'key': 'message', 'type': 'str'}, - 'code': {'key': 'code', 'type': 'str'}, - 'inner_error': {'key': 'innerError', 'type': 'BatchResponseErrorInnerError'}, - } - - def __init__( - self, - **kwargs - ): - super(BatchResponseError, self).__init__(**kwargs) - self.message = kwargs.get('message', None) - self.code = kwargs.get('code', None) - self.inner_error = kwargs.get('inner_error', None) - - -class BatchResponseErrorInnerError(msrest.serialization.Model): - """BatchResponseErrorInnerError. - - :param code: - :type code: str - :param message: - :type message: str - :param details: - :type details: list[~monitor_query_client.models.ErrorDetails] - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'details': {'key': 'details', 'type': '[ErrorDetails]'}, - } - - def __init__( - self, - **kwargs - ): - super(BatchResponseErrorInnerError, self).__init__(**kwargs) - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - self.details = kwargs.get('details', None) class Column(msrest.serialization.Model): """A column in a table. - :param name: The name of this column. + All required parameters must be populated in order to send to Azure. + + :param name: Required. The name of this column. :type name: str - :param type: The data type of this column. - :type type: str + :param type: Required. The data type of this column. Possible values include: "bool", + "datetime", "dynamic", "int", "long", "real", "string". + :type type: str or ~monitor_query_client.models.ColumnDataType """ + _validation = { + 'name': {'required': True}, + 'type': {'required': True}, + } + _attribute_map = { 'name': {'key': 'name', 'type': 'str'}, 'type': {'key': 'type', 'type': 'str'}, @@ -125,8 +75,8 @@ def __init__( **kwargs ): super(Column, self).__init__(**kwargs) - self.name = kwargs.get('name', None) - self.type = kwargs.get('type', None) + self.name = kwargs['name'] + self.type = kwargs['type'] class ErrorDetail(msrest.serialization.Model): @@ -176,33 +126,6 @@ def __init__( self.additional_properties = kwargs.get('additional_properties', None) -class ErrorDetails(msrest.serialization.Model): - """ErrorDetails. - - :param code: - :type code: str - :param message: - :type message: str - :param target: - :type target: str - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'target': {'key': 'target', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(ErrorDetails, self).__init__(**kwargs) - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - self.target = kwargs.get('target', None) - - class ErrorInfo(msrest.serialization.Model): """The code and message for an error. @@ -378,14 +301,18 @@ class LogQueryResponse(msrest.serialization.Model): :type id: str :param status: :type status: int - :param body: Contains the tables, columns & rows resulting from a query. - :type body: ~monitor_query_client.models.QueryResults + :param body: Contains the tables, columns & rows resulting from the query or the error details + if the query failed. + :type body: ~monitor_query_client.models.LogQueryResult + :param headers: Dictionary of :code:``. + :type headers: dict[str, str] """ _attribute_map = { 'id': {'key': 'id', 'type': 'str'}, 'status': {'key': 'status', 'type': 'int'}, - 'body': {'key': 'body', 'type': 'QueryResults'}, + 'body': {'key': 'body', 'type': 'LogQueryResult'}, + 'headers': {'key': 'headers', 'type': '{str}'}, } def __init__( @@ -396,6 +323,38 @@ def __init__( self.id = kwargs.get('id', None) self.status = kwargs.get('status', None) self.body = kwargs.get('body', None) + self.headers = kwargs.get('headers', None) + + +class LogQueryResult(msrest.serialization.Model): + """Contains the tables, columns & rows resulting from the query or the error details if the query failed. + + :param tables: The list of tables, columns and rows. + :type tables: list[~monitor_query_client.models.Table] + :param error: The code and message for an error. + :type error: ~monitor_query_client.models.ErrorInfo + :param statistics: Any object. + :type statistics: object + :param render: Any object. + :type render: object + """ + + _attribute_map = { + 'tables': {'key': 'tables', 'type': '[Table]'}, + 'error': {'key': 'error', 'type': 'ErrorInfo'}, + 'statistics': {'key': 'statistics', 'type': 'object'}, + 'render': {'key': 'render', 'type': 'object'}, + } + + def __init__( + self, + **kwargs + ): + super(LogQueryResult, self).__init__(**kwargs) + self.tables = kwargs.get('tables', None) + self.error = kwargs.get('error', None) + self.statistics = kwargs.get('statistics', None) + self.render = kwargs.get('render', None) class MetadataApplication(msrest.serialization.Model): @@ -1630,12 +1589,6 @@ class QueryBody(msrest.serialization.Model): :type timespan: str :param workspaces: A list of workspaces that are included in the query. :type workspaces: list[str] - :param qualified_names: A list of qualified workspace names that are included in the query. - :type qualified_names: list[str] - :param workspace_ids: A list of workspace IDs that are included in the query. - :type workspace_ids: list[str] - :param azure_resource_ids: A list of Azure resource IDs that are included in the query. - :type azure_resource_ids: list[str] """ _validation = { @@ -1646,9 +1599,6 @@ class QueryBody(msrest.serialization.Model): 'query': {'key': 'query', 'type': 'str'}, 'timespan': {'key': 'timespan', 'type': 'str'}, 'workspaces': {'key': 'workspaces', 'type': '[str]'}, - 'qualified_names': {'key': 'qualifiedNames', 'type': '[str]'}, - 'workspace_ids': {'key': 'workspaceIds', 'type': '[str]'}, - 'azure_resource_ids': {'key': 'azureResourceIds', 'type': '[str]'}, } def __init__( @@ -1659,23 +1609,29 @@ def __init__( self.query = kwargs['query'] self.timespan = kwargs.get('timespan', None) self.workspaces = kwargs.get('workspaces', None) - self.qualified_names = kwargs.get('qualified_names', None) - self.workspace_ids = kwargs.get('workspace_ids', None) - self.azure_resource_ids = kwargs.get('azure_resource_ids', None) class QueryResults(msrest.serialization.Model): """Contains the tables, columns & rows resulting from a query. - :param tables: The list of tables, columns and rows. + All required parameters must be populated in order to send to Azure. + + :param tables: Required. The list of tables, columns and rows. :type tables: list[~monitor_query_client.models.Table] - :param errors: - :type errors: ~monitor_query_client.models.ErrorDetails + :param statistics: Any object. + :type statistics: object + :param render: Any object. + :type render: object """ + _validation = { + 'tables': {'required': True}, + } + _attribute_map = { 'tables': {'key': 'tables', 'type': '[Table]'}, - 'errors': {'key': 'errors', 'type': 'ErrorDetails'}, + 'statistics': {'key': 'statistics', 'type': 'object'}, + 'render': {'key': 'render', 'type': 'object'}, } def __init__( @@ -1683,8 +1639,9 @@ def __init__( **kwargs ): super(QueryResults, self).__init__(**kwargs) - self.tables = kwargs.get('tables', None) - self.errors = kwargs.get('errors', None) + self.tables = kwargs['tables'] + self.statistics = kwargs.get('statistics', None) + self.render = kwargs.get('render', None) class Response(msrest.serialization.Model): diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models_py3.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models_py3.py index 476ee2cd0cfb..03ee8f331112 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models_py3.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_models_py3.py @@ -41,98 +41,39 @@ class BatchResponse(msrest.serialization.Model): :param responses: An array of responses corresponding to each individual request in a batch. :type responses: list[~monitor_query_client.models.LogQueryResponse] - :param error: Error response for a batch request. - :type error: ~monitor_query_client.models.BatchResponseError """ _attribute_map = { 'responses': {'key': 'responses', 'type': '[LogQueryResponse]'}, - 'error': {'key': 'error', 'type': 'BatchResponseError'}, } def __init__( self, *, responses: Optional[List["LogQueryResponse"]] = None, - error: Optional["BatchResponseError"] = None, **kwargs ): super(BatchResponse, self).__init__(**kwargs) self.responses = responses - self.error = error - - -class BatchResponseError(msrest.serialization.Model): - """Error response for a batch request. - - :param message: The error message describing the cause of the error. - :type message: str - :param code: The error code. - :type code: str - :param inner_error: - :type inner_error: ~monitor_query_client.models.BatchResponseErrorInnerError - """ - - _attribute_map = { - 'message': {'key': 'message', 'type': 'str'}, - 'code': {'key': 'code', 'type': 'str'}, - 'inner_error': {'key': 'innerError', 'type': 'BatchResponseErrorInnerError'}, - } - - def __init__( - self, - *, - message: Optional[str] = None, - code: Optional[str] = None, - inner_error: Optional["BatchResponseErrorInnerError"] = None, - **kwargs - ): - super(BatchResponseError, self).__init__(**kwargs) - self.message = message - self.code = code - self.inner_error = inner_error - - -class BatchResponseErrorInnerError(msrest.serialization.Model): - """BatchResponseErrorInnerError. - - :param code: - :type code: str - :param message: - :type message: str - :param details: - :type details: list[~monitor_query_client.models.ErrorDetails] - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'details': {'key': 'details', 'type': '[ErrorDetails]'}, - } - - def __init__( - self, - *, - code: Optional[str] = None, - message: Optional[str] = None, - details: Optional[List["ErrorDetails"]] = None, - **kwargs - ): - super(BatchResponseErrorInnerError, self).__init__(**kwargs) - self.code = code - self.message = message - self.details = details class Column(msrest.serialization.Model): """A column in a table. - :param name: The name of this column. + All required parameters must be populated in order to send to Azure. + + :param name: Required. The name of this column. :type name: str - :param type: The data type of this column. - :type type: str + :param type: Required. The data type of this column. Possible values include: "bool", + "datetime", "dynamic", "int", "long", "real", "string". + :type type: str or ~monitor_query_client.models.ColumnDataType """ + _validation = { + 'name': {'required': True}, + 'type': {'required': True}, + } + _attribute_map = { 'name': {'key': 'name', 'type': 'str'}, 'type': {'key': 'type', 'type': 'str'}, @@ -141,8 +82,8 @@ class Column(msrest.serialization.Model): def __init__( self, *, - name: Optional[str] = None, - type: Optional[str] = None, + name: str, + type: Union[str, "ColumnDataType"], **kwargs ): super(Column, self).__init__(**kwargs) @@ -204,37 +145,6 @@ def __init__( self.additional_properties = additional_properties -class ErrorDetails(msrest.serialization.Model): - """ErrorDetails. - - :param code: - :type code: str - :param message: - :type message: str - :param target: - :type target: str - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'target': {'key': 'target', 'type': 'str'}, - } - - def __init__( - self, - *, - code: Optional[str] = None, - message: Optional[str] = None, - target: Optional[str] = None, - **kwargs - ): - super(ErrorDetails, self).__init__(**kwargs) - self.code = code - self.message = message - self.target = target - - class ErrorInfo(msrest.serialization.Model): """The code and message for an error. @@ -429,14 +339,18 @@ class LogQueryResponse(msrest.serialization.Model): :type id: str :param status: :type status: int - :param body: Contains the tables, columns & rows resulting from a query. - :type body: ~monitor_query_client.models.QueryResults + :param body: Contains the tables, columns & rows resulting from the query or the error details + if the query failed. + :type body: ~monitor_query_client.models.LogQueryResult + :param headers: Dictionary of :code:``. + :type headers: dict[str, str] """ _attribute_map = { 'id': {'key': 'id', 'type': 'str'}, 'status': {'key': 'status', 'type': 'int'}, - 'body': {'key': 'body', 'type': 'QueryResults'}, + 'body': {'key': 'body', 'type': 'LogQueryResult'}, + 'headers': {'key': 'headers', 'type': '{str}'}, } def __init__( @@ -444,13 +358,51 @@ def __init__( *, id: Optional[str] = None, status: Optional[int] = None, - body: Optional["QueryResults"] = None, + body: Optional["LogQueryResult"] = None, + headers: Optional[Dict[str, str]] = None, **kwargs ): super(LogQueryResponse, self).__init__(**kwargs) self.id = id self.status = status self.body = body + self.headers = headers + + +class LogQueryResult(msrest.serialization.Model): + """Contains the tables, columns & rows resulting from the query or the error details if the query failed. + + :param tables: The list of tables, columns and rows. + :type tables: list[~monitor_query_client.models.Table] + :param error: The code and message for an error. + :type error: ~monitor_query_client.models.ErrorInfo + :param statistics: Any object. + :type statistics: object + :param render: Any object. + :type render: object + """ + + _attribute_map = { + 'tables': {'key': 'tables', 'type': '[Table]'}, + 'error': {'key': 'error', 'type': 'ErrorInfo'}, + 'statistics': {'key': 'statistics', 'type': 'object'}, + 'render': {'key': 'render', 'type': 'object'}, + } + + def __init__( + self, + *, + tables: Optional[List["Table"]] = None, + error: Optional["ErrorInfo"] = None, + statistics: Optional[object] = None, + render: Optional[object] = None, + **kwargs + ): + super(LogQueryResult, self).__init__(**kwargs) + self.tables = tables + self.error = error + self.statistics = statistics + self.render = render class MetadataApplication(msrest.serialization.Model): @@ -1864,12 +1816,6 @@ class QueryBody(msrest.serialization.Model): :type timespan: str :param workspaces: A list of workspaces that are included in the query. :type workspaces: list[str] - :param qualified_names: A list of qualified workspace names that are included in the query. - :type qualified_names: list[str] - :param workspace_ids: A list of workspace IDs that are included in the query. - :type workspace_ids: list[str] - :param azure_resource_ids: A list of Azure resource IDs that are included in the query. - :type azure_resource_ids: list[str] """ _validation = { @@ -1880,9 +1826,6 @@ class QueryBody(msrest.serialization.Model): 'query': {'key': 'query', 'type': 'str'}, 'timespan': {'key': 'timespan', 'type': 'str'}, 'workspaces': {'key': 'workspaces', 'type': '[str]'}, - 'qualified_names': {'key': 'qualifiedNames', 'type': '[str]'}, - 'workspace_ids': {'key': 'workspaceIds', 'type': '[str]'}, - 'azure_resource_ids': {'key': 'azureResourceIds', 'type': '[str]'}, } def __init__( @@ -1891,44 +1834,49 @@ def __init__( query: str, timespan: Optional[str] = None, workspaces: Optional[List[str]] = None, - qualified_names: Optional[List[str]] = None, - workspace_ids: Optional[List[str]] = None, - azure_resource_ids: Optional[List[str]] = None, **kwargs ): super(QueryBody, self).__init__(**kwargs) self.query = query self.timespan = timespan self.workspaces = workspaces - self.qualified_names = qualified_names - self.workspace_ids = workspace_ids - self.azure_resource_ids = azure_resource_ids class QueryResults(msrest.serialization.Model): """Contains the tables, columns & rows resulting from a query. - :param tables: The list of tables, columns and rows. + All required parameters must be populated in order to send to Azure. + + :param tables: Required. The list of tables, columns and rows. :type tables: list[~monitor_query_client.models.Table] - :param errors: - :type errors: ~monitor_query_client.models.ErrorDetails + :param statistics: Any object. + :type statistics: object + :param render: Any object. + :type render: object """ + _validation = { + 'tables': {'required': True}, + } + _attribute_map = { 'tables': {'key': 'tables', 'type': '[Table]'}, - 'errors': {'key': 'errors', 'type': 'ErrorDetails'}, + 'statistics': {'key': 'statistics', 'type': 'object'}, + 'render': {'key': 'render', 'type': 'object'}, } def __init__( self, *, - tables: Optional[List["Table"]] = None, - errors: Optional["ErrorDetails"] = None, + tables: List["Table"], + statistics: Optional[object] = None, + render: Optional[object] = None, **kwargs ): super(QueryResults, self).__init__(**kwargs) self.tables = tables - self.errors = errors + self.statistics = statistics + self.render = render class Response(msrest.serialization.Model): diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_monitor_query_client_enums.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_monitor_query_client_enums.py index 3a0efc9ac6d1..09b2171d2811 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_monitor_query_client_enums.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_generated/models/_monitor_query_client_enums.py @@ -37,6 +37,18 @@ class AggregationType(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): MAXIMUM = "Maximum" TOTAL = "Total" +class ColumnDataType(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """The data type of this column. + """ + + BOOL = "bool" + DATETIME = "datetime" + DYNAMIC = "dynamic" + INT = "int" + LONG = "long" + REAL = "real" + STRING = "string" + class MetadataColumnDataType(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): """The data type of the column """ diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py index bc3176afb22c..79f14744b53d 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_log_query_client.py @@ -105,11 +105,11 @@ def query(self, workspace_id, query, duration=None, **kwargs): prefer += "wait=" + str(server_timeout) if include_statistics: if len(prefer) > 0: - prefer += ";" + prefer += " " prefer += "include-statistics=true" if include_render: if len(prefer) > 0: - prefer += ";" + prefer += " " prefer += "include-render=true" body = LogsQueryBody( diff --git a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py index c0ffc4848879..c477de7909c1 100644 --- a/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py +++ b/sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py @@ -12,7 +12,6 @@ from ._generated.models import ( Column as InternalColumn, LogQueryRequest as InternalLogQueryRequest, - ErrorDetails as InternalErrorDetails ) @@ -69,26 +68,22 @@ class LogsQueryResults(object): :keyword tables: The list of tables, columns and rows. :paramtype tables: list[~azure.monitor.query.LogsQueryResultTable] - :keyword errors: - :paramtype errors: ~azure.monitor.query.LogsErrorDetails + :keyword statistics: Any object. + :paramtype statistics: object + :keyword render: Any object. + :paramtype render: object """ def __init__(self, **kwargs): # type: (Any) -> None self.tables = kwargs.get("tables", None) - self.errors = kwargs.get("errors", None) + self.statistics = kwargs.get("statistics", None) + self.render = kwargs.get("render", None) @classmethod def _from_generated(cls, generated): if not generated: return cls() - error = None tables = None - if generated.errors is not None: - error = LogsErrorDetails( - code=generated.errors.code, - message=generated.errors.message, - target=generated.errors.target - ) if generated.tables is not None: tables = [ LogsQueryResultTable._from_generated( # pylint: disable=protected-access @@ -97,7 +92,8 @@ def _from_generated(cls, generated): ] return cls( tables=tables, - error=error + statistics=generated.statistics, + render=generated.render ) @@ -167,25 +163,48 @@ class LogsQueryRequest(InternalLogQueryRequest): :paramtype additional_workspaces: list[str] :keyword request_id: The error details. :paramtype request_id: str + :keyword int server_timeout: the server timeout. The default timeout is 3 minutes, + and the maximum timeout is 10 minutes. + :keyword bool include_statistics: To get information about query statistics. + :keyword bool include_render: In the query language, it is possible to specify different render options. + By default, the API does not return information regarding the type of visualization to show. :keyword headers: Dictionary of :code:``. :paramtype headers: dict[str, str] """ - def __init__(self, query, workspace_id, duration=None, **kwargs): + def __init__(self, query, workspace_id, duration=None, **kwargs): #pylint: disable=super-init-not-called # type: (str, str, Optional[str], Any) -> None - super(LogsQueryRequest, self).__init__(**kwargs) + include_statistics = kwargs.pop("include_statistics", False) + include_render = kwargs.pop("include_render", False) + server_timeout = kwargs.pop("server_timeout", None) + prefer = "" + if server_timeout: + prefer += "wait=" + str(server_timeout) + if include_statistics: + if len(prefer) > 0: + prefer += " " + prefer += "include-statistics=true" + if include_render: + if len(prefer) > 0: + prefer += " " + prefer += "include-render=true" + + headers = kwargs.get("headers", None) + try: + headers['Prefer'] = prefer + except TypeError: + headers = {'Prefer': prefer} start = kwargs.pop('start_time', None) end = kwargs.pop('end_time', None) timespan = construct_iso8601(start, end, duration) additional_workspaces = kwargs.pop("additional_workspaces", None) self.id = kwargs.get("request_id", str(uuid.uuid4())) - self.headers = kwargs.get("headers", None) self.body = { "query": query, "timespan": timespan, "workspaces": additional_workspaces } + self.headers = headers self.workspace = workspace_id - class LogsQueryResult(object): """The LogsQueryResult. @@ -234,8 +253,7 @@ def _from_generated(cls, generated, request_order): return cls( responses=order_results(request_order, [ LogsQueryResult._from_generated(rsp) for rsp in generated.responses # pylint: disable=protected-access - ]), - error=LogsBatchResultError._from_generated(generated.error) # pylint: disable=protected-access + ]) ) @@ -265,32 +283,6 @@ def _from_generated(cls, generated): details=generated.inner_error.details ) -class LogsErrorDetails(InternalErrorDetails): - """ErrorDetails. - - :param code: - :type code: str - :param message: - :type message: str - :param target: - :type target: str - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'target': {'key': 'target', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(LogsErrorDetails, self).__init__(**kwargs) - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - self.target = kwargs.get('target', None) - class MetricNamespace(object): """Metric namespace class specifies the metadata for a metric namespace. diff --git a/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py b/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py index 4018e0d27cc8..eff925ea8a44 100644 --- a/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py +++ b/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py @@ -21,18 +21,19 @@ LogsQueryRequest( query="AzureActivity | summarize count()", duration="PT1H", - workspace= os.environ['LOG_WORKSPACE_ID'] + workspace_id= os.environ['LOG_WORKSPACE_ID'] ), LogsQueryRequest( query= """AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", duration="PT1H", start_time=datetime(2021, 6, 2), - workspace= os.environ['LOG_WORKSPACE_ID'] + workspace_id= os.environ['LOG_WORKSPACE_ID'] ), LogsQueryRequest( - query= "AppRequests | take 2", - workspace= os.environ['LOG_WORKSPACE_ID'] + query= "AppRequests", + workspace_id= os.environ['LOG_WORKSPACE_ID'], + include_statistics=True ), ] response = client.batch_query(requests) diff --git a/sdk/monitor/azure-monitor-query/swagger/README.PYTHON.md b/sdk/monitor/azure-monitor-query/swagger/README.PYTHON.md index ee5ddee3929a..ab2e46ec9443 100644 --- a/sdk/monitor/azure-monitor-query/swagger/README.PYTHON.md +++ b/sdk/monitor/azure-monitor-query/swagger/README.PYTHON.md @@ -14,7 +14,7 @@ no-namespace-folders: true output-folder: ../azure/monitor/query/_generated source-code-folder-path: ./azure/monitor/query/_generated input-file: - - https://github.com/Azure/azure-sdk-for-java/blob/1d14101ba93c6e616899c2ded93fbecb54699f84/sdk/monitor/azure-monitor-query/swagger/log_query_swagger.json + - https://github.com/srnagar/azure-rest-api-specs/blob/a40aabf76646f487ba90350e3e489358d8ab135d/specification/operationalinsights/data-plane/Microsoft.OperationalInsights/preview/2021-05-19_Preview/OperationalInsights.json - https://github.com/Azure/azure-sdk-for-java/blob/1d14101ba93c6e616899c2ded93fbecb54699f84/sdk/monitor/azure-monitor-query/swagger/metrics_definitions.json - https://github.com/Azure/azure-sdk-for-java/blob/1d14101ba93c6e616899c2ded93fbecb54699f84/sdk/monitor/azure-monitor-query/swagger/metrics_namespaces.json - https://github.com/Azure/azure-sdk-for-java/blob/1d14101ba93c6e616899c2ded93fbecb54699f84/sdk/monitor/azure-monitor-query/swagger/metrics_swagger.json @@ -23,4 +23,44 @@ modelerfour: python: true v3: true use: "@autorest/python@5.6.4" +``` + +### Remove metadata operations + +``` yaml +directive: +- from: swagger-document + where: $ + transform: > + delete $.securityDefinitions +``` + +### Add statistics and render + +``` yaml +directive: +- from: swagger-document + where: $.definitions.logQueryResult + transform: > + $.properties["statistics"] = { "type": "object" }; + $.properties["render"] = { "type": "object" }; +``` + +``` yaml +directive: +- from: swagger-document + where: $.definitions.queryResults + transform: > + $.properties["statistics"] = { "type": "object" }; + $.properties["render"] = { "type": "object" }; +``` + +### Make properties required + +``` yaml +directive: +- from: swagger-document + where: $.definitions.column + transform: > + $.required = ["name", "type"] ``` \ No newline at end of file diff --git a/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py b/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py index e0fe0f6241a5..6044cd756e37 100644 --- a/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py +++ b/sdk/monitor/azure-monitor-query/tests/async/test_logs_client_async.py @@ -64,6 +64,7 @@ async def test_logs_batch_query(): assert len(response.responses) == 3 +@pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') @pytest.mark.live_test_only @pytest.mark.asyncio async def test_logs_single_query_additional_workspaces_async(): @@ -81,6 +82,7 @@ async def test_logs_single_query_additional_workspaces_async(): assert response assert len(response.tables[0].rows) == 2 +@pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') @pytest.mark.live_test_only @pytest.mark.asyncio async def test_logs_batch_query_additional_workspaces(): diff --git a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py index d3c0ffb8fce6..340a90f7af8f 100644 --- a/sdk/monitor/azure-monitor-query/tests/test_logs_client.py +++ b/sdk/monitor/azure-monitor-query/tests/test_logs_client.py @@ -85,6 +85,47 @@ def test_logs_batch_query(): assert len(response.responses) == 3 +@pytest.mark.live_test_only +def test_logs_single_query_with_statistics(): + credential = _credential() + client = LogsQueryClient(credential) + query = """AppRequests""" + + # returns LogsQueryResults + response = client.query(os.environ['LOG_WORKSPACE_ID'], query, include_statistics=True) + + assert response.statistics is not None + +@pytest.mark.live_test_only +def test_logs_batch_query_with_statistics_in_some(): + client = LogsQueryClient(_credential()) + + requests = [ + LogsQueryRequest( + query="AzureActivity | summarize count()", + timespan="PT1H", + workspace_id= os.environ['LOG_WORKSPACE_ID'] + ), + LogsQueryRequest( + query= """AppRequests| + summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""", + timespan="PT1H", + workspace_id= os.environ['LOG_WORKSPACE_ID'], + include_statistics=True + ), + LogsQueryRequest( + query= "AppRequests", + workspace_id= os.environ['LOG_WORKSPACE_ID'], + include_statistics=True + ), + ] + response = client.batch_query(requests) + + assert len(response.responses) == 3 + assert response.responses[0].body.statistics is None + assert response.responses[2].body.statistics is not None + +@pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') @pytest.mark.live_test_only def test_logs_single_query_additional_workspaces(): credential = _credential() @@ -102,6 +143,7 @@ def test_logs_single_query_additional_workspaces(): assert len(response.tables[0].rows) == 2 @pytest.mark.live_test_only +@pytest.mark.skip('https://github.com/Azure/azure-sdk-for-python/issues/19382') def test_logs_batch_query_additional_workspaces(): client = LogsQueryClient(_credential()) query = "union * | where TimeGenerated > ago(100d) | project TenantId | summarize count() by TenantId" @@ -127,7 +169,5 @@ def test_logs_batch_query_additional_workspaces(): ] response = client.batch_query(requests) - assert len(response.responses) == 3 - for resp in response.responses: assert len(resp.body.tables[0].rows) == 2