mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 13:12:39 +08:00
Use public metrics (#1093)
This commit is contained in:
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@ -6,7 +6,7 @@ on:
|
||||
- 'release/*'
|
||||
pull_request:
|
||||
env:
|
||||
CORE_REPO_SHA: f367ec2045b2588be95dfa11913868c1d4fcbbc2
|
||||
CORE_REPO_SHA: 741389585b5d6d1af808a8939c5348113158f969
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@ -37,7 +37,7 @@ jobs:
|
||||
run: pip install -U tox-factor
|
||||
- name: Cache tox environment
|
||||
# Preserves .tox directory between runs for faster installs
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: |
|
||||
.tox
|
||||
@ -113,7 +113,7 @@ jobs:
|
||||
run: sudo apt-get install -y libsnappy-dev
|
||||
- name: Cache tox environment
|
||||
# Preserves .tox directory between runs for faster installs
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: |
|
||||
.tox
|
||||
|
@ -42,10 +42,10 @@ Usage
|
||||
|
||||
.. code:: python
|
||||
|
||||
from opentelemetry._metrics import set_meter_provider
|
||||
from opentelemetry.metrics import set_meter_provider
|
||||
from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor
|
||||
from opentelemetry.sdk._metrics import MeterProvider
|
||||
from opentelemetry.sdk._metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader
|
||||
from opentelemetry.sdk.metrics import MeterProvider
|
||||
from opentelemetry.sdk.metrics.export import ConsoleMetricExporter, PeriodicExportingMetricReader
|
||||
|
||||
exporter = ConsoleMetricExporter()
|
||||
|
||||
@ -76,13 +76,12 @@ from typing import Collection, Dict, Iterable, List, Optional
|
||||
|
||||
import psutil
|
||||
|
||||
from opentelemetry._metrics import CallbackOptions, Observation, get_meter
|
||||
|
||||
# FIXME Remove this pyling disabling line when Github issue is cleared
|
||||
# pylint: disable=no-name-in-module
|
||||
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
||||
from opentelemetry.instrumentation.system_metrics.package import _instruments
|
||||
from opentelemetry.instrumentation.system_metrics.version import __version__
|
||||
from opentelemetry.metrics import CallbackOptions, Observation, get_meter
|
||||
from opentelemetry.sdk.util import get_dict_as_key
|
||||
|
||||
_DEFAULT_CONFIG = {
|
||||
|
@ -21,8 +21,8 @@ from unittest import mock
|
||||
from opentelemetry.instrumentation.system_metrics import (
|
||||
SystemMetricsInstrumentor,
|
||||
)
|
||||
from opentelemetry.sdk._metrics import MeterProvider
|
||||
from opentelemetry.sdk._metrics.export import InMemoryMetricReader
|
||||
from opentelemetry.sdk.metrics import MeterProvider
|
||||
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
|
||||
from opentelemetry.test.test_base import TestBase
|
||||
|
||||
|
||||
@ -70,8 +70,11 @@ class TestSystemMetrics(TestBase):
|
||||
meter_provider = MeterProvider(metric_readers=[reader])
|
||||
system_metrics = SystemMetricsInstrumentor()
|
||||
system_metrics.instrument(meter_provider=meter_provider)
|
||||
metrics = reader.get_metrics()
|
||||
metric_names = list({x.name for x in metrics})
|
||||
metric_names = []
|
||||
for resource_metrics in reader.get_metrics_data().resource_metrics:
|
||||
for scope_metrics in resource_metrics.scope_metrics:
|
||||
for metric in scope_metrics.metrics:
|
||||
metric_names.append(metric.name)
|
||||
self.assertEqual(len(metric_names), 17)
|
||||
|
||||
observer_names = [
|
||||
@ -100,17 +103,22 @@ class TestSystemMetrics(TestBase):
|
||||
|
||||
def _assert_metrics(self, observer_name, reader, expected):
|
||||
assertions = 0
|
||||
for metric in reader.get_metrics(): # pylint: disable=protected-access
|
||||
for expect in expected:
|
||||
if (
|
||||
metric.attributes == expect.attributes
|
||||
and metric.name == observer_name
|
||||
):
|
||||
self.assertEqual(
|
||||
metric.point.value,
|
||||
expect.value,
|
||||
)
|
||||
assertions += 1
|
||||
# pylint: disable=too-many-nested-blocks
|
||||
for resource_metrics in reader.get_metrics_data().resource_metrics:
|
||||
for scope_metrics in resource_metrics.scope_metrics:
|
||||
for metric in scope_metrics.metrics:
|
||||
for data_point in metric.data.data_points:
|
||||
for expect in expected:
|
||||
if (
|
||||
dict(data_point.attributes)
|
||||
== expect.attributes
|
||||
and metric.name == observer_name
|
||||
):
|
||||
self.assertEqual(
|
||||
data_point.value,
|
||||
expect.value,
|
||||
)
|
||||
assertions += 1
|
||||
self.assertEqual(len(expected), assertions)
|
||||
|
||||
def _test_metrics(self, observer_name, expected):
|
||||
|
Reference in New Issue
Block a user