Skip to content

Commit

Permalink
feat: update the creation of new test assertions to use new regex
Browse files Browse the repository at this point in the history
OCD-4785
  • Loading branch information
tmy1313 committed Jan 8, 2025
1 parent b2a0a19 commit 7f65f40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public SyntheticsAPITest createSyntheticsTest(String url, List<Long> developerId
.type(SyntheticsAssertionType.STATUS_CODE)),
new SyntheticsAssertion(new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.MATCHES)
.target("/[\\S\s]+[\\S]+/")
.target("/[\\S]/")
.type(SyntheticsAssertionType.BODY))))
.request(new SyntheticsTestRequest()
.url(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
Expand Down Expand Up @@ -63,8 +61,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
datadogSyntheticsTestService.getAllSyntheticsTests().forEach(test -> {
String url = test.getConfig().getRequest().getUrl();

if (url.equals("https://www.praxisemr.com/applicationaccess/api/help/")) {
SyntheticsAPITest body = new SyntheticsAPITest()
SyntheticsAPITest body = new SyntheticsAPITest()
.config(new SyntheticsAPITestConfig()
.assertions(Arrays.asList(
new SyntheticsAssertion(new SyntheticsAssertionTarget()
Expand Down Expand Up @@ -115,28 +112,17 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
.name(url)
.tags(test.getTags());

try {
datadogSyntheticsTestService.getApiProvider().getApiInstance().updateAPITest(test.getPublicId(), body);
LOGGER.info("Test updated: {}", url);
} catch (ApiException e) {
LOGGER.error("Could not update test for URL: {}", url, e);
}
} else {
LOGGER.info("Test NOT updated: {}", url);
try {
datadogSyntheticsTestService.getApiProvider().getApiInstance().updateAPITest(test.getPublicId(), body);
LOGGER.info("Test updated: {}", url);
} catch (ApiException e) {
LOGGER.error("Could not update test for URL: {}", url, e);
}
});

LOGGER.info("********* Completed the Fix Datadog Url Uptime Assertions Job *********");
}

private Optional<SyntheticsAssertion> getContentHeaderAssertionExist(List<SyntheticsAssertion> assertions) {
return assertions.stream()
.filter(assertion -> assertion.getSyntheticsAssertionTarget().getType().equals(SyntheticsAssertionType.HEADER)
&& assertion.getSyntheticsAssertionTarget().getProperty().equals("content-length"))
.findAny();

}

private Long convertMinutesToSeconds(Long minutes) {
return minutes * SECONDS_IN_A_MINUTE;
}
Expand Down

0 comments on commit 7f65f40

Please sign in to comment.