Пример #1
0
 def _create_data_feed(self, name):
     name = create_random_name(name)
     return self.admin_client.create_data_feed(
         DataFeed(
             name=name,
             source=SQLServerDataFeed(
                 connection_string=self.sql_server_connection_string,
                 query='select * from adsample2 where Timestamp = @StartTime'
             ),
             granularity=DataFeedGranularity(
                 granularity_type="Daily",
             ),
             schema=DataFeedSchema(
                 metrics=[
                     DataFeedMetric(name="cost"),
                     DataFeedMetric(name="revenue")
                 ],
                 dimensions=[
                     DataFeedDimension(name="category"),
                     DataFeedDimension(name="city")
                 ],
                 timestamp_column="Timestamp"
             ),
             ingestion_settings=DataFeedIngestionSettings(
                 ingestion_begin_time=datetime.datetime(2019, 10, 1),
             )
         )
     )
    def test_create_simple_data_feed(self):
        data_feed_name = self.create_random_name("testfeed")
        try:
            data_feed = self.admin_client.create_data_feed(
                name=data_feed_name,
                source=SQLServerDataFeed(
                    connection_string=self.sql_server_connection_string,
                    query="select * from adsample2 where Timestamp = @StartTime"
                ),
                granularity="Daily",
                schema=["cost", "revenue"],
                ingestion_settings=datetime.datetime(2019, 10, 1)
            )

            self.assertIsNotNone(data_feed.id)
            self.assertIsNotNone(data_feed.created_time)
            self.assertIsNotNone(data_feed.name)
            self.assertEqual(data_feed.source.data_source_type, "SqlServer")
            self.assertIsNotNone(data_feed.source.connection_string)
            self.assertIsNotNone(data_feed.source.query)
            self.assertEqual(data_feed.granularity.granularity_type, "Daily")
            self.assertEqual(data_feed.schema.metrics[0].name, "cost")
            self.assertEqual(data_feed.schema.metrics[1].name, "revenue")
            self.assertEqual(data_feed.ingestion_settings.ingestion_begin_time,
                             datetime.datetime(2019, 10, 1, tzinfo=tzutc()))
        finally:
            self.admin_client.delete_data_feed(data_feed.id)
Пример #3
0
async def sample_create_data_feed_async():
    # [START create_data_feed_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorAdministrationClient
    from azure.ai.metricsadvisor.models import (
        SQLServerDataFeed,
        DataFeedSchema,
        Metric,
        Dimension,
        DataFeedOptions,
        DataFeedRollupSettings,
        DataFeedMissingDataPointFillSettings
    )

    service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
    subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
    api_key = os.getenv("METRICS_ADVISOR_API_KEY")
    sql_server_connection_string = os.getenv("METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING")
    query = os.getenv("METRICS_ADVISOR_SQL_SERVER_QUERY")

    client = MetricsAdvisorAdministrationClient(service_endpoint,
                                  MetricsAdvisorKeyCredential(subscription_key, api_key))

    async with client:
        data_feed = await client.create_data_feed(
            name="My data feed",
            source=SQLServerDataFeed(
                connection_string=sql_server_connection_string,
                query=query,
            ),
            granularity="Daily",
            schema=DataFeedSchema(
                metrics=[
                    Metric(name="cost", display_name="Cost"),
                    Metric(name="revenue", display_name="Revenue")
                ],
                dimensions=[
                    Dimension(name="category", display_name="Category"),
                    Dimension(name="city", display_name="City")
                ],
                timestamp_column="Timestamp"
            ),
            ingestion_settings=datetime.datetime(2019, 10, 1),
            options=DataFeedOptions(
                data_feed_description="cost/revenue data feed",
                rollup_settings=DataFeedRollupSettings(
                    rollup_type="AutoRollup",
                    rollup_method="Sum",
                    rollup_identification_value="__CUSTOM_SUM__"
                ),
                missing_data_point_fill_settings=DataFeedMissingDataPointFillSettings(
                    fill_type="SmartFilling"
                ),
                access_mode="Private"
            )
        )

        return data_feed
    def test_update_data_feed_with_kwargs(self):

        data_feed = self._create_data_feed_for_update("update")
        try:
            self.admin_client.update_data_feed(
                data_feed.id,
                name="update",
                data_feed_description="updated",
                timestamp_column="time",
                ingestion_begin_time=datetime.datetime(2020, 12, 10),
                ingestion_start_offset=1,
                data_source_request_concurrency=1,
                ingestion_retry_delay=1,
                stop_retry_after=1,
                rollup_type="AlreadyRollup",
                rollup_method="Sum",
                rollup_identification_value="sumrollup",
                auto_rollup_group_by_column_names=[],
                fill_type="CustomValue",
                custom_fill_value=2,
                access_mode="Public",
                viewer_emails=["updated"],
                status="Paused",
                action_link_template="updated",
                source=SQLServerDataFeed(
                    connection_string="updated",
                    query="get data"
                )
            )
            updated = self.admin_client.get_data_feed(data_feed.id)
            self.assertEqual(updated.name, "update")
            self.assertEqual(updated.options.data_feed_description, "updated")
            self.assertEqual(updated.schema.timestamp_column, "time")
            self.assertEqual(updated.ingestion_settings.ingestion_begin_time,
                             datetime.datetime(2020, 12, 10, tzinfo=tzutc()))
            self.assertEqual(updated.ingestion_settings.ingestion_start_offset, 1)
            self.assertEqual(updated.ingestion_settings.data_source_request_concurrency, 1)
            self.assertEqual(updated.ingestion_settings.ingestion_retry_delay, 1)
            self.assertEqual(updated.ingestion_settings.stop_retry_after, 1)
            self.assertEqual(updated.options.rollup_settings.rollup_type, "AlreadyRollup")
            self.assertEqual(updated.options.rollup_settings.rollup_method, "Sum")
            self.assertEqual(updated.options.rollup_settings.rollup_identification_value, "sumrollup")
            self.assertEqual(updated.options.rollup_settings.auto_rollup_group_by_column_names, [])
            self.assertEqual(updated.options.missing_data_point_fill_settings.fill_type, "CustomValue")
            self.assertEqual(updated.options.missing_data_point_fill_settings.custom_fill_value, 2)
            self.assertEqual(updated.options.access_mode, "Public")
            self.assertEqual(updated.options.viewer_emails, ["updated"])
            self.assertEqual(updated.status, "Paused")
            self.assertEqual(updated.options.action_link_template, "updated")
            self.assertEqual(updated.source.connection_string, "updated")
            self.assertEqual(updated.source.query, "get data")

        finally:
            self.admin_client.delete_data_feed(data_feed.id)
Пример #5
0
 def _create_data_feed_for_update(self, name):
     data_feed_name = create_random_name(name)
     return self.admin_client.create_data_feed(
         DataFeed(
             name=data_feed_name,
             source=SQLServerDataFeed(
                 connection_string=self.sql_server_connection_string,
                 query='select * from adsample2 where Timestamp = @StartTime'
             ),
             granularity=DataFeedGranularity(
                 granularity_type="Daily",
             ),
             schema=DataFeedSchema(
                 metrics=[
                     DataFeedMetric(name="cost", display_name="display cost", description="the cost"),
                     DataFeedMetric(name="revenue", display_name="display revenue", description="the revenue")
                 ],
                 dimensions=[
                     DataFeedDimension(name="category", display_name="display category"),
                     DataFeedDimension(name="city", display_name="display city")
                 ],
                 timestamp_column="Timestamp"
             ),
             ingestion_settings=DataFeedIngestionSettings(
                 ingestion_begin_time=datetime.datetime(2019, 10, 1),
                 data_source_request_concurrency=0,
                 ingestion_retry_delay=-1,
                 ingestion_start_offset=-1,
                 stop_retry_after=-1,
             ),
             options=DataFeedOptions(
                 admin_emails=["*****@*****.**"],
                 data_feed_description="my first data feed",
                 missing_data_point_fill_settings=DataFeedMissingDataPointFillSettings(
                     fill_type="SmartFilling"
                 ),
                 rollup_settings=DataFeedRollupSettings(
                     rollup_type="NoRollup",
                     rollup_method="None",
                 ),
                 viewer_emails=["viewers"],
                 access_mode="Private",
                 action_link_template="action link template"
             )
         )
     )
 def _create_data_feed(self, name):
     name = self.create_random_name(name)
     return self.admin_client.create_data_feed(
         name=name,
         source=SQLServerDataFeed(
             connection_string=self.sql_server_connection_string,
             query="select * from adsample2 where Timestamp = @StartTime"),
         granularity="Daily",
         schema=DataFeedSchema(
             metrics=[Metric(name="cost"),
                      Metric(name="revenue")],
             dimensions=[
                 Dimension(name="category"),
                 Dimension(name="city")
             ],
         ),
         ingestion_settings="2019-10-01T00:00:00Z",
     )
    def test_create_data_feed_from_sql_server(self):

        data_feed_name = self.create_random_name("testfeed")
        try:
            data_feed = self.admin_client.create_data_feed(
                name=data_feed_name,
                source=SQLServerDataFeed(
                    connection_string=self.sql_server_connection_string,
                    query=u"select * from adsample2 where Timestamp = @StartTime"
                ),
                granularity=DataFeedGranularity(
                    granularity_type="Daily",
                ),
                schema=DataFeedSchema(
                    metrics=[
                        Metric(name="cost", display_name="display cost", description="the cost"),
                        Metric(name="revenue", display_name="display revenue", description="the revenue")
                    ],
                    dimensions=[
                        Dimension(name="category", display_name="display category"),
                        Dimension(name="city", display_name="display city")
                    ],
                    timestamp_column="Timestamp"
                ),
                ingestion_settings=DataFeedIngestionSettings(
                    ingestion_begin_time=datetime.datetime(2019, 10, 1),
                    data_source_request_concurrency=0,
                    ingestion_retry_delay=-1,
                    ingestion_start_offset=-1,
                    stop_retry_after=-1,
                ),
                options=DataFeedOptions(
                    admins=["*****@*****.**"],
                    data_feed_description="my first data feed",
                    missing_data_point_fill_settings=DataFeedMissingDataPointFillSettings(
                        fill_type="SmartFilling"
                    ),
                    rollup_settings=DataFeedRollupSettings(
                        rollup_type="NoRollup",
                        rollup_method="None",
                    ),
                    viewers=["viewers"],
                    access_mode="Private",
                    action_link_template="action link template"
                )

            )
            self.assertIsNotNone(data_feed.id)
            self.assertIsNotNone(data_feed.created_time)
            self.assertIsNotNone(data_feed.name)
            self.assertEqual(data_feed.source.data_source_type, "SqlServer")
            self.assertIsNotNone(data_feed.source.connection_string)
            self.assertIsNotNone(data_feed.source.query)
            self.assertEqual(data_feed.granularity.granularity_type, "Daily")
            self.assertEqual(data_feed.granularity.custom_granularity_value, None)
            self.assertEqual(data_feed.schema.metrics[0].name, "cost")
            self.assertEqual(data_feed.schema.metrics[1].name, "revenue")
            self.assertEqual(data_feed.schema.metrics[0].display_name, "display cost")
            self.assertEqual(data_feed.schema.metrics[1].display_name, "display revenue")
            self.assertEqual(data_feed.schema.metrics[0].description, "the cost")
            self.assertEqual(data_feed.schema.metrics[1].description, "the revenue")
            self.assertEqual(data_feed.schema.dimensions[0].name, "category")
            self.assertEqual(data_feed.schema.dimensions[1].name, "city")
            self.assertEqual(data_feed.schema.dimensions[0].display_name, "display category")
            self.assertEqual(data_feed.schema.dimensions[1].display_name, "display city")
            self.assertEqual(data_feed.ingestion_settings.ingestion_begin_time,
                             datetime.datetime(2019, 10, 1, tzinfo=tzutc()))
            self.assertEqual(data_feed.ingestion_settings.data_source_request_concurrency, 0)
            self.assertEqual(data_feed.ingestion_settings.ingestion_retry_delay, -1)
            self.assertEqual(data_feed.ingestion_settings.ingestion_start_offset, -1)
            self.assertEqual(data_feed.ingestion_settings.stop_retry_after, -1)
            self.assertIn("*****@*****.**", data_feed.options.admins)
            self.assertEqual(data_feed.options.data_feed_description, "my first data feed")
            self.assertEqual(data_feed.options.missing_data_point_fill_settings.fill_type, "SmartFilling")
            self.assertEqual(data_feed.options.rollup_settings.rollup_type, "NoRollup")
            self.assertEqual(data_feed.options.rollup_settings.rollup_method, "None")
            self.assertEqual(data_feed.options.viewers, ["viewers"])
            self.assertEqual(data_feed.options.access_mode, "Private")
            self.assertEqual(data_feed.options.action_link_template, "action link template")
            self.assertEqual(data_feed.status, "Active")
            self.assertTrue(data_feed.is_admin)
            self.assertIsNotNone(data_feed.metric_ids)

        finally:
            self.admin_client.delete_data_feed(data_feed.id)

            with self.assertRaises(ResourceNotFoundError):
                self.admin_client.get_data_feed(data_feed.id)