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): adds support for multiple browsers and devices with synthetic monitors #2743

Merged
merged 24 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d3cbc61
feat(synthetics): multi browser, devices changes in couple of synthet…
shashank-reddy-nr Aug 8, 2024
bb702fa
feat(synthetic Browser Monitor): Add multi browser support for simple…
vagrawal-newrelic Aug 11, 2024
51c20ca
feat(synthetics): added integration test changes of multi browsers su…
shashank-reddy-nr Aug 13, 2024
baaec80
fix(synthetics): made changes to show drift if monitor config changes…
shashank-reddy-nr Aug 16, 2024
14fab73
fix(synthetics): fixed feat to see drift if user changes sometime in UI
shashank-reddy-nr Aug 19, 2024
cf76c2e
fix(synthetics): allow new -> legacy runtime downgrade until Oct 22 f…
pranav-new-relic Aug 30, 2024
186c53c
chore(synthetics): update code to revert setting empty strings in sim…
pranav-new-relic Aug 30, 2024
9c0d0a2
chore(synthetics): update code to revert setting empty strings in sim…
pranav-new-relic Aug 30, 2024
5da79d9
chore(synthetics): Merged EOL changes main into working branch
shashank-reddy-nr Sep 3, 2024
5801055
fix(synthetic monitor): Add logic to show drift in case of any UI cha…
vagrawal-newrelic Aug 16, 2024
5aec0eb
feat(Synthetics): Removing device_type and device_orientation from th…
vagrawal-newrelic Sep 4, 2024
819e473
fix(drift): fixed the drift issue with devices field
shashank-reddy-nr Sep 4, 2024
8cfbbc3
chore(synthetics): Computed method changes
shashank-reddy-nr Sep 6, 2024
803e1e7
chore(synthetics): merged facilitate-runtime-downgrade-simple-scripte…
shashank-reddy-nr Sep 6, 2024
774b7a6
chore(synthetics): diff supress method changes, still need to address…
shashank-reddy-nr Sep 7, 2024
436dda5
chore(synthetics): diffsupress solution final changes
shashank-reddy-nr Sep 9, 2024
87090d5
Revert "chore(synthetics): merged facilitate-runtime-downgrade-simple…
shashank-reddy-nr Sep 9, 2024
bab7afe
feat(synthetics): multibrowsers final set of changes with native appr…
shashank-reddy-nr Sep 10, 2024
d65f87d
chore(synthetics): reverted go.sum change
shashank-reddy-nr Sep 10, 2024
1316a16
fix(synthetics): compilation errors fix
shashank-reddy-nr Sep 10, 2024
d1c090f
chore(lint): lint issue fix
shashank-reddy-nr Sep 10, 2024
417555e
chore(synthetics): pointed client-go changes
shashank-reddy-nr Sep 10, 2024
0adf859
fix(tests): integration tests fixed
shashank-reddy-nr Sep 11, 2024
43237d5
Merge branch 'main' into NR-293404
shashank-reddy-nr Sep 11, 2024
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: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.30.0
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.44.0
github.com/newrelic/newrelic-client-go/v2 v2.45.0
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ github.com/newrelic/go-agent/v3 v3.30.0 h1:ZXHCT/Cot4iIPwcegCZURuRQOsfmGA6wilW+S
github.com/newrelic/go-agent/v3 v3.30.0/go.mod h1:9utrgxlSryNqRrTvII2XBL+0lpofXbqXApvVWPpbzUg=
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
github.com/newrelic/newrelic-client-go/v2 v2.44.0 h1:n4zP64Hfui8pjW/D3tbE1Hi+Acbpz8nBIrI2miEAGiI=
github.com/newrelic/newrelic-client-go/v2 v2.44.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4=
github.com/newrelic/newrelic-client-go/v2 v2.45.0 h1:3zaJqE4V2n07b8Fx3byV+WeJSdeTeR4sW6yVSXrrNN4=
github.com/newrelic/newrelic-client-go/v2 v2.45.0/go.mod h1:pDFY24/6iIMEbPIdowTRrRn9YYwkXc3j+B+XpTb4oF4=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
36 changes: 36 additions & 0 deletions newrelic/resource_helpers_synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ var SyntheticsUseLegacyRuntimeSchema = &schema.Schema{
DiffSuppressFunc: syntheticMonitorsUseUnsupportedLegacyRuntimeDiffSuppressor,
}

var browsersSchema = &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1,
Optional: true,
Description: "The multiple browsers list on which synthetic monitors will run. Valid values are array of CHROME," +
"and FIREFOX",
}
var devicesSchema = &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1,
Optional: true,
Description: "The multiple devices list on which synthetic monitors will run. Valid values are array of DESKTOP," +
" MOBILE_LANDSCAPE, MOBILE_PORTRAIT, TABLET_LANDSCAPE and TABLET_PORTRAIT",
}

var syntheticsMonitorPeriodValueMap = map[int]synthetics.SyntheticsMonitorPeriod{
1: synthetics.SyntheticsMonitorPeriodTypes.EVERY_MINUTE,
5: synthetics.SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES,
Expand Down Expand Up @@ -256,6 +273,25 @@ func expandSyntheticsPublicLocations(locations []interface{}) []string {
return locationsOut
}

func expandSyntheticsBrowsers(browsers []interface{}) []synthetics.SyntheticsBrowser {
browsersOut := make([]synthetics.SyntheticsBrowser, len(browsers))

for i, v := range browsers {
browsersOut[i] = synthetics.SyntheticsBrowser(v.(string))

}
return browsersOut
}

func expandSyntheticsDevices(devices []interface{}) []synthetics.SyntheticsDevice {
devicesOut := make([]synthetics.SyntheticsDevice, len(devices))

for i, v := range devices {
devicesOut[i] = synthetics.SyntheticsDevice(v.(string))
}
return devicesOut
}

func expandSyntheticsPrivateLocations(locations []interface{}) []synthetics.SyntheticsPrivateLocationInput {
locationsOut := make([]synthetics.SyntheticsPrivateLocationInput, len(locations))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func resourceNewRelicSyntheticsBrokenLinksMonitor() *schema.Resource {
syntheticsMonitorLocationsAsStringsSchema(),
syntheticsMonitorRuntimeOptions(),
),
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
CustomizeDiff: validateSyntheticMonitorAttributes,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func resourceNewRelicSyntheticsCertCheckMonitor() *schema.Resource {
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
},
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
CustomizeDiff: validateSyntheticMonitorAttributes,
}
}

Expand Down
18 changes: 11 additions & 7 deletions newrelic/resource_newrelic_synthetics_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource {
Description: "Capture a screenshot during job execution",
Optional: true,
},
"browsers": browsersSchema,
"devices": devicesSchema,
"custom_header": {
Type: schema.TypeSet,
Description: "Custom headers to use in monitor job",
Expand All @@ -166,17 +168,19 @@ func resourceNewRelicSyntheticsMonitor() *schema.Resource {
},
},
"device_orientation": {
Type: schema.TypeString,
Optional: true,
Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.",
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"device_type"},
Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.",
},
"device_type": {
Type: schema.TypeString,
Optional: true,
Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.",
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"device_orientation"},
Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.",
},
},
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
CustomizeDiff: validateSyntheticMonitorAttributes,
}
}

Expand Down
23 changes: 16 additions & 7 deletions newrelic/resource_newrelic_synthetics_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationError(t *testing.T)
// Test: Create
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)),
ExpectError: regexp.MustCompile(`both device_orientation and device_type should be specified to enable device emulation`),
ExpectError: regexp.MustCompile("all of `device_orientation,device_type` must be\nspecified"),
Copy link
Member

Choose a reason for hiding this comment

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

is the \n intended 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this is intended, due to the error message format is quite weird as shown below
Screenshot 2024-09-11 at 11 16 00 AM

},
},
})
Expand All @@ -51,10 +51,17 @@ func TestAccNewRelicSyntheticsBrowserMonitor_DeviceEmulationErrorUpdate(t *testi
testAccCheckNewRelicSyntheticsMonitorExists(resourceName),
),
},
// Test: Update
// Test: Update ; By removing device_type field
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulationError(rName, string(SyntheticsMonitorTypes.BROWSER)),
ExpectError: regexp.MustCompile(`both device_orientation and device_type should be specified to enable device emulation`),
ExpectError: regexp.MustCompile("all of `device_orientation,device_type` must be\nspecified"),
},
// Test: Update ; Added back removed device_type field
{
Config: testAccNewRelicSyntheticsBrowserMonitorConfig_DeviceEmulation(rName, string(SyntheticsMonitorTypes.BROWSER)),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsMonitorExists(resourceName),
),
},
},
})
Expand Down Expand Up @@ -288,6 +295,8 @@ func TestAccNewRelicSyntheticsSimpleBrowserMonitor(t *testing.T) {
"device_orientation",
"device_type",
SyntheticsUseLegacyRuntimeAttrLabel,
"browsers",
"devices",
},
},
},
Expand All @@ -305,6 +314,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp
name = "customer-header-2"
value = "header-value-2"
}
browsers = ["CHROME", "FIREFOX"]
devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"]
enable_screenshot_on_failure_and_script = true
validation_string = "success"
verify_ssl = true
Expand All @@ -317,8 +328,6 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfig(name string, monitorTyp
status = "ENABLED"
type = "%s"
uri = "https://www.one.newrelic.com"
device_orientation = "PORTRAIT"
device_type = "MOBILE"
}`, name, monitorType)
}

Expand All @@ -329,6 +338,8 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon
name = "name"
value = "simple_browser"
}
browsers = ["CHROME"]
devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE"]
enable_screenshot_on_failure_and_script = false
validation_string = "success"
verify_ssl = false
Expand All @@ -341,8 +352,6 @@ func testAccNewRelicSyntheticsSimpleBrowserMonitorConfigUpdated(name string, mon
status = "DISABLED"
type = "%s"
uri = "https://www.one.newrelic.com"
device_orientation = "LANDSCAPE"
device_type = "TABLET"
}`, name, monitorType)
}

Expand Down
28 changes: 15 additions & 13 deletions newrelic/resource_newrelic_synthetics_script_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package newrelic

import (
"context"
"log"

"github.com/newrelic/newrelic-client-go/v2/pkg/common"
"github.com/newrelic/newrelic-client-go/v2/pkg/entities"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/newrelic/newrelic-client-go/v2/pkg/common"
"github.com/newrelic/newrelic-client-go/v2/pkg/entities"
"github.com/newrelic/newrelic-client-go/v2/pkg/synthetics"
"log"
)

func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource {
Expand All @@ -28,7 +26,7 @@ func resourceNewRelicSyntheticsScriptMonitor() *schema.Resource {
syntheticsScriptMonitorLocationsSchema(),
syntheticsScriptBrowserMonitorAdvancedOptionsSchema(),
),
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
CustomizeDiff: validateSyntheticMonitorAttributes,
}
}

Expand Down Expand Up @@ -66,23 +64,27 @@ func syntheticsScriptMonitorLocationsSchema() map[string]*schema.Schema {
}
}

// Scripted browser monitors have advanced options, but scripted API monitors do not.
// Scripted browser monitors have advanced options, browsers and devices fields, but scripted API monitors do not.
func syntheticsScriptBrowserMonitorAdvancedOptionsSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"enable_screenshot_on_failure_and_script": {
Type: schema.TypeBool,
Optional: true,
Description: "Capture a screenshot during job execution.",
},
"browsers": browsersSchema,
"devices": devicesSchema,
"device_orientation": {
Type: schema.TypeString,
Optional: true,
Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.",
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"device_type"},
Description: "The device orientation the user would like to represent. Valid values are LANDSCAPE, PORTRAIT, or NONE.",
},
"device_type": {
Type: schema.TypeString,
Optional: true,
Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.",
Type: schema.TypeString,
Optional: true,
RequiredWith: []string{"device_orientation"},
Description: "The device type that a user can select. Valid values are MOBILE, TABLET, or NONE.",
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func TestAccNewRelicSyntheticsScriptBrowserMonitor(t *testing.T) {
"device_orientation",
"device_type",
SyntheticsUseLegacyRuntimeAttrLabel,
"browsers",
"devices",
},
},
},
Expand All @@ -120,24 +122,6 @@ func testAccNewRelicSyntheticsScriptAPIMonitorConfig(name string, scriptMonitorT
}`, name, scriptMonitorType)
}

func testAccNewRelicSyntheticsScriptMonitorConfig(name string) string {
return fmt.Sprintf(`
resource "newrelic_synthetics_script_monitor" "foo" {
locations_public = [
"EU_WEST_1",
"EU_WEST_2",
]
name = "%s"
period = "EVERY_DAY"
script = "console.log('script update works!')"
status = "ENABLED"
type = "SCRIPT_BROWSER"
script_language = "JAVASCRIPT"
runtime_type = "`+SyntheticsChromeBrowserRuntimeType+`"
runtime_type_version = "`+SyntheticsChromeBrowserNewRuntimeTypeVersion+`"
}`, name)
}

func testAccNewRelicSyntheticsScriptBrowserMonitorConfig(name string) string {
return fmt.Sprintf(`
resource "newrelic_synthetics_script_monitor" "bar" {
Expand All @@ -153,9 +137,8 @@ func testAccNewRelicSyntheticsScriptBrowserMonitorConfig(name string) string {
script_language = "JAVASCRIPT"
script = "$browser.get('https://one.newrelic.com')"

device_orientation = "PORTRAIT"
device_type = "MOBILE"

browsers = ["CHROME", "FIREFOX"]
devices = ["DESKTOP", "TABLET_LANDSCAPE", "MOBILE_PORTRAIT", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"]
tag {
key = "Name"
values = ["scriptedMonitor"]
Expand Down Expand Up @@ -232,23 +215,3 @@ func testAccCheckNewRelicSyntheticsScriptMonitorDestroy(s *terraform.State) erro
}
return nil
}

func TestAccNewRelicSyntheticsMonitorScriptUpdate(t *testing.T) {
resourceName := "newrelic_synthetics_script_monitor.foo"
rName := generateNameForIntegrationTestResource()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNewRelicSyntheticsScriptMonitorDestroy,
Steps: []resource.TestStep{

{
Config: testAccNewRelicSyntheticsScriptMonitorConfig(fmt.Sprintf(rName)),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicSyntheticsMonitorScriptUpdate(resourceName),
),
},
},
})
}
4 changes: 3 additions & 1 deletion newrelic/resource_newrelic_synthetics_step_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func resourceNewRelicSyntheticsStepMonitor() *schema.Resource {
syntheticsMonitorCommonSchema(),
syntheticsStepMonitorSchema(),
),
CustomizeDiff: validateSyntheticMonitorRuntimeAttributes,
CustomizeDiff: validateSyntheticMonitorAttributes,
}
}

Expand Down Expand Up @@ -103,6 +103,8 @@ func syntheticsStepMonitorSchema() map[string]*schema.Schema {
Description: "The specific semver version of the runtime type.",
},
SyntheticsUseLegacyRuntimeAttrLabel: SyntheticsUseLegacyRuntimeSchema,
"browsers": browsersSchema,
"devices": devicesSchema,
}
}

Expand Down
6 changes: 5 additions & 1 deletion newrelic/resource_newrelic_synthetics_step_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func TestAccNewRelicSyntheticsStepMonitor(t *testing.T) {
"tag",
"enable_screenshot_on_failure_and_script",
SyntheticsUseLegacyRuntimeAttrLabel,
"browsers",
"devices",
},
},
},
Expand All @@ -83,7 +85,9 @@ resource "newrelic_synthetics_step_monitor" "foo" {
type = "NAVIGATE"
values = ["https://google.com"]
}

browsers = ["CHROME", "FIREFOX"]
devices = ["DESKTOP","MOBILE_PORTRAIT", "TABLET_LANDSCAPE", "MOBILE_LANDSCAPE", "TABLET_PORTRAIT"]

%[2]s
}
`,
Expand Down
Loading
Loading