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

chore(ci_visibility): create client for test visibility backend API #10752

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

romainkomorndatadog
Copy link
Collaborator

This creates a new client for the Test Visibility API.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@romainkomorndatadog romainkomorndatadog self-assigned this Sep 22, 2024
Copy link
Contributor

github-actions bot commented Sep 22, 2024

CODEOWNERS have been resolved as:

ddtrace/internal/ci_visibility/_api_client.py                           @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/git_data.py                              @DataDog/ci-app-libraries
tests/ci_visibility/api_client/_util.py                                 @DataDog/ci-app-libraries
tests/ci_visibility/api_client/real_world_skippable_response_flask_suite_level.json  @DataDog/ci-app-libraries
tests/ci_visibility/api_client/real_world_skippable_response_flask_test_level.json  @DataDog/ci-app-libraries
tests/ci_visibility/api_client/test_ci_visibility_api_client.py         @DataDog/ci-app-libraries
tests/ci_visibility/api_client/test_ci_visibility_api_client_setting_responses.py  @DataDog/ci-app-libraries
tests/ci_visibility/api_client/test_ci_visibility_api_client_skippable_real_world_responses.py  @DataDog/ci-app-libraries
tests/ci_visibility/api_client/test_ci_visibility_api_client_skippable_responses.py  @DataDog/ci-app-libraries
tests/ci_visibility/test_ci_visibility_check_enabled_features.py        @DataDog/ci-app-libraries
ddtrace/contrib/pytest/_plugin_v1.py                                    @DataDog/ci-app-libraries
ddtrace/contrib/pytest/_plugin_v2.py                                    @DataDog/ci-app-libraries
ddtrace/ext/test_visibility/__init__.py                                 @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_base.py                             @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_module.py                           @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_session.py                          @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/api/_test.py                             @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/constants.py                             @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/errors.py                                @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/recorder.py                              @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/telemetry/itr.py                         @DataDog/ci-app-libraries
ddtrace/internal/ci_visibility/utils.py                                 @DataDog/ci-app-libraries
ddtrace/internal/test_visibility/coverage_lines.py                      @DataDog/ci-app-libraries
pyproject.toml                                                          @DataDog/python-guild
tests/ci_visibility/api/fake_runner_all_itr_skip_suite_level.py         @DataDog/ci-app-libraries
tests/ci_visibility/api/fake_runner_mix_fail_itr_suite_level.py         @DataDog/ci-app-libraries
tests/ci_visibility/api/test_api_fake_runners.py                        @DataDog/ci-app-libraries
tests/ci_visibility/api/test_internal_test_visibility_api.py            @DataDog/ci-app-libraries
tests/ci_visibility/test_ci_visibility.py                               @DataDog/ci-app-libraries
tests/ci_visibility/test_encoder.py                                     @DataDog/ci-app-libraries
tests/ci_visibility/util.py                                             @DataDog/ci-app-libraries
tests/contrib/asynctest/test_asynctest.py                               @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/pytest/test_coverage_per_suite.py                         @DataDog/ci-app-libraries
tests/contrib/pytest/test_pytest.py                                     @DataDog/ci-app-libraries
tests/contrib/pytest/test_pytest_snapshot.py                            @DataDog/ci-app-libraries
tests/contrib/pytest/test_pytest_snapshot_v2.py                         @DataDog/ci-app-libraries
tests/contrib/pytest_bdd/test_pytest_bdd.py                             @DataDog/ci-app-libraries
tests/contrib/pytest_benchmark/test_pytest_benchmark.py                 @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/unittest/test_unittest.py                                 @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/unittest/test_unittest_snapshot.py                        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/integration/test_integration_civisibility.py                      @DataDog/apm-core-python

Comment on lines 155 to 164
else:
return EVPProxyTestVisibilityClient(
itr_skipping_level,
git_data,
self.default_configurations,
agent_url,
dd_service,
dd_env,
client_timeout,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

else is not necessary since the if clause has a return (...read more)

If the code in the if branch returns a value, do not have the else branch present.

View in Datadog  Leave us feedback  Documentation



def _get_mock_connection(body):
class _mock_http_response:
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

class names should be CamelCase (...read more)

Class names should be CapWords and not camelCase or snake_case.

Learn More

View in Datadog  Leave us feedback  Documentation

Comment on lines +154 to +157
except: # noqa: E722
log.debug("Failed to parse coverage data for file %s", covered_file)
parse_errors += 1
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

no bare except (...read more)

Avoid bare except. Try to always use specialized exception names in except blocks.

View in Datadog  Leave us feedback  Documentation

Comment on lines 155 to 164
else:
return EVPProxyTestVisibilityClient(
itr_skipping_level,
git_data,
self.default_configurations,
agent_url,
dd_service,
dd_env,
client_timeout,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

else is not necessary since the if clause has a return (...read more)

If the code in the if branch returns a value, do not have the else branch present.

View in Datadog  Leave us feedback  Documentation



def _get_mock_connection(body):
class _mock_http_response:
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

class names should be CamelCase (...read more)

Class names should be CapWords and not camelCase or snake_case.

Learn More

View in Datadog  Leave us feedback  Documentation

Comment on lines +154 to +157
except: # noqa: E722
log.debug("Failed to parse coverage data for file %s", covered_file)
parse_errors += 1
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

no bare except (...read more)

Avoid bare except. Try to always use specialized exception names in except blocks.

View in Datadog  Leave us feedback  Documentation

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Sep 22, 2024

Datadog Report

Branch report: romain.komorn/SDTEST-854/add_flaky_tests_retry_api
Commit report: 6df23bd
Test service: dd-trace-py

✅ 0 Failed, 592 Passed, 694 Skipped, 20m 3.81s Total duration (16m 59.4s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Sep 22, 2024

Benchmarks

Benchmark execution time: 2024-09-23 17:09:48

Comparing candidate commit 6df23bd in PR branch romain.komorn/SDTEST-854/add_flaky_tests_retry_api with baseline commit aef5bc0 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 353 metrics, 47 unstable metrics.

parse_errors = 0
for covered_file, covered_lines_bytes in covered_files_data.items():
try:
covered_lines = CoverageLines.from_bytearray(bytearray(b64decode(covered_lines_bytes)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to say that we already have a from_b64_string method in CoverageLines, but it turns out it's missing the b64decode() there (which I think is wrong).

Copy link
Collaborator Author

@romainkomorndatadog romainkomorndatadog Sep 23, 2024

Choose a reason for hiding this comment

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

😓 that's because I started adding that method and the decided it wasn't worth adding as a new method to the API (but then neglected to remove it).

try:
suite_id = _get_suite_id_from_skippable_suite(skippable_suite)
suites_to_skip.add(suite_id)
except Exception: # noqa: E722
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes we use bare except and sometimes we use except Exception, should we standardize on a single one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I think I just lack enough of an opinion to pick one. :D Maybe just except: ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the code quality thingy seems to complain about bare except: but not about except Exception: (but then again, it may be updated to complain about except Exception: too at some point, so this is not a strong argument). One potential point in favor of except Exception is that it makes you stop and thing "do I really need to catch every exception?" (but then again, in the tracer we often do want that).

ddtrace/internal/ci_visibility/_api_client.py Show resolved Hide resolved
ddtrace/internal/ci_visibility/constants.py Show resolved Hide resolved
@@ -68,7 +68,7 @@ def subprocess_run(self, *args):

def test_and_emit_get_version(self):
version = get_version()
assert type(version) == str
assert type(version) is str
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

use isintance() instead of type() (...read more)

Using isinstance is faster than type but also consider inheritance, which makes it more accurate.

View in Datadog  Leave us feedback  Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants