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

[datadog_synthetics_test] Add javascript assertion to Synthetics Assertion #2576

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

RomainGuarinoni
Copy link
Contributor

@RomainGuarinoni RomainGuarinoni commented Sep 11, 2024

SYNTH-14849

Context

We want to add the capabilities to create JS assertions with terraform

Important

Because the javascript assertion does not contains any operator, we need to make the operator field of an assertion Optional.

Because we cannot validate a field based on another field in schema right now, it means we cannot make the operator optional only if type is javascript and make it required otherwise.

This implies that we cannot validate anymore if the user forgot to add an operator for a non javascript assertion, and terraform will still perform the request to dogweb and then display the validation error from dogweb.

But we still have the operator validation, meaning terraform will fail if the user provide a wrong operator value

Now, we have thew options to deal with this issue:

  1. Do nothing about it, and let the terraform accept an assertion with no operator (other than javascript assertion) and then display the error from dogweb :
{"errors":["'assertions' value '{'operator': '', 'target': 2000, 'type': 'responseTime'}' is invalid"]}
  1. Add an special operator for this kind of case where we don't really need any operator, such as noOperator or something like this. This would require a lot of work in the worker, frontend and api spec because we already created a bunch of type for this assertion assuming there is no operator
  2. Create a new schema for assertion without operator so we still have the required operator for regular assertions, and no operator for the js assertion, for example:
  assertion {
    type     = "responseTime"
    operator = "is"
    target   = "200"
  }
  javascript_assertion {
    type = "javascript"
    code = "console.log('hello world')"
  }

Change

  • add the new NewSyntheticsAssertionJavascriptTypeFromValue value to validate the assertion type value
  • add the code field to the assertion
  • set the operator field to optional
  • update function buildDatadogAssertions to create javascript assertion
  • update buildTerraformAssertions to handle javascript assertion
  • update test to create a javascript assertion

QA

Tested locally with the provider and it works

@RomainGuarinoni RomainGuarinoni force-pushed the romain.guarinoni/add-js-assertion branch from 467cde6 to d832faf Compare September 11, 2024 14:33
@RomainGuarinoni RomainGuarinoni force-pushed the romain.guarinoni/add-js-assertion branch from d832faf to eda92a8 Compare September 16, 2024 08:57
@RomainGuarinoni RomainGuarinoni marked this pull request as ready for review September 16, 2024 09:55
@RomainGuarinoni RomainGuarinoni requested review from a team as code owners September 16, 2024 09:55
@RomainGuarinoni RomainGuarinoni changed the title [SYNTH-14849] Add javascript assertion to Synthetics Assertion [datadog_synthetics_test] Add javascript assertion to Synthetics Assertion Sep 16, 2024
@HantingZhang2 HantingZhang2 merged commit 8ea5c87 into master Sep 18, 2024
16 of 18 checks passed
@HantingZhang2 HantingZhang2 deleted the romain.guarinoni/add-js-assertion branch September 18, 2024 15:08
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.

4 participants