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

Validate metrics using metadata.csv #6027

Merged
merged 3 commits into from
Apr 16, 2020
Merged

Conversation

AlexandreYang
Copy link
Member

@AlexandreYang AlexandreYang commented Mar 11, 2020

What does this PR do?

Validate metrics using metadata.csv.

See examples below:

tests/test_check.py:79: in test_e2e
    aggregator.assert_metrics_using_metadata(exclude=['lighttpd.performance.busy_servers'])
../datadog_checks_base/datadog_checks/base/stubs/aggregator.py:336: in assert_metrics_using_metadata
    assert not errors, "Metadata assertion errors using metadata.csv: " + "\n\t- ".join([""] + sorted(list(errors)))
E   AssertionError: Metadata assertion errors using metadata.csv:
E     	- Expect `lighttpd.net.bytes` to be in metadata.csv.
E     	- Expect `lighttpd.net.request_per_s` to be in metadata.csv.
E     	- Expect `lighttpd.performance.idle_server` to have type `count` but got `gauge`.
E     	- Expect `lighttpd.performance.uptime` to be in metadata.csv.
E   assert not {'Expect `lighttpd.net.bytes` to be in metadata.csv.', 'Expect `lighttpd.net.request_per_s` to be in metadata.csv.', '...nce.idle_server` to have type `count` but got `gauge`.', 'Expect `lighttpd.performance.uptime` to be in metadata.csv.'}

Motivation

That will help validating that metadata.csv metric types and actual types match.

Additional Notes

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #6027 into master will decrease coverage by 0.37%.
The diff coverage is 21.42%.

Impacted Files Coverage Δ
...hecks_base/datadog_checks/base/stubs/aggregator.py 67.21% <21.05%> (-4.21%) ⬇️
datadog_checks_dev/datadog_checks/dev/utils.py 51.53% <22.22%> (-1.42%) ⬇️
datadog_checks_base/tests/conftest.py 39.13% <0.00%> (-60.87%) ⬇️
datadog_checks_dev/tests/test_docker.py 48.14% <0.00%> (-51.86%) ⬇️
disk/tests/common.py 61.53% <0.00%> (-38.47%) ⬇️
datadog_checks_dev/tests/tooling/test_utils.py 73.40% <0.00%> (-26.60%) ⬇️
datadog_checks_dev/datadog_checks/dev/env.py 22.72% <0.00%> (-20.46%) ⬇️
datadog_checks_dev/datadog_checks/dev/docker.py 25.80% <0.00%> (-18.55%) ⬇️
...atadog_checks_dev/datadog_checks/dev/structures.py 68.85% <0.00%> (-18.04%) ⬇️
datadog_checks_dev/tests/test_conditions.py 82.25% <0.00%> (-17.75%) ⬇️
... and 579 more

@AlexandreYang AlexandreYang changed the title Add metric type using metadata.csv Validate metrics using metadata.csv Mar 11, 2020
@AlexandreYang AlexandreYang marked this pull request as ready for review March 11, 2020 15:14
@AlexandreYang AlexandreYang requested review from a team as code owners March 11, 2020 15:14
Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad idea to have as the default behavior since most environments would need to be extremely specialized to produce even the majority of metrics.

Instead, let's add a new method that asserts everything in metadata.csv and add the ability to pass in a list of metrics to exclude.

WDYT?

@AlexandreYang AlexandreYang requested a review from ofek March 11, 2020 17:06
Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use

@AlexandreYang
Copy link
Member Author

AlexandreYang commented Mar 11, 2020

On hold, need to move stubs to datadog_checks_dev first.

Related: #3700 (comment)

@AlexandreYang AlexandreYang changed the title Validate metrics using metadata.csv [HOLD] Validate metrics using metadata.csv Mar 12, 2020
@AlexandreYang AlexandreYang changed the title [HOLD] Validate metrics using metadata.csv Validate metrics using metadata.csv Apr 9, 2020
@AlexandreYang
Copy link
Member Author

AlexandreYang commented Apr 9, 2020

@ofek

I changed the implementation to avoid aggregator. assert_metrics_using_metadata depending on the metadata.csv file internally.

Now aggregator. assert_metrics_using_metadata received the metadata_metrics as an argument. Better decoupling and reusability.

@@ -301,6 +301,45 @@ def assert_all_metrics_covered(self):
msg += '\nMissing Metrics:{}{}'.format(prefix, prefix.join(sorted(self.not_asserted())))
assert condition, msg

def assert_metrics_using_metadata(self, metadata_metrics, check_metric_type=True, exclude=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt? since more integrations would have integration tests and not e2e

Suggested change
def assert_metrics_using_metadata(self, metadata_metrics, check_metric_type=True, exclude=None):
def assert_metrics_using_metadata(self, metadata_metrics, check_metric_type=False, exclude=None):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ofek
I think this method has the most value for e2e since check the type is quite valuable.

Having check_metric_type=True by default will encourage that. WDYT?

Co-Authored-By: Ofek Lev <ofekmeister@gmail.com>
@AlexandreYang AlexandreYang requested a review from ofek April 16, 2020 14:29
@AlexandreYang AlexandreYang merged commit 52706b0 into master Apr 16, 2020
@dd-devflow dd-devflow bot deleted the alex/auto_assert_metric_type branch February 7, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants