def test_create_envelope(self):
        metric = create_metric()
        exporter = metrics_exporter.MetricsExporter(
            instrumentation_key='12345678-1234-5678-abcd-12345678abcd')
        value = metric.time_series[0].points[0].value.value
        data_point = DataPoint(ns=metric.descriptor.name,
                               name=metric.descriptor.name,
                               value=value)
        timestamp = datetime(2019, 3, 20, 21, 34, 0, 537954)
        properties = {'url': 'website.com'}
        envelope = exporter._create_envelope(data_point, timestamp, properties)

        self.assertTrue('iKey' in envelope)
        self.assertEqual(envelope.iKey, '12345678-1234-5678-abcd-12345678abcd')
        self.assertTrue('tags' in envelope)
        self.assertTrue('time' in envelope)
        self.assertEqual(envelope.time, timestamp.isoformat())
        self.assertTrue('name' in envelope)
        self.assertEqual(envelope.name, 'Microsoft.ApplicationInsights.Metric')
        self.assertTrue('data' in envelope)
        self.assertTrue('baseData' in envelope.data)
        self.assertTrue('baseType' in envelope.data)
        self.assertTrue('metrics' in envelope.data.baseData)
        self.assertTrue('properties' in envelope.data.baseData)
        self.assertEqual(envelope.data.baseData.properties, properties)
Пример #2
0
 def _create_data_points(self, time_series, metric_descriptor):
     """Convert a metric's OC time series to list of Azure data points."""
     data_points = []
     for point in time_series.points:
         # TODO: Possibly encode namespace in name
         data_point = DataPoint(ns=metric_descriptor.name,
                                name=metric_descriptor.name,
                                value=point.value.value)
         data_points.append(data_point)
     return data_points