(
        self, metadata_metrics, check_metric_type=True, check_submission_type=False, exclude=None
    )
Assert metrics using metadata.csv

        Checking type: By default we are asserting the in-app metric type (`check_submission_type=False`),
        asserting this type make sense for e2e (metrics collected from agent).
        For integrations tests, we can check the submission type with `check_submission_type=True`, or
        use `check_metric_type=False` not to check types.

        Usage:

            from datadog_checks.dev.utils import get_metadata_metrics
            aggregator.assert_metrics_using_metadata(get_metadata_metrics())
Assert metrics using metadata.csv
Assert metrics using metadata . csv
def assert_metrics_using_metadata(
        self, metadata_metrics, check_metric_type=True, check_submission_type=False, exclude=None
    ):
        """
        Assert metrics using metadata.csv

        Checking type: By default we are asserting the in-app metric type (`check_submission_type=False`),
        asserting this type make sense for e2e (metrics collected from agent).
        For integrations tests, we can check the submission type with `check_submission_type=True`, or
        use `check_metric_type=False` not to check types.

        Usage:

            from datadog_checks.dev.utils import get_metadata_metrics
            aggregator.assert_metrics_using_metadata(get_metadata_metrics())

        """

        exclude = exclude or []
        errors = set()
        for metric_name, metric_stubs in iteritems(self._metrics):
            if metric_name in exclude:
                continue
            for metric_stub in metric_stubs:
                metric_stub_name = backend_normalize_metric_name(metric_stub.name)
                actual_metric_type = AggregatorStub.METRIC_ENUM_MAP_REV[metric_stub.type]

                # We only check `*.count` metrics for histogram and historate submissions
                # Note: all Openmetrics histogram and summary metrics are actually separately submitted
                if check_submission_type and actual_metric_type in ['histogram', 'historate']:
                    metric_stub_name += '.count'

                # Checking the metric is in `metadata.csv`
                if metric_stub_name not in metadata_metrics:
                    errors.add("Expect `{}` to be in metadata.csv.".format(metric_stub_name))
                    continue

                expected_metric_type = metadata_metrics[metric_stub_name]['metric_type']
                if check_submission_type:
                    # Integration tests type mapping
                    actual_metric_type = AggregatorStub.METRIC_TYPE_SUBMISSION_TO_BACKEND_MAP[actual_metric_type]
                else:
                    # E2E tests
                    if actual_metric_type == 'monotonic_count' and expected_metric_type == 'count':
                        actual_metric_type = 'count'

                if check_metric_type:
                    if expected_metric_type != actual_metric_type:
                        errors.add(
                            "Expect `{}` to have type `{}` but got `{}`.".format(
                                metric_stub_name, expected_metric_type, actual_metric_type
                            )
                        )

        assert not errors, "Metadata assertion errors using metadata.csv:" + "\n\t- ".join([''] + sorted(errors))
def assert_metrics_using_metadata ( self , metadata_metrics , check_metric_type = True , check_submission_type = False , exclude = None ) : exclude = exclude or [ ] errors = set ( ) for metric_name , metric_stubs in iteritems ( self . _metrics ) : if metric_name in exclude : continue for metric_stub in metric_stubs : metric_stub_name = backend_normalize_metric_name ( metric_stub . name ) actual_metric_type = AggregatorStub . METRIC_ENUM_MAP_REV [ metric_stub . type ] # We only check `*.count` metrics for histogram and historate submissions # Note: all Openmetrics histogram and summary metrics are actually separately submitted if check_submission_type and actual_metric_type in [ 'histogram' , 'historate' ] : metric_stub_name += '.count' # Checking the metric is in `metadata.csv` if metric_stub_name not in metadata_metrics : errors . add ( "Expect `{}` to be in metadata.csv." . format ( metric_stub_name ) ) continue expected_metric_type = metadata_metrics [ metric_stub_name ] [ 'metric_type' ] if check_submission_type : # Integration tests type mapping actual_metric_type = AggregatorStub . METRIC_TYPE_SUBMISSION_TO_BACKEND_MAP [ actual_metric_type ] else : # E2E tests if actual_metric_type == 'monotonic_count' and expected_metric_type == 'count' : actual_metric_type = 'count' if check_metric_type : if expected_metric_type != actual_metric_type : errors . add ( "Expect `{}` to have type `{}` but got `{}`." . format ( metric_stub_name , expected_metric_type , actual_metric_type ) ) assert not errors , "Metadata assertion errors using metadata.csv:" + "\n\t- " . join ( [ '' ] + sorted ( errors ) )