github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/applications.go (about)

     1  package apm
     2  
     3  import "context"
     4  
     5  // ApplicationsInterface interface should be refactored to be a global interface for fetching NR type things
     6  type ApplicationsInterface interface {
     7  	find(accountID int, name string) (*Application, error)
     8  	list(accountID int, params *ListApplicationsParams) ([]*Application, error)
     9  
    10  	create(accountID int, name string) (*Application, error)
    11  	get(accountID int, applicationID int) (*Application, error)
    12  	update(accountID int, applicationID int, params UpdateApplicationParams) (*Application, error)
    13  	remove(accountID int, applicationID int) (*Application, error) // delete is a reserved word...
    14  }
    15  
    16  // Application represents information about a New Relic application.
    17  type Application struct {
    18  	ID             int                       `json:"id,omitempty"`
    19  	Name           string                    `json:"name,omitempty"`
    20  	Language       string                    `json:"language,omitempty"`
    21  	HealthStatus   string                    `json:"health_status,omitempty"`
    22  	Reporting      bool                      `json:"reporting"`
    23  	LastReportedAt string                    `json:"last_reported_at,omitempty"`
    24  	Summary        ApplicationSummary        `json:"application_summary,omitempty"`
    25  	EndUserSummary ApplicationEndUserSummary `json:"end_user_summary,omitempty"`
    26  	Settings       ApplicationSettings       `json:"settings,omitempty"`
    27  	Links          ApplicationLinks          `json:"links,omitempty"`
    28  }
    29  
    30  // ApplicationSummary represents performance information about a New Relic application.
    31  type ApplicationSummary struct {
    32  	ResponseTime            float64 `json:"response_time"`
    33  	Throughput              float64 `json:"throughput"`
    34  	ErrorRate               float64 `json:"error_rate"`
    35  	ApdexTarget             float64 `json:"apdex_target"`
    36  	ApdexScore              float64 `json:"apdex_score"`
    37  	HostCount               int     `json:"host_count"`
    38  	InstanceCount           int     `json:"instance_count"`
    39  	ConcurrentInstanceCount int     `json:"concurrent_instance_count"`
    40  }
    41  
    42  // ApplicationEndUserSummary represents performance information about a New Relic application.
    43  type ApplicationEndUserSummary struct {
    44  	ResponseTime float64 `json:"response_time"`
    45  	Throughput   float64 `json:"throughput"`
    46  	ApdexTarget  float64 `json:"apdex_target"`
    47  	ApdexScore   float64 `json:"apdex_score"`
    48  }
    49  
    50  // ApplicationSettings represents some of the settings of a New Relic application.
    51  type ApplicationSettings struct {
    52  	AppApdexThreshold        float64 `json:"app_apdex_threshold,omitempty"`
    53  	EndUserApdexThreshold    float64 `json:"end_user_apdex_threshold,omitempty"`
    54  	EnableRealUserMonitoring bool    `json:"enable_real_user_monitoring"`
    55  	UseServerSideConfig      bool    `json:"use_server_side_config"`
    56  }
    57  
    58  // ApplicationLinks represents all the links for a New Relic application.
    59  type ApplicationLinks struct {
    60  	ServerIDs     []int `json:"servers,omitempty"`
    61  	HostIDs       []int `json:"application_hosts,omitempty"`
    62  	InstanceIDs   []int `json:"application_instances,omitempty"`
    63  	AlertPolicyID int   `json:"alert_policy"`
    64  }
    65  
    66  // ListApplicationsParams represents a set of filters to be
    67  // used when querying New Relic applications.
    68  type ListApplicationsParams struct {
    69  	Name     string `url:"filter[name],omitempty"`
    70  	Host     string `url:"filter[host],omitempty"`
    71  	IDs      []int  `url:"filter[ids],omitempty,comma"`
    72  	Language string `url:"filter[language],omitempty"`
    73  }
    74  
    75  // UpdateApplicationParams represents a set of parameters to be
    76  // used when updating New Relic applications.
    77  type UpdateApplicationParams struct {
    78  	Name     string
    79  	Settings ApplicationSettings
    80  }
    81  
    82  // ListApplications is used to retrieve New Relic applications.
    83  func (a *APM) ListApplications(params *ListApplicationsParams) ([]*Application, error) {
    84  	return a.ListApplicationsWithContext(context.Background(), params)
    85  }
    86  
    87  // ListApplicationsWithContext is used to retrieve New Relic applications.
    88  func (a *APM) ListApplicationsWithContext(ctx context.Context, params *ListApplicationsParams) ([]*Application, error) {
    89  	accountID := 0
    90  
    91  	method := applicationsREST{
    92  		parent: a,
    93  	}
    94  
    95  	return method.list(ctx, accountID, params)
    96  }
    97  
    98  // GetApplication is used to retrieve a single New Relic application.
    99  func (a *APM) GetApplication(applicationID int) (*Application, error) {
   100  	return a.GetApplicationWithContext(context.Background(), applicationID)
   101  }
   102  
   103  // GetApplicationWithContext is used to retrieve a single New Relic application.
   104  func (a *APM) GetApplicationWithContext(ctx context.Context, applicationID int) (*Application, error) {
   105  	accountID := 0
   106  	method := applicationsREST{
   107  		parent: a,
   108  	}
   109  
   110  	return method.get(ctx, accountID, applicationID)
   111  }
   112  
   113  // UpdateApplication is used to update a New Relic application's name and/or settings.
   114  func (a *APM) UpdateApplication(applicationID int, params UpdateApplicationParams) (*Application, error) {
   115  	return a.UpdateApplicationWithContext(context.Background(), applicationID, params)
   116  }
   117  
   118  // UpdateApplicationWithContext is used to update a New Relic application's name and/or settings.
   119  func (a *APM) UpdateApplicationWithContext(ctx context.Context, applicationID int, params UpdateApplicationParams) (*Application, error) {
   120  	accountID := 0
   121  	method := applicationsREST{
   122  		parent: a,
   123  	}
   124  
   125  	return method.update(ctx, accountID, applicationID, params)
   126  }
   127  
   128  // DeleteApplication is used to delete a New Relic application.
   129  // This process will only succeed if the application is no longer reporting data.
   130  func (a *APM) DeleteApplication(applicationID int) (*Application, error) {
   131  	return a.DeleteApplicationWithContext(context.Background(), applicationID)
   132  }
   133  
   134  // DeleteApplicationWithContext is used to delete a New Relic application.
   135  // This process will only succeed if the application is no longer reporting data.
   136  func (a *APM) DeleteApplicationWithContext(ctx context.Context, applicationID int) (*Application, error) {
   137  	accountID := 0
   138  	method := applicationsREST{
   139  		parent: a,
   140  	}
   141  
   142  	return method.remove(ctx, accountID, applicationID)
   143  }