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

Consistency related changes #20385

Merged
merged 8 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions sdk/monitor/azure-monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Features Added

- Added additional `display_description` attribute to the `Metric` type.
- Added a `MetricClass` enum to provide the class of a metric.
- Added a `metric_class` attribute to the `MetricDefinition` type.
- Added a `MetricNamespaceClassification` enum to support the `namespace_classification` attribute on `MetricNamespace` type.

### Breaking Changes

Expand All @@ -22,6 +25,11 @@
- `LogsQueryResult` now returns `datetime` objects for a time values.
- `LogsBatchQuery` doesn't accept a `request_id` anymore.
- `MetricsMetadataValues` is removed. A dictionary is used instead.
- `time_stamp` is renamed to `timestamp` in `MetricValue` type.
- `AggregationType` is renamed to `MetricAggregationType`.
- Removed `LogsBatchResultError` type.
- `LogsQueryResultTable` is named to `LogsTable`
- `LogsQueryResultColumn` is renamed to `LogsTableColumn`

### Bugs Fixed

Expand Down
8 changes: 4 additions & 4 deletions sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ LogsQueryResult / LogsBatchQueryResult
|---statistics
|---visualization
|---error
|---tables (list of `LogsQueryResultTable` objects)
|---tables (list of `LogsTable` objects)
|---name
|---rows
|---columns (list of `LogsQueryResultColumn` objects)
|---columns (list of `LogsTableColumn` objects)
|---name
|---type
```
Expand Down Expand Up @@ -313,7 +313,7 @@ MetricsResult
```python
import os
from datetime import datetime, timedelta
from azure.monitor.query import MetricsQueryClient, AggregationType
from azure.monitor.query import MetricsQueryClient, MetricAggregationType
from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential()
Expand All @@ -323,7 +323,7 @@ metrics_uri = os.environ['METRICS_RESOURCE_URI']
response = client.query(
metrics_uri,
metric_names=["MatchedEventCount"],
aggregations=[AggregationType.COUNT]
aggregations=[MetricAggregationType.COUNT]
)

for metric in response.metrics:
Expand Down
18 changes: 10 additions & 8 deletions sdk/monitor/azure-monitor-query/azure/monitor/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,42 @@
from ._metrics_query_client import MetricsQueryClient

from ._models import (
AggregationType,
MetricAggregationType,
LogsBatchQueryResult,
LogsQueryResult,
LogsQueryResultTable,
LogsQueryResultColumn,
LogsTable,
LogsTableColumn,
MetricsResult,
LogsBatchResultError,
LogsBatchQuery,
MetricNamespace,
MetricNamespaceClassification,
MetricDefinition,
TimeSeriesElement,
Metric,
MetricValue,
MetricClass,
MetricAvailability
)

from ._version import VERSION

__all__ = [
"AggregationType",
"MetricAggregationType",
"LogsQueryClient",
"LogsBatchQueryResult",
"LogsBatchResultError",
"LogsQueryResult",
"LogsQueryResultColumn",
"LogsQueryResultTable",
"LogsTableColumn",
"LogsTable",
"LogsBatchQuery",
"MetricsQueryClient",
"MetricNamespace",
"MetricNamespaceClassification",
"MetricDefinition",
"MetricsResult",
"TimeSeriesElement",
"Metric",
"MetricValue",
"MetricClass",
"MetricAvailability"
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def query(self, resource_uri, metric_names, **kwargs):
or tuple[~datetime.datetime, ~datetime.datetime]
:keyword granularity: The granularity (i.e. timegrain) of the query.
:paramtype granularity: ~datetime.timedelta
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
enum to get each aggregation type.
:keyword aggregations: The list of aggregation types to retrieve. Use
`azure.monitor.query.MetricAggregationType` enum to get each aggregation type.
:paramtype aggregations: list[str]
:keyword max_results: The maximum number of records to retrieve.
Valid only if $filter is specified.
Expand Down Expand Up @@ -134,7 +134,7 @@ def list_metric_namespaces(self, resource_uri, **kwargs):
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
namespaces.
:paramtype start_time: str
:return: An iterator like instance of either MetricNamespaceCollection or the result of cls(response)
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
:raises: ~azure.core.exceptions.HttpResponseError
"""
Expand Down
89 changes: 46 additions & 43 deletions sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
)


class LogsQueryResultTable(object):
class LogsTable(object):
"""Contains the columns and rows for one table in a query response.

All required parameters must be populated in order to send to Azure.

:param name: Required. The name of the table.
:type name: str
:param columns: Required. The list of columns in this table.
:type columns: list[~azure.monitor.query.LogsQueryResultColumn]
:type columns: list[~azure.monitor.query.LogsTableColumn]
:param rows: Required. The resulting rows from this query.
:type rows: list[list[str]]
"""
def __init__(self, name, columns, rows):
# type: (str, List[LogsQueryResultColumn], List[List[str]]) -> None
# type: (str, List[LogsTableColumn], List[List[str]]) -> None
self.name = name
self.columns = columns
self.rows = [process_row(self.columns, row) for row in rows]
Expand All @@ -38,12 +38,12 @@ def __init__(self, name, columns, rows):
def _from_generated(cls, generated):
return cls(
name=generated.name,
columns=[LogsQueryResultColumn(name=col.name, type=col.type) for col in generated.columns],
columns=[LogsTableColumn(name=col.name, type=col.type) for col in generated.columns],
rows=generated.rows
)


class LogsQueryResultColumn(InternalColumn):
class LogsTableColumn(InternalColumn):
"""A column in a table.

:ivar name: The name of this column.
Expand All @@ -59,7 +59,7 @@ class LogsQueryResultColumn(InternalColumn):

def __init__(self, **kwargs):
# type: (Any) -> None
super(LogsQueryResultColumn, self).__init__(**kwargs)
super(LogsTableColumn, self).__init__(**kwargs)
self.name = kwargs.get("name", None)
self.type = kwargs.get("type", None)

Expand All @@ -68,7 +68,7 @@ class LogsQueryResult(object):
"""Contains the tables, columns & rows resulting from a query.

:ivar tables: The list of tables, columns and rows.
:vartype tables: list[~azure.monitor.query.LogsQueryResultTable]
:vartype tables: list[~azure.monitor.query.LogsTable]
:ivar statistics: This will include a statistics property in the response that describes various
performance statistics such as query execution time and resource usage.
:vartype statistics: object
Expand All @@ -92,7 +92,7 @@ def _from_generated(cls, generated):
tables = None
if generated.tables is not None:
tables = [
LogsQueryResultTable._from_generated( # pylint: disable=protected-access
LogsTable._from_generated( # pylint: disable=protected-access
table
) for table in generated.tables
]
Expand Down Expand Up @@ -222,7 +222,7 @@ class LogsBatchQueryResult(object):
:ivar status: status code of the response.
:vartype status: int
:ivar tables: The list of tables, columns and rows.
:vartype tables: list[~azure.monitor.query.LogsQueryResultTable]
:vartype tables: list[~azure.monitor.query.LogsTable]
:ivar statistics: This will include a statistics property in the response that describes various
performance statistics such as query execution time and resource usage.
:vartype statistics: object
Expand Down Expand Up @@ -250,7 +250,7 @@ def _from_generated(cls, generated):
tables = None
if generated.body.tables is not None:
tables = [
LogsQueryResultTable._from_generated( # pylint: disable=protected-access
LogsTable._from_generated( # pylint: disable=protected-access
table
) for table in generated.body.tables
]
Expand All @@ -264,31 +264,13 @@ def _from_generated(cls, generated):
)


class LogsBatchResultError(object):
"""Error response for a batch request.

:ivar message: The error message describing the cause of the error.
:vartype message: str
:param code: The error code.
:vartype code: str
:param details: The details of the error.
:vartype inner_error: list[~azure.monitor.query.ErrorDetails]
class MetricNamespaceClassification(str, Enum):
"""Kind of namespace
"""
def __init__(self, **kwargs):
# type: (Any) -> None
self.message = kwargs.get("message", None)
self.code = kwargs.get("code", None)
self.details = kwargs.get("details", None)

@classmethod
def _from_generated(cls, generated):
if not generated:
return cls()
return cls(
message=generated.inner_error.message,
code=generated.code,
details=generated.inner_error.details
)
PLATFORM = "Platform"
CUSTOM = "Custom"
QOS = "Qos"


class MetricNamespace(object):
Expand All @@ -302,6 +284,8 @@ class MetricNamespace(object):
:paramtype name: str
:keyword fully_qualified_namespace: The fully qualified namespace name.
:paramtype fully_qualified_namespace: str
:keyword namespace_classification: Kind of namespace. Possible values include: "Platform", "Custom", "Qos".
:paramtype namespace_classification: str or ~azure.monitor.query.MetricNamespaceClassification
"""
def __init__(
self,
Expand All @@ -311,6 +295,7 @@ def __init__(
self.type = kwargs.get('type', None)
self.name = kwargs.get('name', None)
self.fully_qualified_namespace = kwargs.get('fully_qualified_namespace', None)
self.namespace_classification = kwargs.get('namespace_classification', None)

@classmethod
def _from_generated(cls, generated):
Expand All @@ -323,10 +308,23 @@ def _from_generated(cls, generated):
id=generated.id,
type=generated.type,
name=generated.name,
fully_qualified_namespace=fully_qualified_namespace
fully_qualified_namespace=fully_qualified_namespace,
namespace_classification=generated.classification
)

class MetricDefinition(object):

class MetricClass(str, Enum):
"""The class of the metric.
"""

AVAILABILITY = "Availability"
TRANSACTIONS = "Transactions"
ERRORS = "Errors"
LATENCY = "Latency"
SATURATION = "Saturation"


class MetricDefinition(object): #pylint: disable=too-many-instance-attributes
"""Metric definition class specifies the metadata for a metric.

:keyword dimension_required: Flag to indicate whether the dimension is required.
Expand All @@ -344,12 +342,15 @@ class MetricDefinition(object):
:keyword primary_aggregation_type: the primary aggregation type value defining how to use the
values for display. Possible values include: "None", "Average", "Count", "Minimum", "Maximum",
"Total".
:paramtype primary_aggregation_type: str or ~monitor_query_client.models.AggregationType
:paramtype primary_aggregation_type: str or ~azure.monitor.query.MetricAggregationType
:keyword metric_class: The class of the metric. Possible values include: "Availability",
"Transactions", "Errors", "Latency", "Saturation".
:paramtype metric_class: str or ~azure.monitor.query.MetricClass
:keyword supported_aggregation_types: the collection of what aggregation types are supported.
:paramtype supported_aggregation_types: list[str or ~monitor_query_client.models.AggregationType]
:paramtype supported_aggregation_types: list[str or ~azure.monitor.query.MetricAggregationType]
:keyword metric_availabilities: the collection of what aggregation intervals are available to be
queried.
:paramtype metric_availabilities: list[~monitor_query_client.models.MetricAvailability]
:paramtype metric_availabilities: list[~azure.monitor.query.MetricAvailability]
:keyword id: the resource identifier of the metric definition.
:paramtype id: str
:keyword dimensions: the name and the display name of the dimension, i.e. it is a localizable
Expand All @@ -371,6 +372,7 @@ def __init__(
self.metric_availabilities = kwargs.get('metric_availabilities', None) # type: List[MetricAvailability]
self.id = kwargs.get('id', None) # type: Optional[str]
self.dimensions = kwargs.get('dimensions', None) # type: Optional[List[str]]
self.metric_class = kwargs.get('metric_class', None) # type: Optional[str]

@classmethod
def _from_generated(cls, generated):
Expand All @@ -387,6 +389,7 @@ def _from_generated(cls, generated):
unit=generated.unit,
primary_aggregation_type=generated.primary_aggregation_type,
supported_aggregation_types=generated.supported_aggregation_types,
metric_class=generated.metric_class,
metric_availabilities=[
MetricAvailability._from_generated( # pylint: disable=protected-access
val
Expand All @@ -401,8 +404,8 @@ class MetricValue(object):

All required parameters must be populated in order to send to Azure.

:ivar time_stamp: Required. The timestamp for the metric value in ISO 8601 format.
:vartype time_stamp: ~datetime.datetime
:ivar timestamp: Required. The timestamp for the metric value in ISO 8601 format.
:vartype timestamp: ~datetime.datetime
:ivar average: The average value in the time range.
:vartype average: float
:ivar minimum: The least value in the time range.
Expand All @@ -420,7 +423,7 @@ def __init__(
**kwargs
):
# type: (Any) -> None
self.time_stamp = kwargs['time_stamp']
self.timestamp = kwargs['timestamp']
self.average = kwargs.get('average', None)
self.minimum = kwargs.get('minimum', None)
self.maximum = kwargs.get('maximum', None)
Expand All @@ -432,7 +435,7 @@ def _from_generated(cls, generated):
if not generated:
return cls()
return cls(
time_stamp=generated.time_stamp,
timestamp=generated.time_stamp,
average=generated.average,
minimum=generated.minimum,
maximum=generated.maximum,
Expand Down Expand Up @@ -552,7 +555,7 @@ def _from_generated(cls, generated):
)


class AggregationType(str, Enum):
class MetricAggregationType(str, Enum):
"""The aggregation type of the metric.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def query(
or tuple[~datetime.datetime, ~datetime.datetime]
:keyword granularity: The interval (i.e. timegrain) of the query.
:paramtype granularity: ~datetime.timedelta
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.MetricAggregationType`
enum to get each aggregation type.
:paramtype aggregations: list[str]
:keyword max_results: The maximum number of records to retrieve.
Expand Down Expand Up @@ -118,7 +118,7 @@ def list_metric_namespaces(self, resource_uri: str, **kwargs: Any) -> AsyncItemP
:keyword start_time: The ISO 8601 conform Date start time from which to query for metric
namespaces.
:paramtype start_time: str
:return: An iterator like instance of either MetricNamespaceCollection or the result of cls(response)
:return: An iterator like instance of either MetricNamespace or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.monitor.query.MetricNamespace]
:raises: ~azure.core.exceptions.HttpResponseError
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def logs_query():

# if you dont want to use pandas - here's how you can process it.

#response.tables is a LogsQueryResultTable
#response.tables is a LogsTable
for table in response.tables:
for col in table.columns: #LogsQueryResultColumn
print(col.name + "/"+ col.type + " | ", end="")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if not response.tables:
print("No results for the query")

#response.tables is a LogsQueryResultTable
#response.tables is a LogsTable
for table in response.tables:
for col in table.columns: #LogsQueryResultColumn
print(col.name + "/"+ col.type + " | ", end="")
Expand Down
Loading