Skip to content

Commit

Permalink
Rename attrs is metrics (Azure#20236)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakshith Bhyravabhotla authored Aug 16, 2021
1 parent 22e5b84 commit 7ba9f04
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
5 changes: 5 additions & 0 deletions sdk/monitor/azure-monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
- `include_render` is now renamed to `include_visualization` in the query API.
- `LogsQueryResult` and `LogsBatchQueryResult` now return `visualization` instead of `render`.
- `start_time`, `duration` and `end_time` are now replaced with a single param called `timespan`
- `resourceregion` is renamed to `resource_region` in the MetricResult type.
- `top` is renamed to `max_results` in the metric's `query` API.
- `metric_namespace_name` is renamed to `fully_qualified_namespace`
- `is_dimension_required` is renamed to `dimension_required`
- `time_grain` is renamed to `granularity`

### Bugs Fixed

Expand Down
2 changes: 1 addition & 1 deletion sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ MetricsResult
|---timespan
|---cost
|---namespace
|---resourceregion
|---resource_region
|---metrics (list of `Metric` objects)
|---id
|---type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def query(self, resource_uri, metric_names, **kwargs):
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
enum to get each aggregation type.
:paramtype aggregations: list[str]
:keyword top: The maximum number of records to retrieve.
:keyword max_results: The maximum number of records to retrieve.
Valid only if $filter is specified.
Defaults to 10.
:paramtype top: int
:paramtype max_results: int
:keyword orderby: The aggregation to use for sorting results and the direction of the sort.
Only one order can be specified.
Examples: sum asc.
Expand Down Expand Up @@ -116,6 +116,7 @@ def query(self, resource_uri, metric_names, **kwargs):
timespan = construct_iso8601(kwargs.pop("timespan", None))
kwargs.setdefault("metricnames", ",".join(metric_names))
kwargs.setdefault("timespan", timespan)
kwargs.setdefault("top", kwargs.pop("max_results", None))
generated = self._metrics_op.list(resource_uri, connection_verify=False, **kwargs)
return MetricsResult._from_generated(generated) # pylint: disable=protected-access

Expand Down
36 changes: 18 additions & 18 deletions sdk/monitor/azure-monitor-query/azure/monitor/query/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class MetricsResult(object):
:vartype interval: ~datetime.timedelta
:ivar namespace: The namespace of the metrics that has been queried.
:vartype namespace: str
:ivar resourceregion: The region of the resource that has been queried for metrics.
:vartype resourceregion: str
:ivar resource_region: The region of the resource that has been queried for metrics.
:vartype resource_region: str
:ivar metrics: Required. The value of the collection.
:vartype metrics: list[~monitor_query_client.models.Metric]
"""
Expand All @@ -132,7 +132,7 @@ def __init__(self, **kwargs):
self.timespan = kwargs["timespan"]
self.interval = kwargs.get("interval", None)
self.namespace = kwargs.get("namespace", None)
self.resourceregion = kwargs.get("resourceregion", None)
self.resource_region = kwargs.get("resource_region", None)
self.metrics = kwargs["metrics"]

@classmethod
Expand All @@ -144,7 +144,7 @@ def _from_generated(cls, generated):
timespan=generated.timespan,
interval=generated.interval,
namespace=generated.namespace,
resourceregion=generated.resourceregion,
resource_region=generated.resourceregion,
metrics=[Metric._from_generated(m) for m in generated.value] # pylint: disable=protected-access
)

Expand Down Expand Up @@ -302,8 +302,8 @@ class MetricNamespace(object):
:paramtype type: str
:keyword name: The name of the namespace.
:paramtype name: str
:keyword metric_namespace_name: The fully qualified namespace name.
:paramtype metric_namespace_name: str
:keyword fully_qualified_namespace: The fully qualified namespace name.
:paramtype fully_qualified_namespace: str
"""
def __init__(
self,
Expand All @@ -312,27 +312,27 @@ def __init__(
self.id = kwargs.get('id', None)
self.type = kwargs.get('type', None)
self.name = kwargs.get('name', None)
self.metric_namespace_name = kwargs.get('metric_namespace_name', None)
self.fully_qualified_namespace = kwargs.get('fully_qualified_namespace', None)

@classmethod
def _from_generated(cls, generated):
if not generated:
return cls()
metric_namespace_name = None
fully_qualified_namespace = None
if generated.properties:
metric_namespace_name = generated.properties.metric_namespace_name
fully_qualified_namespace = generated.properties.metric_namespace_name
return cls(
id=generated.id,
type=generated.type,
name=generated.name,
metric_namespace_name=metric_namespace_name
fully_qualified_namespace=fully_qualified_namespace
)

class MetricDefinition(object):
"""Metric definition class specifies the metadata for a metric.
:keyword is_dimension_required: Flag to indicate whether the dimension is required.
:paramtype is_dimension_required: bool
:keyword dimension_required: Flag to indicate whether the dimension is required.
:paramtype dimension_required: bool
:keyword resource_id: the resource identifier of the resource that emitted the metric.
:paramtype resource_id: str
:keyword namespace: the namespace the metric belongs to.
Expand Down Expand Up @@ -363,7 +363,7 @@ def __init__(
**kwargs
):
# type: (Any) -> None
self.is_dimension_required = kwargs.get('is_dimension_required', None) # type: Optional[bool]
self.dimension_required = kwargs.get('dimension_required', None) # type: Optional[bool]
self.resource_id = kwargs.get('resource_id', None) # type: Optional[str]
self.namespace = kwargs.get('namespace', None) # type: Optional[str]
self.name = kwargs.get('name', None) # type: Optional[str]
Expand All @@ -382,7 +382,7 @@ def _from_generated(cls, generated):
if generated.dimensions is not None:
dimensions = [d.value for d in generated.dimensions]
return cls(
is_dimension_required=generated.is_dimension_required,
dimension_required=generated.is_dimension_required,
resource_id=generated.resource_id,
namespace=generated.namespace,
name=generated.name.value,
Expand Down Expand Up @@ -552,9 +552,9 @@ class MetricAvailability(object):
"""Metric availability specifies the time grain (aggregation interval or frequency)
and the retention period for that time grain.
:keyword time_grain: the time grain specifies the aggregation interval for the metric. Expressed
:keyword granularity: the time grain specifies the aggregation interval for the metric. Expressed
as a duration 'PT1M', 'P1D', etc.
:paramtype time_grain: ~datetime.timedelta
:paramtype granularity: ~datetime.timedelta
:keyword retention: the retention period for the metric at the specified timegrain. Expressed as
a duration 'PT1M', 'P1D', etc.
:paramtype retention: ~datetime.timedelta
Expand All @@ -564,15 +564,15 @@ def __init__(
**kwargs
):
# type: (Any) -> None
self.time_grain = kwargs.get('time_grain', None)
self.granularity = kwargs.get('granularity', None)
self.retention = kwargs.get('retention', None)

@classmethod
def _from_generated(cls, generated):
if not generated:
return cls()
return cls(
time_grain=generated.time_grain,
granularity=generated.time_grain,
retention=generated.retention
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ async def query(
:keyword aggregations: The list of aggregation types to retrieve. Use `azure.monitor.query.AggregationType`
enum to get each aggregation type.
:paramtype aggregations: list[str]
:keyword top: The maximum number of records to retrieve.
:keyword max_results: The maximum number of records to retrieve.
Valid only if $filter is specified.
Defaults to 10.
:paramtype top: int
:paramtype max_results: int
:keyword orderby: The aggregation to use for sorting results and the direction of the sort.
Only one order can be specified.
Examples: sum asc.
Expand All @@ -97,6 +97,7 @@ async def query(
timespan = construct_iso8601(kwargs.pop('timespan', None))
kwargs.setdefault("metricnames", ",".join(metric_names))
kwargs.setdefault("timespan", timespan)
kwargs.setdefault("top", kwargs.pop("max_results", None))
aggregations = kwargs.pop("aggregations", None)
if aggregations:
kwargs.setdefault("aggregation", ",".join(aggregations))
Expand Down

0 comments on commit 7ba9f04

Please sign in to comment.