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

add more samples #15007

Merged
merged 5 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ def list_metric_enriched_series_data(
:return: Pageable of MetricEnrichedSeriesData
:rtype: ~azure.core.paging.ItemPaged[~azure.ai.metricsadvisor.models.MetricEnrichedSeriesData]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_metric_enriched_series_data]
:end-before: [END list_metric_enriched_series_data]
:language: python
:dedent: 4
:caption: Query metric enriched series data.
"""

series_list = [
Expand Down Expand Up @@ -487,6 +496,15 @@ def list_dimension_values(
:return: Dimension values of anomalies.
:rtype: ~azure.core.paging.ItemPaged[str]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_dimension_values]
:end-before: [END list_dimension_values]
:language: python
:dedent: 4
:caption: Query dimension values.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -646,6 +664,15 @@ def list_metric_dimension_values(self, metric_id, dimension_name, **kwargs):
:return: Dimension from certain metric.
:rtype: ~azure.core.paging.ItemPaged[str]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_metric_dimension_values]
:end-before: [END list_metric_dimension_values]
:language: python
:dedent: 4
:caption: Query metric dimension values.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -683,6 +710,15 @@ def list_metrics_series_data(self,
:return: Time series data from metric.
:rtype: ~azure.core.paging.ItemPaged[~azure.ai.metricsadvisor.models.MetricSeriesData]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_metrics_series_data]
:end-before: [END list_metrics_series_data]
:language: python
:dedent: 4
:caption: Query metrics series data.
"""

converted_start_time = convert_datetime(start_time)
Expand Down Expand Up @@ -719,6 +755,15 @@ def list_metric_series_definitions(self, metric_id, active_since, **kwargs):
:return: Series (dimension combinations) from metric.
:rtype: ~azure.core.paging.ItemPaged[~azure.ai.metricsadvisor.models.MetricSeriesDefinition]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_metric_series_definitions]
:end-before: [END list_metric_series_definitions]
:language: python
:dedent: 4
:caption: Query metric series definitions.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -749,6 +794,15 @@ def list_metric_enrichment_status(self, metric_id, start_time, end_time, **kwarg
:return: Anomaly detection status.
:rtype: ~azure.core.paging.ItemPaged[~azure.ai.metricsadvisor.models.EnrichmentStatus]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/sample_queries.py
:start-after: [START list_metric_enrichment_status]
:end-before: [END list_metric_enrichment_status]
:language: python
:dedent: 4
:caption: Query metric enrichment status.
"""

skip = kwargs.pop('skip', None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def list_incident_root_causes(self, detection_configuration_id, incident_id, **k

.. admonition:: Example:

.. literalinclude:: ../samples/sample_incidents_async.py
.. literalinclude:: ../samples/async_samples/sample_incidents_async.py
:start-after: [START list_incident_root_cause_async]
:end-before: [END list_incident_root_cause_async]
:language: python
Expand Down Expand Up @@ -279,6 +279,15 @@ def list_metric_enriched_series_data(
:return: Pageable of MetricEnrichedSeriesData
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.ai.metricsadvisor.models.MetricEnrichedSeriesData]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_metric_enriched_series_data_async]
:end-before: [END list_metric_enriched_series_data_async]
:language: python
:dedent: 4
:caption: Query metric enriched series data.
"""

series_list = [
Expand Down Expand Up @@ -493,6 +502,15 @@ def list_dimension_values(
:return: Dimension values of anomalies.
:rtype: ~azure.core.async_paging.AsyncItemPaged[str]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_dimension_values_async]
:end-before: [END list_dimension_values_async]
:language: python
:dedent: 4
:caption: Query dimension values.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -567,7 +585,7 @@ def list_incidents(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_incidents_async.py
.. literalinclude:: ../samples/async_samples/sample_incidents_async.py
:start-after: [START list_incidents_for_alert_async]
:end-before: [END list_incidents_for_alert_async]
:language: python
Expand Down Expand Up @@ -597,7 +615,7 @@ def list_incidents(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_incidents_async.py
.. literalinclude:: ../samples/async_samples/sample_incidents_async.py
:start-after: [START list_incidents_for_detection_configuration_async]
:end-before: [END list_incidents_for_detection_configuration_async]
:language: python
Expand Down Expand Up @@ -656,6 +674,15 @@ def list_metric_dimension_values(self, metric_id, dimension_name, **kwargs):
:return: Dimension from certain metric.
:rtype: ~azure.core.async_paging.AsyncItemPaged[str]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_metric_dimension_values_async]
:end-before: [END list_metric_dimension_values_async]
:language: python
:dedent: 4
:caption: Query metric dimension values.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -693,6 +720,15 @@ def list_metrics_series_data(
:return: Time series data from metric.
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.ai.metricsadvisor.models.MetricSeriesData]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_metrics_series_data_async]
:end-before: [END list_metrics_series_data_async]
:language: python
:dedent: 4
:caption: Query metrics series data.
"""

converted_start_time = convert_datetime(start_time)
Expand Down Expand Up @@ -729,6 +765,15 @@ def list_metric_series_definitions(self, metric_id, active_since, **kwargs):
:return: Series (dimension combinations) from metric.
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.ai.metricsadvisor.models.MetricSeriesDefinition]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_metric_series_definitions_async]
:end-before: [END list_metric_series_definitions_async]
:language: python
:dedent: 4
:caption: Query metric series definitions.
"""

skip = kwargs.pop('skip', None)
Expand Down Expand Up @@ -764,6 +809,15 @@ def list_metric_enrichment_status(self,
:return: Anomaly detection status.
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.ai.metricsadvisor.models.EnrichmentStatus]
:raises ~azure.core.exceptions.HttpResponseError:

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_queries_async.py
:start-after: [START list_metric_enrichment_status_async]
:end-before: [END list_metric_enrichment_status_async]
:language: python
:dedent: 4
:caption: Query metric enrichment status.
"""

skip = kwargs.pop('skip', None)
Expand Down
3 changes: 3 additions & 0 deletions sdk/metricsadvisor/azure-ai-metricsadvisor/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The async versions of the samples require Python 3.5 or later.
|[sample_anomaly_alert_configuration.py][sample_anomaly_alert_configuration] and [sample_anomaly_alert_configuration_async.py][sample_anomaly_alert_configuration_async]|Create, list, get, update, and delete anomaly alert configurations. Also list alerts and anomalies for a specific alert configuration.|
|[sample_hooks.py][sample_hooks] and [sample_hooks_async.py][sample_hooks_async]|Create, list, get, update, and delete notification hooks|
|[sample_feedback.py][sample_feedback] and [sample_feedback_async.py][sample_feedback_async]|Add, get, and list feedback for the anomaly detection result|
|[sample_queries.py][sample_queries] and [sample_queries_async.py][sample_queries_async]|Query dimensions/data/status/etc.|


## Prerequisites
Expand Down Expand Up @@ -70,3 +71,5 @@ what you can do with the Azure Metrics Advisor client library.
[sample_hooks_async]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/metricsadvisor/azure-ai-metricsadvisor/samples/async_samples/sample_hooks_async.py
[sample_feedback]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/metricsadvisor/azure-ai-metricsadvisor/samples/sample_feedback.py
[sample_feedback_async]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/metricsadvisor/azure-ai-metricsadvisor/samples/async_samples/sample_feedback_async.py
[sample_queries]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/metricsadvisor/azure-ai-metricsadvisor/samples/sample_queries.py
[sample_queries_async]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/metricsadvisor/azure-ai-metricsadvisor/samples/async_samples/sample_queries_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def sample_create_alert_config_async():
MetricsAdvisorKeyCredential(subscription_key, api_key))

async with client:
alert_config = await client.create_anomaly_alert_configuration(
alert_config = await client.create_alert_configuration(
name="my alert config",
description="alert config description",
cross_metrics_operator="AND",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def sample_create_detection_config_async():
)

async with client:
detection_config = await client.create_metric_anomaly_detection_configuration(
detection_config = await client.create_detection_configuration(
name="my_detection_config",
metric_id=metric_id,
description="anomaly detection config for metric",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
1) METRICS_ADVISOR_ENDPOINT - the endpoint of your Azure Metrics Advisor service
2) METRICS_ADVISOR_SUBSCRIPTION_KEY - Metrics Advisor service subscription key
3) METRICS_ADVISOR_API_KEY - Metrics Advisor service API key
4) METRICS_ADVISOR_METRIC_ID - the ID of an metric from an existing data feed
5) METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID - the ID of an anomaly detection configuration
6) METRICS_ADVISOR_ALERT_CONFIGURATION_ID - the ID of an alert configuration
7) METRICS_ADVISOR_INCIDENT_ID - the ID of an incident
8) METRICS_ADVISOR_ALERT_ID - the ID of an alert
4) METRICS_ADVISOR_DETECTION_CONFIGURATION_ID - the ID of an anomaly detection configuration
5) METRICS_ADVISOR_ALERT_CONFIGURATION_ID - the ID of an alert configuration
6) METRICS_ADVISOR_INCIDENT_ID - the ID of an incident
7) METRICS_ADVISOR_ALERT_ID - the ID of an alert
"""

import os
import asyncio


def sample_list_incidents_for_detection_configuration():
async def sample_list_incidents_for_detection_configuration_async():
# [START list_incidents_for_detection_configuration_async]
import datetime
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
Expand All @@ -39,49 +38,49 @@ def sample_list_incidents_for_detection_configuration():
service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
anomaly_detection_configuration_id = os.getenv("METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
async with client:
results = client.list_incidents_for_detection_configuration(
detection_configuration_id=anomaly_detection_configuration_id,
results = client.list_incidents(
detection_configuration_id=detection_configuration_id,
start_time=datetime.datetime(2020, 1, 1),
end_time=datetime.datetime(2020, 9, 9),
)
for result in results:
async for result in results:
print("Metric id: {}".format(result.metric_id))
print("Incident ID: {}".format(result.id))
print("Severity: {}".format(result.severity))
print("Status: {}".format(result.status))

# [END list_incidents_for_detection_configuration_async]

def sample_list_incident_root_cause():
async def sample_list_incident_root_cause_async():
# [START list_incident_root_cause_async]
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
from azure.ai.metricsadvisor.aio import MetricsAdvisorClient

service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
api_key = os.getenv("METRICS_ADVISOR_API_KEY")
anomaly_detection_configuration_id = os.getenv("METRICS_ADVISOR_ANOMALY_DETECTION_CONFIGURATION_ID")
detection_configuration_id = os.getenv("METRICS_ADVISOR_DETECTION_CONFIGURATION_ID")
incident_id = os.getenv("METRICS_ADVISOR_INCIDENT_ID")

client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
async with client:
results = client.list_incident_root_causes(
detection_configuration_id=anomaly_detection_configuration_id,
detection_configuration_id=detection_configuration_id,
incident_id=incident_id,
)
for result in results:
async for result in results:
print("Score: {}".format(result.score))
print("Description: {}".format(result.description))

# [END list_incident_root_cause_async]

def sample_list_incidents_for_alert():
async def sample_list_incidents_for_alert_async():
# [START list_incidents_for_alert_async]
from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
from azure.ai.metricsadvisor.aio import MetricsAdvisorClient
Expand All @@ -95,11 +94,11 @@ def sample_list_incidents_for_alert():
client = MetricsAdvisorClient(service_endpoint,
MetricsAdvisorKeyCredential(subscription_key, api_key))
async with client:
results = client.list_incidents_for_alert(
results = client.list_incidents(
alert_configuration_id=alert_configuration_id,
alert_id=alert_id,
)
for result in results:
async for result in results:
print("Metric id: {}".format(result.metric_id))
print("Incident ID: {}".format(result.id))
print("Severity: {}".format(result.severity))
Expand All @@ -110,11 +109,11 @@ def sample_list_incidents_for_alert():

async def main():
print("---List incidents for detection configuration...")
sample_list_incidents_for_detection_configuration()
await sample_list_incidents_for_detection_configuration_async()
print("---List root causes...")
sample_list_incident_root_cause()
await sample_list_incident_root_cause_async()
print("---List incidents for alert configuration...")
sample_list_incidents_for_alert()
await sample_list_incidents_for_alert_async()

if __name__ == '__main__':
loop = asyncio.get_event_loop()
Expand Down
Loading