diff --git a/.tutone.yml b/.tutone.yml index 6d0fde6ce..406da24a7 100644 --- a/.tutone.yml +++ b/.tutone.yml @@ -171,6 +171,8 @@ packages: max_query_field_depth: 1 - name: "steps" max_query_field_depth: 1 + - name: "automatedTestResult" + max_query_field_depth: 6 mutations: - name: syntheticsCreateSecureCredential max_query_field_depth: 2 @@ -216,6 +218,8 @@ packages: max_query_field_depth: 2 - name: syntheticsPurgePrivateLocationQueue max_query_field_depth: 2 + - name: syntheticsStartAutomatedTest + max_query-field_depth: 4 types: - name: EpochMilliseconds field_type_override: "*nrtime.EpochMilliseconds" diff --git a/pkg/synthetics/synthetics_api.go b/pkg/synthetics/synthetics_api.go index 227d9ca1c..bb71e0509 100644 --- a/pkg/synthetics/synthetics_api.go +++ b/pkg/synthetics/synthetics_api.go @@ -785,6 +785,51 @@ const SyntheticsPurgePrivateLocationQueueMutation = `mutation( } } }` +// Starts automated testing job +func (a *Synthetics) SyntheticsStartAutomatedTest( + config SyntheticsAutomatedTestConfigInput, + tests []SyntheticsAutomatedTestMonitorInput, +) (*SyntheticsAutomatedTestStartResult, error) { + return a.SyntheticsStartAutomatedTestWithContext(context.Background(), + config, + tests, + ) +} + +// Starts automated testing job +func (a *Synthetics) SyntheticsStartAutomatedTestWithContext( + ctx context.Context, + config SyntheticsAutomatedTestConfigInput, + tests []SyntheticsAutomatedTestMonitorInput, +) (*SyntheticsAutomatedTestStartResult, error) { + + resp := SyntheticsStartAutomatedTestQueryResponse{} + vars := map[string]interface{}{ + "config": config, + "tests": tests, + } + + if err := a.client.NerdGraphQueryWithContext(ctx, SyntheticsStartAutomatedTestMutation, vars, &resp); err != nil { + return nil, err + } + + return &resp.SyntheticsAutomatedTestStartResult, nil +} + +type SyntheticsStartAutomatedTestQueryResponse struct { + SyntheticsAutomatedTestStartResult SyntheticsAutomatedTestStartResult `json:"SyntheticsStartAutomatedTest"` +} + +const SyntheticsStartAutomatedTestMutation = `mutation( + $config: SyntheticsAutomatedTestConfigInput, + $tests: [SyntheticsAutomatedTestMonitorInput], +) { syntheticsStartAutomatedTest( + config: $config, + tests: $tests, +) { + batchId +} }` + // Update a Synthetic Broken Links monitor func (a *Synthetics) SyntheticsUpdateBrokenLinksMonitor( gUID EntityGUID, @@ -1379,6 +1424,84 @@ const SyntheticsUpdateStepMonitorMutation = `mutation( } } }` +// Query that fetches results for an automated test +func (a *Synthetics) GetAutomatedTestResult( + accountID int, + batchId string, +) (*SyntheticsAutomatedTestResult, error) { + return a.GetAutomatedTestResultWithContext(context.Background(), + accountID, + batchId, + ) +} + +// Query that fetches results for an automated test +func (a *Synthetics) GetAutomatedTestResultWithContext( + ctx context.Context, + accountID int, + batchId string, +) (*SyntheticsAutomatedTestResult, error) { + + resp := automatedTestResultResponse{} + vars := map[string]interface{}{ + "accountID": accountID, + "batchId": batchId, + } + + if err := a.client.NerdGraphQueryWithContext(ctx, getAutomatedTestResultQuery, vars, &resp); err != nil { + return nil, err + } + + return &resp.Actor.Account.Synthetics.AutomatedTestResult, nil +} + +const getAutomatedTestResultQuery = `query( + $accountID: Int!, + $batchId: String!, +) { actor { account(id: $accountID) { synthetics { automatedTestResult( + batchId: $batchId, +) { + config { + batchName + branch + commit + deepLink + platform + repository + } + status + tests { + automatedTestMonitorConfig { + isBlocking + overrides { + domain { + domain + override + } + location + secureCredential { + key + overrideKey + } + startingUrl + } + } + batchId + duration + error + id + location + locationLabel + monitorGuid + monitorId + monitorName + result + resultsUrl + type + typeLabel + } +} } } } }` + // Query that fetches the script of a specific scripted monitor func (a *Synthetics) GetScript( accountID int, @@ -1419,7 +1542,7 @@ const getScriptQuery = `query( text } } } } }` -// Query that fetches the steps used by the specified Step Monitor +// visiblity(flag:Synthetics/setGraphqlCustomerVisible) Query that fetches the steps used by the specified Step Monitor func (a *Synthetics) GetSteps( accountID int, monitorGUID EntityGUID, @@ -1430,7 +1553,7 @@ func (a *Synthetics) GetSteps( ) } -// Query that fetches the steps used by the specified Step Monitor +// visiblity(flag:Synthetics/setGraphqlCustomerVisible) Query that fetches the steps used by the specified Step Monitor func (a *Synthetics) GetStepsWithContext( ctx context.Context, accountID int, diff --git a/pkg/synthetics/types.go b/pkg/synthetics/types.go index d04c2a756..4a30da66d 100644 --- a/pkg/synthetics/types.go +++ b/pkg/synthetics/types.go @@ -96,6 +96,29 @@ var Nr1CatalogInstallPlanTargetTypeTypes = struct { UNKNOWN: "UNKNOWN", } +// SyntheticsAutomatedTestStatus - Enum of automated test status +type SyntheticsAutomatedTestStatus string + +var SyntheticsAutomatedTestStatusTypes = struct { + // At least one blocking job in the automated test has failed + FAILED SyntheticsAutomatedTestStatus + // Indicates jobs in the automated test are still running + IN_PROGRESS SyntheticsAutomatedTestStatus + // All blocking jobs in the automated test has passed + PASSED SyntheticsAutomatedTestStatus + // Some jobs in the automated test failed to provide a status within the timeout + TIMEOUT SyntheticsAutomatedTestStatus +}{ + // At least one blocking job in the automated test has failed + FAILED: "FAILED", + // Indicates jobs in the automated test are still running + IN_PROGRESS: "IN_PROGRESS", + // All blocking jobs in the automated test has passed + PASSED: "PASSED", + // Some jobs in the automated test failed to provide a status within the timeout + TIMEOUT: "TIMEOUT", +} + // SyntheticsDeviceOrientation - enum of Orientations that the user can select for their emulated device type SyntheticsDeviceOrientation string @@ -134,6 +157,29 @@ var SyntheticsDeviceTypeTypes = struct { TABLET: "TABLET", } +// SyntheticsJobStatus - Enum of job status +type SyntheticsJobStatus string + +var SyntheticsJobStatusTypes = struct { + // Indicates the job has failed + FAILED SyntheticsJobStatus + // Indicates an in-progress job + PENDING SyntheticsJobStatus + // Indicates the job has succeeded + SUCCESS SyntheticsJobStatus + // Indicates the job status was lost or unknown + UNKNOWN SyntheticsJobStatus +}{ + // Indicates the job has failed + FAILED: "FAILED", + // Indicates an in-progress job + PENDING: "PENDING", + // Indicates the job has succeeded + SUCCESS: "SUCCESS", + // Indicates the job status was lost or unknown + UNKNOWN: "UNKNOWN", +} + // SyntheticsMonitorCreateErrorType - Types of errors that can be returned from a create monitor request type SyntheticsMonitorCreateErrorType string @@ -231,6 +277,41 @@ var SyntheticsMonitorStatusTypes = struct { MUTED: "MUTED", } +// SyntheticsMonitorType - Enum of monitor types +type SyntheticsMonitorType string + +var SyntheticsMonitorTypeTypes = struct { + // Broken links monitor + BROKEN_LINKS SyntheticsMonitorType + // Simple browser monitor + BROWSER SyntheticsMonitorType + // Certificate Check + CERT_CHECK SyntheticsMonitorType + // Script API monitor + SCRIPT_API SyntheticsMonitorType + // Script browser monitor + SCRIPT_BROWSER SyntheticsMonitorType + // Simple (ping) monitor + SIMPLE SyntheticsMonitorType + // Step Monitor + STEP_MONITOR SyntheticsMonitorType +}{ + // Broken links monitor + BROKEN_LINKS: "BROKEN_LINKS", + // Simple browser monitor + BROWSER: "BROWSER", + // Certificate Check + CERT_CHECK: "CERT_CHECK", + // Script API monitor + SCRIPT_API: "SCRIPT_API", + // Script browser monitor + SCRIPT_BROWSER: "SCRIPT_BROWSER", + // Simple (ping) monitor + SIMPLE: "SIMPLE", + // Step Monitor + STEP_MONITOR: "STEP_MONITOR", +} + // SyntheticsMonitorUpdateErrorType - Types of errors that can be returned from a Monitor mutation request type SyntheticsMonitorUpdateErrorType string @@ -350,9 +431,12 @@ var SyntheticsStepTypeTypes = struct { // Account configuration data is queried through this object, as well as // telemetry data that is specific to a single account. type Account struct { - ID int `json:"id,omitempty"` + // + ID int `json:"id,omitempty"` + // LicenseKey string `json:"licenseKey,omitempty"` - Name string `json:"name,omitempty"` + // + Name string `json:"name,omitempty"` // This field provides access to Synthetics data. Synthetics SyntheticsAccountStitchedFields `json:"synthetics,omitempty"` } @@ -502,12 +586,142 @@ func (x *Nr1CatalogTargetedInstallPlanDirective) ImplementsNr1CatalogInstallPlan // SyntheticsAccountStitchedFields - Nerdgraph account field type SyntheticsAccountStitchedFields struct { + // Query that fetches results for an automated test + AutomatedTestResult SyntheticsAutomatedTestResult `json:"automatedTestResult,omitempty"` // Query that fetches the script of a specific scripted monitor Script SyntheticsMonitorScriptQueryResponse `json:"script,omitempty"` // visiblity(flag:Synthetics/setGraphqlCustomerVisible) Query that fetches the steps used by the specified Step Monitor Steps []SyntheticsStep `json:"steps"` } +// SyntheticsAutomatedTestConfig - Global automated test config +type SyntheticsAutomatedTestConfig struct { + // An identifier for the automated test run + BatchName string `json:"batchName,omitempty"` + // Branch metadata to indicate what triggered the automated test + Branch string `json:"branch,omitempty"` + // Commit metadata to indicate what commit triggered the automated test + Commit string `json:"commit,omitempty"` + // Metadata for the automated test + DeepLink string `json:"deepLink,omitempty"` + // Metadata about the platform target the automated test will run against + Platform string `json:"platform,omitempty"` + // The unique client identifier for the Synthetics Monitor in New Relic + Repository string `json:"repository,omitempty"` +} + +// SyntheticsAutomatedTestConfigInput - Global automated test config +type SyntheticsAutomatedTestConfigInput struct { + // An identifier for the automated test run + BatchName string `json:"batchName,omitempty"` + // Branch metadata to indicate what triggered the automated test + Branch string `json:"branch,omitempty"` + // Commit metadata to indicate what commit triggered the automated test + Commit string `json:"commit,omitempty"` + // Metadata for the automated test + DeepLink string `json:"deepLink,omitempty"` + // Metadata about the platform target the automated test will run against + Platform string `json:"platform,omitempty"` + // The unique client identifier for the Synthetics Monitor in New Relic + Repository string `json:"repository,omitempty"` +} + +// SyntheticsAutomatedTestJobResult - Information on a job that was apart of a batch of automated test jobs +type SyntheticsAutomatedTestJobResult struct { + // Test overrides + AutomatedTestMonitorConfig SyntheticsAutomatedTestMonitorConfig `json:"automatedTestMonitorConfig,omitempty"` + // Job batch Id + BatchId string `json:"batchId,omitempty"` + // Job duration + Duration Milliseconds `json:"duration,omitempty"` + // Job error if any + Error string `json:"error,omitempty"` + // Job Id + ID string `json:"id,omitempty"` + // Job location + Location string `json:"location,omitempty"` + // Job location label + LocationLabel string `json:"locationLabel,omitempty"` + // Monitor nr1 entity guid + MonitorGUID EntityGUID `json:"monitorGuid,omitempty"` + // Job monitor Id + MonitorId string `json:"monitorId,omitempty"` + // Job monitor name + MonitorName string `json:"monitorName,omitempty"` + // Job result + Result SyntheticsJobStatus `json:"result,omitempty"` + // Link to job results + ResultsURL string `json:"resultsUrl,omitempty"` + // Job type + Type SyntheticsMonitorType `json:"type,omitempty"` + // Job type label + TypeLabel string `json:"typeLabel,omitempty"` +} + +// SyntheticsAutomatedTestMonitorConfig - Monitor specific test config +type SyntheticsAutomatedTestMonitorConfig struct { + // Specifies whether a failure of this monitor should fail the entire automated test + IsBlocking bool `json:"isBlocking,omitempty"` + // Specific overrides for the given monitor + Overrides SyntheticsAutomatedTestOverrides `json:"overrides,omitempty"` +} + +// SyntheticsAutomatedTestMonitorConfigInput - Monitor specific test configuration +type SyntheticsAutomatedTestMonitorConfigInput struct { + // Specifies whether a failure of this monitor should fail the entire automated test +bool `json:"isBlocking,omitempty"` + // Specific overrides for the given monitor + Overrides SyntheticsAutomatedTestOverridesInput `json:"overrides,omitempty"` +} + +// SyntheticsAutomatedTestMonitorInput - Monitor test definition to be included in the automated test +type SyntheticsAutomatedTestMonitorInput struct { + // The monitor config for an automated test + Config SyntheticsAutomatedTestMonitorConfigInput `json:"config,omitempty"` + // The unique client identifier for the Synthetics Monitor in New Relic + MonitorGUID EntityGUID `json:"monitorGuid"` +} + +// SyntheticsAutomatedTestOverrides - Automated test monitor overrides +type SyntheticsAutomatedTestOverrides struct { + // Override a domain throughout a scripted monitor + Domain []SyntheticsScriptDomainOverride `json:"domain,omitempty"` + // Override monitor to use a specific location + Location string `json:"location,omitempty"` + // Override a script secure credential with another credential value + SecureCredential []SyntheticsSecureCredentialOverride `json:"secureCredential,omitempty"` + // Override a browser monitor starting url + StartingURL string `json:"startingUrl,omitempty"` +} + +// SyntheticsAutomatedTestOverridesInput - Automated test monitor overrides +type SyntheticsAutomatedTestOverridesInput struct { + // Override a domain throughout a scripted monitor + Domain SyntheticsScriptDomainOverrideInput `json:"domain,omitempty"` + // Override monitor to use a specific location + Location string `json:"location,omitempty"` + // Override a script secure credential with another credential value + SecureCredential SyntheticsSecureCredentialOverrideInput `json:"secureCredential,omitempty"` + // Override a browser monitor starting url + StartingURL string `json:"startingUrl,omitempty"` +} + +// SyntheticsAutomatedTestResult - Results from fetching automated test job +type SyntheticsAutomatedTestResult struct { + // Automated test config + Config SyntheticsAutomatedTestConfig `json:"config,omitempty"` + // Calculated status of automated test as a whole + Status SyntheticsAutomatedTestStatus `json:"status,omitempty"` + // List of completed automated test jobs + Tests []SyntheticsAutomatedTestJobResult `json:"tests,omitempty"` +} + +// SyntheticsAutomatedTestStartResult - Results from starting automated test job +type SyntheticsAutomatedTestStartResult struct { + // Job batch Id + BatchId string `json:"batchId,omitempty"` +} + // SyntheticsBrokenLinksMonitor - A Broken Links monitor resulting from a Broken Links monitor mutation type SyntheticsBrokenLinksMonitor struct { // The creation time of the monitor in millis @@ -974,6 +1188,22 @@ type SyntheticsScriptBrowserMonitorUpdateMutationResult struct { Monitor SyntheticsScriptBrowserMonitor `json:"monitor,omitempty"` } +// SyntheticsScriptDomainOverride - Override a script url domain +type SyntheticsScriptDomainOverride struct { + // The target domain to override + Domain string `json:"domain,omitempty"` + // The override value for the domain + Override string `json:"override,omitempty"` +} + +// SyntheticsScriptDomainOverrideInput - Override a script url domain +type SyntheticsScriptDomainOverrideInput struct { + // The target domain to override + Domain string `json:"domain,omitempty"` + // The override value for the domain + Override string `json:"override,omitempty"` +} + // SyntheticsScriptedMonitorLocationsInput - The location(s) from which the scripted monitor runs. type SyntheticsScriptedMonitorLocationsInput struct { // The private location(s) that the monitor will run jobs from @@ -996,6 +1226,22 @@ type SyntheticsSecureCredentialMutationResult struct { LastUpdate *nrtime.EpochMilliseconds `json:"lastUpdate,omitempty"` } +// SyntheticsSecureCredentialOverride - Override a monitor scripts secure credential key with a different key +type SyntheticsSecureCredentialOverride struct { + // The target secure credential key to override + Key string `json:"key,omitempty"` + // The secure credential key override + OverrideKey string `json:"overrideKey,omitempty"` +} + +// SyntheticsSecureCredentialOverrideInput - Override a monitor scripts secure credential key with a different key +type SyntheticsSecureCredentialOverrideInput struct { + // The target secure credential key to override + Key string `json:"key,omitempty"` + // The secure credential key override + OverrideKey string `json:"overrideKey,omitempty"` +} + // SyntheticsSimpleBrowserMonitor - A Simple Browser monitor resulting from a Simple Browser monitor mutation type SyntheticsSimpleBrowserMonitor struct { // The monitor advanced options @@ -1348,6 +1594,10 @@ type SyntheticsUpdateStepMonitorInput struct { Tags []SyntheticsTag `json:"tags,omitempty"` } +type automatedTestResultResponse struct { + Actor Actor `json:"actor"` +} + type scriptResponse struct { Actor Actor `json:"actor"` } @@ -1364,6 +1614,9 @@ type EntityGUID string // [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754). type Float string +// Milliseconds - The `Milliseconds` scalar represents a duration in milliseconds +type Milliseconds string + // Nr1CatalogRawNerdletState - Represents JSON nerdlet state data type Nr1CatalogRawNerdletState string