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

feat(synthetics): addition of support for next-gen runtime to step, cert check, broken links monitors #1114

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .tutone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ packages:
field_type_override: "*SyntheticsDeviceEmulationInput"
- name: SyntheticsRuntimeInput
field_type_override: "*SyntheticsRuntimeInput"
- name: SyntheticsExtendedTypeMonitorRuntimeInput
field_type_override: "*SyntheticsExtendedTypeMonitorRuntimeInput"
# overrides and specifications of fields associated with the syntheticsStartAutomatedTest mutation start here
- name: SyntheticsAutomatedTestConfigInput
struct_tags:
Expand Down
24 changes: 24 additions & 0 deletions pkg/synthetics/synthetics_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 135 additions & 1 deletion pkg/synthetics/synthetics_api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,8 @@ func TestSyntheticsBrokenLinksMonitor_Basic(t *testing.T) {
Values: []string{"avocado"},
},
},
Uri: "https://www.google.com",
Uri: "https://www.google.com",
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{},
}

createdMonitor, err := a.SyntheticsCreateBrokenLinksMonitor(testAccountID, monitorInput)
Expand All @@ -758,6 +759,10 @@ func TestSyntheticsBrokenLinksMonitor_Basic(t *testing.T) {
Locations: monitorInput.Locations,
Tags: monitorInput.Tags,
Uri: fmt.Sprintf("%s?updated=true", monitorInput.Uri),
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "NODE_API",
RuntimeTypeVersion: "16.10",
},
}

updatedMonitor, err := a.SyntheticsUpdateBrokenLinksMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
Expand Down Expand Up @@ -799,6 +804,10 @@ func TestSyntheticsCertCheckMonitor_Basic(t *testing.T) {
// do not add a "https://" to the domain; recent error handling in Synthetics throws an "invalid domain" error with "https://"
Domain: "www.google.com",
NumberDaysToFailBeforeCertExpires: 1,
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "NODE_API",
RuntimeTypeVersion: "16.10",
},
}

createdMonitor, err := a.SyntheticsCreateCertCheckMonitor(testAccountID, monitorInput)
Expand All @@ -815,6 +824,7 @@ func TestSyntheticsCertCheckMonitor_Basic(t *testing.T) {
Tags: monitorInput.Tags,
Domain: fmt.Sprintf("%s?updated=true", monitorInput.Domain),
NumberDaysToFailBeforeCertExpires: 2,
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{},
}

updatedMonitor, err := a.SyntheticsUpdateCertCheckMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
Expand Down Expand Up @@ -870,6 +880,10 @@ func TestSyntheticsStepMonitor_Basic(t *testing.T) {
Values: []string{"%=", "New Relic"}, // %= is used for "contains" logic
},
},
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "CHROME_BROWSER",
RuntimeTypeVersion: "100",
},
}

createdMonitor, err := a.SyntheticsCreateStepMonitor(testAccountID, monitorInput)
Expand Down Expand Up @@ -898,6 +912,7 @@ func TestSyntheticsStepMonitor_Basic(t *testing.T) {
Values: []string{"h2.NewDesign", "present", "true"},
},
},
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{},
}

updatedMonitor, err := a.SyntheticsUpdateStepMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
Expand Down Expand Up @@ -1826,6 +1841,125 @@ func TestSynthetics_MonitorDowntimeMonthly_Error(t *testing.T) {
require.Error(t, err)
}

func TestSyntheticsBrokenLinksMonitor_IncorrectRuntimeError(t *testing.T) {
testAccountID, err := mock.GetTestAccountID()
if err != nil {
t.Skipf("%s", err)
}

a := newIntegrationTestClient(t)

monitorName := generateSyntheticsEntityNameForIntegrationTest("MONITOR", false)
monitorInput := SyntheticsCreateBrokenLinksMonitorInput{
Name: monitorName,
Period: SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES,
Status: SyntheticsMonitorStatusTypes.DISABLED,
Locations: SyntheticsLocationsInput{
Public: []string{"AP_SOUTH_1"},
},
Tags: []SyntheticsTag{
{
Key: "coconut",
Values: []string{"avocado"},
},
},
Uri: "https://www.google.com",
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "INVALID_RUNTIME",
RuntimeTypeVersion: "INVALID_RUNTIME",
},
}

createdMonitor, err := a.SyntheticsCreateBrokenLinksMonitor(testAccountID, monitorInput)
require.NotNil(t, createdMonitor.Errors[0].Description)
require.Equal(t, createdMonitor.Errors[0].Description, "Runtime values are invalid combination.")
}

func TestSyntheticsCertCheckMonitor_IncorrectRuntimeError(t *testing.T) {
testAccountID, err := mock.GetTestAccountID()
if err != nil {
t.Skipf("%s", err)
}

a := newIntegrationTestClient(t)

monitorName := generateSyntheticsEntityNameForIntegrationTest("MONITOR", false)
monitorInput := SyntheticsCreateCertCheckMonitorInput{
Name: monitorName,
Period: SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES,
Status: SyntheticsMonitorStatusTypes.DISABLED,
Locations: SyntheticsLocationsInput{
Public: []string{"AP_SOUTH_1"},
},
Tags: []SyntheticsTag{
{
Key: "coconut",
Values: []string{"avocado"},
},
},
// do not add a "https://" to the domain; recent error handling in Synthetics throws an "invalid domain" error with "https://"
Domain: "www.google.com",
NumberDaysToFailBeforeCertExpires: 1,
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "INVALID_RUNTIME",
RuntimeTypeVersion: "INVALID_RUNTIME",
},
}

createdMonitor, err := a.SyntheticsCreateCertCheckMonitor(testAccountID, monitorInput)
require.NotNil(t, createdMonitor.Errors[0].Description)
require.Equal(t, createdMonitor.Errors[0].Description, "Runtime values are invalid combination.")
}

func TestSyntheticsStepMonitor_IncorrectRuntimeError(t *testing.T) {
testAccountID, err := mock.GetTestAccountID()
if err != nil {
t.Skipf("%s", err)
}

a := newIntegrationTestClient(t)

monitorName := generateSyntheticsEntityNameForIntegrationTest("MONITOR", false)
enableScreenshotOnFailureAndScript := true
monitorInput := SyntheticsCreateStepMonitorInput{
Name: monitorName,
Period: SyntheticsMonitorPeriodTypes.EVERY_DAY,
Status: SyntheticsMonitorStatusTypes.DISABLED,
AdvancedOptions: SyntheticsStepMonitorAdvancedOptionsInput{
EnableScreenshotOnFailureAndScript: &enableScreenshotOnFailureAndScript,
},
Locations: SyntheticsScriptedMonitorLocationsInput{
Public: []string{"AP_SOUTH_1"},
},
Tags: []SyntheticsTag{
{
Key: "step",
Values: []string{"monitor"},
},
},
Steps: []SyntheticsStepInput{
{
Ordinal: 0,
Type: SyntheticsStepTypeTypes.NAVIGATE,
Values: []string{"https://one.newrelic.com"},
},
{
Ordinal: 1,
Type: SyntheticsStepTypeTypes.ASSERT_TITLE,
Values: []string{"%=", "New Relic"}, // %= is used for "contains" logic
},
},
Runtime: &SyntheticsExtendedTypeMonitorRuntimeInput{
RuntimeType: "INVALID_RUNTIME",
RuntimeTypeVersion: "INVALID_RUNTIME",
},
}

_, err = a.SyntheticsCreateStepMonitor(testAccountID, monitorInput)
require.Error(t, err)
require.ErrorContains(t, err, "Runtime values are invalid combination.")
}

func getSampleScriptedBrowserMonitorInput(name string) SyntheticsCreateScriptBrowserMonitorInput {
return SyntheticsCreateScriptBrowserMonitorInput{
Locations: SyntheticsScriptedMonitorLocationsInput{
Expand Down
34 changes: 34 additions & 0 deletions pkg/synthetics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ type SyntheticsBrokenLinksMonitor struct {
Name string `json:"name,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs
Runtime SyntheticsExtendedTypeMonitorRuntime `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
// The uri the monitor runs against
Expand Down Expand Up @@ -847,6 +849,8 @@ type SyntheticsCertCheckMonitor struct {
NumberDaysToFailBeforeCertExpires int `json:"numberDaysToFailBeforeCertExpires,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs
Runtime SyntheticsExtendedTypeMonitorRuntime `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
}
Expand Down Expand Up @@ -877,6 +881,8 @@ type SyntheticsCreateBrokenLinksMonitorInput struct {
Name string `json:"name"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: NODE_API & runtimeTypeVersion: 16.10
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status"`
// The tags that will be associated with the monitor
Expand All @@ -899,6 +905,8 @@ type SyntheticsCreateCertCheckMonitorInput struct {
NumberDaysToFailBeforeCertExpires int `json:"numberDaysToFailBeforeCertExpires"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: NODE_API & runtimeTypeVersion: 16.10
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status"`
// The tags that will be associated with the monitor
Expand Down Expand Up @@ -1001,6 +1009,8 @@ type SyntheticsCreateStepMonitorInput struct {
Name string `json:"name"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: CHROME_BROWSER & runtimeTypeVersion: 100
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status"`
// The steps that make up the script the monitor will run
Expand Down Expand Up @@ -1099,6 +1109,22 @@ type SyntheticsError struct {
Description string `json:"description,omitempty"`
}

// SyntheticsExtendedTypeMonitorRuntime - The runtime that a step monitor runs
type SyntheticsExtendedTypeMonitorRuntime struct {
// The runtime type that the monitor will run
RuntimeType string `json:"runtimeType,omitempty"`
// The specific version of the runtime type selected
RuntimeTypeVersion SemVer `json:"runtimeTypeVersion,omitempty"`
}

// SyntheticsExtendedTypeMonitorRuntimeInput - Input to determine which runtime the step monitor will run
type SyntheticsExtendedTypeMonitorRuntimeInput struct {
// The runtime type that the monitor will run.
RuntimeType string `json:"runtimeType"`
// The specific version of the runtime type selected.
RuntimeTypeVersion SemVer `json:"runtimeTypeVersion"`
}

// SyntheticsLocations - The location(s) from which the monitor runs
type SyntheticsLocations struct {
// Existing private location(s) in which the monitor will run
Expand Down Expand Up @@ -1667,6 +1693,8 @@ type SyntheticsStepMonitor struct {
Name string `json:"name,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs
Runtime SyntheticsExtendedTypeMonitorRuntime `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
// The steps that make up the script the monitor will run
Expand Down Expand Up @@ -1719,6 +1747,8 @@ type SyntheticsUpdateBrokenLinksMonitorInput struct {
Name string `json:"name,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: NODE_API & runtimeTypeVersion: 16.10
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
// The tags that will be associated with the monitor
Expand All @@ -1741,6 +1771,8 @@ type SyntheticsUpdateCertCheckMonitorInput struct {
NumberDaysToFailBeforeCertExpires int `json:"numberDaysToFailBeforeCertExpires,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: NODE_API & runtimeTypeVersion: 16.10
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
// The tags that will be associated with the monitor
Expand Down Expand Up @@ -1843,6 +1875,8 @@ type SyntheticsUpdateStepMonitorInput struct {
Name string `json:"name,omitempty"`
// The interval at which the monitor runs in minutes
Period SyntheticsMonitorPeriod `json:"period,omitempty"`
// The runtime that the monitor will use to run jobs. The only accepted values are runtimeType: CHROME_BROWSER & runtimeTypeVersion: 100
Runtime *SyntheticsExtendedTypeMonitorRuntimeInput `json:"runtime,omitempty"`
// The run state of the monitor
Status SyntheticsMonitorStatus `json:"status,omitempty"`
// The steps that make up the script the monitor will run
Expand Down
Loading