diff --git a/.tutone.yml b/.tutone.yml index f5cc4baf4..31549396c 100644 --- a/.tutone.yml +++ b/.tutone.yml @@ -1676,9 +1676,9 @@ packages: field_type_override: "*nrtime.EpochMilliseconds" skip_type_create: true - - name: apm - path: pkg/apm - import_path: github.com/newrelic/newrelic-client-go/v2/pkg/apm + - name: applicationSettings + path: pkg/applicationSettings + import_path: github.com/newrelic/newrelic-client-go/v2/pkg/applicationSettings generators: - typegen - nerdgraphclient diff --git a/pkg/apm/applications.go b/pkg/apm/applications.go index 65d905575..658e9bdb3 100644 --- a/pkg/apm/applications.go +++ b/pkg/apm/applications.go @@ -15,7 +15,6 @@ type ApplicationsInterface interface { // Application represents information about a New Relic application. type Application struct { - GUID EntityGUID `json:"guid,omitempty"` ID int `json:"id,omitempty"` Name string `json:"name,omitempty"` Language string `json:"language,omitempty"` @@ -76,8 +75,8 @@ type ListApplicationsParams struct { // UpdateApplicationParams represents a set of parameters to be // used when updating New Relic applications. type UpdateApplicationParams struct { - Name string `json:"name,omitempty"` - Settings ApplicationSettings `json:"settings,omitempty"` + Name string + Settings ApplicationSettings } // ListApplications is used to retrieve New Relic applications. diff --git a/pkg/apm/applications_test.go b/pkg/apm/applications_test.go index f0cae33a5..4a12f528c 100644 --- a/pkg/apm/applications_test.go +++ b/pkg/apm/applications_test.go @@ -38,6 +38,7 @@ var ( EnableRealUserMonitoring: true, UseServerSideConfig: false, } + testApplicationLinks = ApplicationLinks{ ServerIDs: []int{}, HostIDs: []int{204260579}, diff --git a/pkg/applicationSettings/applicationSettings.go b/pkg/applicationSettings/applicationSettings.go new file mode 100644 index 000000000..14c4db4ee --- /dev/null +++ b/pkg/applicationSettings/applicationSettings.go @@ -0,0 +1,46 @@ +package applicationsettings + +import ( + "github.com/newrelic/newrelic-client-go/v2/internal/http" + "github.com/newrelic/newrelic-client-go/v2/pkg/config" + "github.com/newrelic/newrelic-client-go/v2/pkg/entities" + "github.com/newrelic/newrelic-client-go/v2/pkg/logging" + mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" + "testing" +) + +type ApplicationSettings struct { + client http.Client + logger logging.Logger + config config.Config +} + +func New(config config.Config) ApplicationSettings { + client := http.NewClient(config) + pkg := ApplicationSettings{ + client: client, + logger: config.GetLogger(), + config: config, + } + return pkg +} + +func newIntegrationTestClient(t *testing.T) ApplicationSettings { + tc := mock.NewIntegrationTestConfig(t) + return New(tc) +} + +func newMockResponseApm(t *testing.T, mockJSONResponse string, statusCode int) ApplicationSettings { + ts := mock.NewMockServer(t, mockJSONResponse, statusCode) + tc := mock.NewTestConfig(t, ts) + + return New(tc) +} + +// nolint +func newMockResponse(t *testing.T, mockJSONResponse string, statusCode int) entities.Entities { + ts := mock.NewMockServer(t, mockJSONResponse, statusCode) + tc := mock.NewTestConfig(t, ts) + + return entities.New(tc) +} diff --git a/pkg/apm/apm_api.go b/pkg/applicationSettings/applicationSettings_api.go similarity index 95% rename from pkg/apm/apm_api.go rename to pkg/applicationSettings/applicationSettings_api.go index 0aa1b74a4..7bf2c0aa8 100644 --- a/pkg/apm/apm_api.go +++ b/pkg/applicationSettings/applicationSettings_api.go @@ -1,12 +1,10 @@ // Code generated by tutone: DO NOT EDIT -package apm +package applicationsettings -import ( - "context" -) +import "context" // Update configuration for APM applications. Includes thresholds for how often to record Transaction traces, SQL traces, enabling Distributed traces, ignoring certain error classes. This is the main mutation that powers the Application > Settings page in APM. -func (a *APM) AgentApplicationSettingsUpdate( +func (a *ApplicationSettings) AgentApplicationSettingsUpdate( gUID EntityGUID, settings AgentApplicationSettingsUpdateInput, ) (*AgentApplicationSettingsUpdateResult, error) { @@ -17,7 +15,7 @@ func (a *APM) AgentApplicationSettingsUpdate( } // Update configuration for APM applications. Includes thresholds for how often to record Transaction traces, SQL traces, enabling Distributed traces, ignoring certain error classes. This is the main mutation that powers the Application > Settings page in APM. -func (a *APM) AgentApplicationSettingsUpdateWithContext( +func (a *ApplicationSettings) AgentApplicationSettingsUpdateWithContext( ctx context.Context, gUID EntityGUID, settings AgentApplicationSettingsUpdateInput, diff --git a/pkg/applicationSettings/applicationSettings_integration_test.go b/pkg/applicationSettings/applicationSettings_integration_test.go new file mode 100644 index 000000000..5bac59193 --- /dev/null +++ b/pkg/applicationSettings/applicationSettings_integration_test.go @@ -0,0 +1,65 @@ +//go:build integration +// +build integration + +package applicationsettings + +import ( + "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" + "github.com/stretchr/testify/require" + "testing" +) + +func TestIntegrationAgentApplicationSettings_All(t *testing.T) { + t.Parallel() + client := newIntegrationTestClient(t) + + aliasName := testhelpers.IntegrationTestApplicationEntityNameNew + // updating an existing application setting + // this is expected to throw no error, and successfully updating application setting + applicationSettingTestResult, err := client.AgentApplicationSettingsUpdate( + testhelpers.IntegrationTestApplicationEntityGUIDNew, + AgentApplicationSettingsUpdateInput{ + Alias: &aliasName, + }, + ) + + require.NoError(t, err) + require.NotNil(t, applicationSettingTestResult) + require.Equal(t, aliasName, applicationSettingTestResult.Alias) + + // updating an existing application setting + // this is expected to throw no error, and successfully updating application setting + applicationSettingTestResult, err = client.AgentApplicationSettingsUpdate( + testhelpers.IntegrationTestApplicationEntityGUIDNew, + AgentApplicationSettingsUpdateInput{ + ApmConfig: &AgentApplicationSettingsApmConfigInput{ + ApdexTarget: 0.5, + }, + }, + ) + + require.NoError(t, err) + require.NotNil(t, applicationSettingTestResult) + require.Equal(t, aliasName, applicationSettingTestResult.Alias) + require.Equal(t, applicationSettingTestResult.ApmSettings.ApmConfig.ApdexTarget, 0.5) + +} + +func TestIntegrationAgentApplicationSettingsError(t *testing.T) { + t.Parallel() + client := newIntegrationTestClient(t) + + TransactionValue := 0.5 + // updating an existing application setting + // this is expected to throw no error, and successfully updating application setting + _, err := client.AgentApplicationSettingsUpdate( + testhelpers.IntegrationTestApplicationEntityGUIDNew, + AgentApplicationSettingsUpdateInput{ + TransactionTracer: &AgentApplicationSettingsTransactionTracerInput{ + TransactionThresholdValue: &TransactionValue, + }, + }, + ) + + require.Error(t, err) +} diff --git a/pkg/applicationSettings/applicationSettings_test.go b/pkg/applicationSettings/applicationSettings_test.go new file mode 100644 index 000000000..630c0f2b9 --- /dev/null +++ b/pkg/applicationSettings/applicationSettings_test.go @@ -0,0 +1,96 @@ +//go:build unit +// +build unit + +package applicationsettings + +import ( + "fmt" + mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +var ( + testApplicationSettings = AgentApplicationSettingsUpdateInput{ + Alias: func(s string) *string { return &s }("tf_test_updated"), + ApmConfig: &AgentApplicationSettingsApmConfigInput{ + ApdexTarget: 0, + UseServerSideConfig: func(b bool) *bool { return &b }(false), + }, + ThreadProfiler: &AgentApplicationSettingsThreadProfilerInput{ + Enabled: func(b bool) *bool { return &b }(false), + }, + ErrorCollector: &AgentApplicationSettingsErrorCollectorInput{ + Enabled: func(b bool) *bool { return &b }(false), + ExpectedErrorCodes: nil, + ExpectedErrorClasses: nil, + IgnoredErrorCodes: nil, + IgnoredErrorClasses: nil, + }, + TransactionTracer: &AgentApplicationSettingsTransactionTracerInput{ + Enabled: func(b bool) *bool { return &b }(false), + TransactionThresholdValue: func(f float64) *float64 { return &f }(0), + TransactionThresholdType: "", + RecordSql: "", + LogSql: func(b bool) *bool { return &b }(false), + StackTraceThreshold: func(f float64) *float64 { return &f }(0), + ExplainEnabled: func(b bool) *bool { return &b }(false), + ExplainThresholdValue: func(f float64) *float64 { return &f }(0), + ExplainThresholdType: "", + }, + TracerType: &AgentApplicationSettingsTracerTypeInput{"NONE"}, + } + + testApplicationJson = `{ + "apmSettings": { + "Alias": "tf_test_updated", + "ApmConfig": { + "ApdexTarget": 0, + "UseServerSideConfig": false + }, + "ThreadProfilerEnabled": false, + "ErrorCollector": { + "Enabled": false, + "ExpectedErrorCodes": [], + "ExpectedErrorClasses": [], + "IgnoredErrorCodes": [], + "IgnoredErrorClasses": [] + }, + "TransactionTracing": { + "Enabled": false, + "TransactionThresholdValue": 0, + "TransactionThresholdType": "off", + "RecordSql": "off", + "LogSql": false, + "StackTraceThresholdValue": 0, + "ExplainQueryPlanEnabled": false, + "ExplainQueryPlanThresholdValue": 0, + "ExplainQueryPlanThresholdType": "off" + }, + "TracerType": "NONE" + } + }` +) + +func TestGetApmApplicationDetails(t *testing.T) { + t.Parallel() + responseJSON := fmt.Sprintf(`{"application": %s}`, testApplicationJson) + client := newMockResponse(t, responseJSON, http.StatusOK) + + actual, err := client.GetEntity(mock.IntegrationTestApplicationEntityGUIDNew) + + assert.NoError(t, err) + assert.NotNil(t, actual) +} + +func TestUpdateApmApplicationDetails(t *testing.T) { + t.Parallel() + responseJSON := fmt.Sprintf(`{ "application": %s}`, testApplicationJson) + client := newMockResponseApm(t, responseJSON, http.StatusOK) + + actual, err := client.AgentApplicationSettingsUpdate(mock.IntegrationTestApplicationEntityGUIDNew, testApplicationSettings) + + assert.NoError(t, err) + assert.NotNil(t, actual) +} diff --git a/pkg/apm/types.go b/pkg/applicationSettings/types.go similarity index 99% rename from pkg/apm/types.go rename to pkg/applicationSettings/types.go index 63cb3ce5b..aa72a0c21 100644 --- a/pkg/apm/types.go +++ b/pkg/applicationSettings/types.go @@ -1,5 +1,7 @@ // Code generated by tutone: DO NOT EDIT -package apm +// NOTE: This file has been generated by Tutone and had to be manually edited for some structs to meet specific requirements. +// These changes should not be overridden by future Tutone generations. +package applicationsettings // AgentApplicationSettingsBrowserLoader - Determines which browser loader will be configured. Some allowed return values are specified for backwards-compatibility and do not represent currently allowed values for new applications. // See [documentation](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/#agent-types) for further information.