DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
612 stars 304 forks source link

Synthetics CI test API returns 502 error when called with metadata object #694

Closed spr0ut closed 2 years ago

spr0ut commented 3 years ago

Describe the bug The synthetics api for running tests triggered from ci with metadata included produces a 502 error. HTTP response body: {"errors": ["'pipeline' should be object"]}

With the metadata removed, the synthetics test is triggers successfully but without the metadata present, it's impossible to tell which branch/commit triggered the test.

To Reproduce Tested with curl:

curl -X POST \
-H 'Content-Type: application/json' \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d '{
    "tests": [
        {
            "public_id": "{A_VALID_TEST_ID}"
        }
    ],
    "metadata": {
        "git": {
            "branch": "test"
        },
        "ci": {
            "pipeline": {},
            "provider": {
                "name": "azdo"
            }
        }
    }
}' "https://api.datadoghq.com/api/v1/synthetics/tests/trigger/ci"

Also tested with python client using the example in the docs from https://datadoghq.dev/datadog-api-client-python/v1/SyntheticsApi/#trigger_ci_tests. This is simplified by removing everything else not needed, keeping the metadata.


import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import synthetics_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the API class
    api_instance = synthetics_api.SyntheticsApi(api_client)
    body = SyntheticsCITestBody(
        tests=[
            SyntheticsCITest(
                metadata=SyntheticsCITestMetadata(
                    ci=SyntheticsCITestMetadataCi(
                        pipeline="pipeline_example",
                        provider="provider_example",
                    ),
                    git=SyntheticsCITestMetadataGit(
                        branch="branch_example",
                        commit_sha="commit_sha_example",
                    ),
                ),
                public_id="A_VALID_TEST_ID",
            ),
        ],
    ) # SyntheticsCITestBody | Details of the test to trigger.

# example passing only required values which don't have defaults set
try:
# Trigger tests from CI/CD pipelines
    api_response = api_instance.trigger_ci_tests(body)
    print(api_response)
except ApiException as e:
    print("Exception when calling SyntheticsApi->trigger_ci_tests: %s\n" % e)

Expected behavior
The synthetic test is triggered, and is displayed in datadog with the supplied metadata (branch, pipeline, commit etc.)

Environment and Versions (please complete the following information):
datadogpy v0.42.0

github-actions[bot] commented 2 years ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

spr0ut commented 2 years ago

Not stale. Waiting for response on the original repo.

spr0ut commented 2 years ago

Looks like this was resolved with https://github.com/DataDog/datadog-api-client-python/pull/610.