From 4c08c0c68ce9f3d387f3e9afc5194e57cf55a1bf Mon Sep 17 00:00:00 2001 From: Lucas Messina Date: Thu, 15 Sep 2022 13:12:55 +0200 Subject: [PATCH 1/3] feat: update servicelevel model --- pkg/servicelevel/servicelevel_api.go | 78 +++++++++++++++++++++++++--- pkg/servicelevel/types.go | 71 +++++++++++++++++++++---- 2 files changed, 132 insertions(+), 17 deletions(-) diff --git a/pkg/servicelevel/servicelevel_api.go b/pkg/servicelevel/servicelevel_api.go index 8e4b080b6..46f87d0ff 100644 --- a/pkg/servicelevel/servicelevel_api.go +++ b/pkg/servicelevel/servicelevel_api.go @@ -66,17 +66,30 @@ const ServiceLevelCreateMutation = `mutation( } badEvents { from + select { + attribute + function + } where } goodEvents { from + select { + attribute + function + } where } validEvents { from + select { + attribute + function + } where } } + guid id name objectives { @@ -99,24 +112,28 @@ const ServiceLevelCreateMutation = `mutation( } } }` -// Deletes an existing SLI by the ID. +// Deletes an existing SLI by the GUID. func (a *Servicelevel) ServiceLevelDelete( + gUID common.EntityGUID, iD string, ) (*ServiceLevelIndicator, error) { return a.ServiceLevelDeleteWithContext(context.Background(), + gUID, iD, ) } -// Deletes an existing SLI by the ID. +// Deletes an existing SLI by the GUID. func (a *Servicelevel) ServiceLevelDeleteWithContext( ctx context.Context, + gUID common.EntityGUID, iD string, ) (*ServiceLevelIndicator, error) { resp := ServiceLevelDeleteQueryResponse{} vars := map[string]interface{}{ - "id": iD, + "guid": gUID, + "id": iD, } if err := a.client.NerdGraphQueryWithContext(ctx, ServiceLevelDeleteMutation, vars, &resp); err != nil { @@ -131,8 +148,10 @@ type ServiceLevelDeleteQueryResponse struct { } const ServiceLevelDeleteMutation = `mutation( - $id: ID!, + $guid: EntityGuid, + $id: ID, ) { serviceLevelDelete( + guid: $guid, id: $id, ) { createdAt @@ -151,17 +170,30 @@ const ServiceLevelDeleteMutation = `mutation( } badEvents { from + select { + attribute + function + } where } goodEvents { from + select { + attribute + function + } where } validEvents { from + select { + attribute + function + } where } } + guid id name objectives { @@ -184,26 +216,30 @@ const ServiceLevelDeleteMutation = `mutation( } } }` -// Updates an existing SLI by the ID. +// Updates an existing SLI by the GUID. func (a *Servicelevel) ServiceLevelUpdate( + gUID common.EntityGUID, iD string, indicator ServiceLevelIndicatorUpdateInput, ) (*ServiceLevelIndicator, error) { return a.ServiceLevelUpdateWithContext(context.Background(), + gUID, iD, indicator, ) } -// Updates an existing SLI by the ID. +// Updates an existing SLI by the GUID. func (a *Servicelevel) ServiceLevelUpdateWithContext( ctx context.Context, + gUID common.EntityGUID, iD string, indicator ServiceLevelIndicatorUpdateInput, ) (*ServiceLevelIndicator, error) { resp := ServiceLevelUpdateQueryResponse{} vars := map[string]interface{}{ + "guid": gUID, "id": iD, "indicator": indicator, } @@ -220,9 +256,11 @@ type ServiceLevelUpdateQueryResponse struct { } const ServiceLevelUpdateMutation = `mutation( - $id: ID!, + $guid: EntityGuid, + $id: ID, $indicator: ServiceLevelIndicatorUpdateInput!, ) { serviceLevelUpdate( + guid: $guid, id: $id, indicator: $indicator, ) { @@ -242,17 +280,30 @@ const ServiceLevelUpdateMutation = `mutation( } badEvents { from + select { + attribute + function + } where } goodEvents { from + select { + attribute + function + } where } validEvents { from + select { + attribute + function + } where } } + guid id name objectives { @@ -325,17 +376,30 @@ const getIndicatorsQuery = `query( } badEvents { from + select { + attribute + function + } where } goodEvents { from + select { + attribute + function + } where } validEvents { from + select { + attribute + function + } where } } + guid id name objectives { diff --git a/pkg/servicelevel/types.go b/pkg/servicelevel/types.go index c2f632e00..981bda9a7 100644 --- a/pkg/servicelevel/types.go +++ b/pkg/servicelevel/types.go @@ -7,6 +7,21 @@ import ( "github.com/newrelic/newrelic-client-go/pkg/nrtime" ) +// ServiceLevelEventsQuerySelectFunction - The function to use in the SELECT clause. +type ServiceLevelEventsQuerySelectFunction string + +var ServiceLevelEventsQuerySelectFunctionTypes = struct { + // COUNT. + COUNT ServiceLevelEventsQuerySelectFunction + // SUM. + SUM ServiceLevelEventsQuerySelectFunction +}{ + // COUNT. + COUNT: "COUNT", + // SUM. + SUM: "SUM", +} + // ServiceLevelObjectiveRollingTimeWindowUnit - The rolling time window units. type ServiceLevelObjectiveRollingTimeWindowUnit string @@ -53,7 +68,7 @@ type ServiceLevelDefinition struct { // ServiceLevelEvents - The events that define the SLI. type ServiceLevelEvents struct { // The New Relic account to fetch the events from. - Account accounts.AccountReference `json:"account"` + Account accounts.AccountReference `json:"account,omitempty"` // The definition of bad events. BadEvents *ServiceLevelEventsQuery `json:"badEvents,omitempty"` // The definition of good events. @@ -76,24 +91,54 @@ type ServiceLevelEventsCreateInput struct { // ServiceLevelEventsQuery - The query that represents the events to fetch. type ServiceLevelEventsQuery struct { - // The NRDB event or metric to fetch the data from. + // The NRDB event to fetch the data from. From NRQL `json:"from"` + // The NRQL SELECT clause to aggregate events. + Select ServiceLevelEventsQuerySelect `json:"select,omitempty"` // The NRQL condition to filter the events. Where NRQL `json:"where,omitempty"` } // ServiceLevelEventsQueryCreateInput - The query that represents the events to fetch. type ServiceLevelEventsQueryCreateInput struct { - // The NRDB event or metric to fetch the data from. + // The NRDB event to fetch the data from. From NRQL `json:"from"` + // The NRQL SELECT clause to aggregate events. Default is COUNT(*). + Select ServiceLevelEventsQuerySelectCreateInput `json:"select,omitempty"` // The NRQL condition to filter the events. Where NRQL `json:"where,omitempty"` } +// ServiceLevelEventsQuerySelect - The resulting NRQL SELECT clause to aggregate events. +type ServiceLevelEventsQuerySelect struct { + // The event attribute to use in the SELECT clause. + Attribute string `json:"attribute,omitempty"` + // The function to use in the SELECT clause. + Function ServiceLevelEventsQuerySelectFunction `json:"function"` +} + +// ServiceLevelEventsQuerySelectCreateInput - The NRQL SELECT clause to aggregate events. +type ServiceLevelEventsQuerySelectCreateInput struct { + // The event attribute to use in the SELECT clause. + Attribute string `json:"attribute,omitempty"` + // The function to use in the SELECT clause. + Function ServiceLevelEventsQuerySelectFunction `json:"function"` +} + +// ServiceLevelEventsQuerySelectUpdateInput - The NRQL SELECT clause to aggregate events. +type ServiceLevelEventsQuerySelectUpdateInput struct { + // The event attribute to use in the SELECT clause. + Attribute string `json:"attribute,omitempty"` + // The function to use in the SELECT clause. + Function ServiceLevelEventsQuerySelectFunction `json:"function"` +} + // ServiceLevelEventsQueryUpdateInput - The query that represents the events to fetch. type ServiceLevelEventsQueryUpdateInput struct { - // The NRDB event or metric to fetch the data from. + // The NRDB event to fetch the data from. From NRQL `json:"from"` + // The NRQL SELECT clause to aggregate events. Default is COUNT(*). + Select ServiceLevelEventsQuerySelectUpdateInput `json:"select,omitempty"` // The NRQL condition to filter the events. Where NRQL `json:"where,omitempty"` } @@ -113,13 +158,15 @@ type ServiceLevelIndicator struct { // The date when the SLI was created represented in the number of milliseconds since the Unix epoch. CreatedAt *nrtime.EpochMilliseconds `json:"createdAt"` // The user who created the SLI. - CreatedBy UserReference `json:"createdBy"` + CreatedBy UserReference `json:"createdBy,omitempty"` // The description of the SLI. Description string `json:"description,omitempty"` // The entity which the SLI is attached to. EntityGUID common.EntityGUID `json:"entityGuid"` // The events that define the SLI. Events ServiceLevelEvents `json:"events"` + // The unique entity identifier of the SLI. + GUID common.EntityGUID `json:"guid"` // The unique identifier of the SLI. ID string `json:"id"` // The name of the SLI. @@ -206,7 +253,7 @@ type ServiceLevelObjectiveRollingTimeWindow struct { // ServiceLevelObjectiveRollingTimeWindowCreateInput - The rolling time window configuration of the SLO. type ServiceLevelObjectiveRollingTimeWindowCreateInput struct { - // The count of time units. Accepted values are 1, 7, 14, 28 and 30 days. + // The count of time units. Accepted values are 1, 7 and 28 days. Count int `json:"count"` // The time unit. Unit ServiceLevelObjectiveRollingTimeWindowUnit `json:"unit"` @@ -214,7 +261,7 @@ type ServiceLevelObjectiveRollingTimeWindowCreateInput struct { // ServiceLevelObjectiveRollingTimeWindowUpdateInput - The rolling time window configuration of the SLO. type ServiceLevelObjectiveRollingTimeWindowUpdateInput struct { - // The count of time units. Accepted values are 1, 7, 14, 28 and 30 days. + // The count of time units. Accepted values are 1, 7 and 28 days. Count int `json:"count"` // The time unit. Unit ServiceLevelObjectiveRollingTimeWindowUnit `json:"unit"` @@ -258,10 +305,14 @@ type ServiceLevelResultQuery struct { // UserReference - The `UserReference` object provides basic identifying information about the user. type UserReference struct { - Email string `json:"email,omitempty"` + // + Email string `json:"email,omitempty"` + // Gravatar string `json:"gravatar,omitempty"` - ID int `json:"id,omitempty"` - Name string `json:"name,omitempty"` + // + ID int `json:"id,omitempty"` + // + Name string `json:"name,omitempty"` } type indicatorsResponse struct { From 366ce5cb8ac0d8be4b895ce3e442647bd47cbea1 Mon Sep 17 00:00:00 2001 From: Lucas Messina Date: Tue, 20 Sep 2022 09:48:45 +0200 Subject: [PATCH 2/3] fix: add servicelevel select types as nullables --- .tutone.yml | 5 +++++ pkg/servicelevel/types.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.tutone.yml b/.tutone.yml index a32589188..c4b7f5498 100644 --- a/.tutone.yml +++ b/.tutone.yml @@ -1094,6 +1094,11 @@ packages: field_type_override: "*ServiceLevelEventsQueryUpdateInput" - name: ServiceLevelEventsUpdateInput field_type_override: "*ServiceLevelEventsUpdateInput" + - name: ServiceLevelEventsQuerySelectCreateInput + field_type_override: "*ServiceLevelEventsQuerySelectCreateInput" + - name: ServiceLevelEventsQuerySelectUpdateInput + field_type_override: "*ServiceLevelEventsQuerySelectUpdateInput" + # # Types owned by other packages diff --git a/pkg/servicelevel/types.go b/pkg/servicelevel/types.go index 981bda9a7..2348a9c3e 100644 --- a/pkg/servicelevel/types.go +++ b/pkg/servicelevel/types.go @@ -104,7 +104,7 @@ type ServiceLevelEventsQueryCreateInput struct { // The NRDB event to fetch the data from. From NRQL `json:"from"` // The NRQL SELECT clause to aggregate events. Default is COUNT(*). - Select ServiceLevelEventsQuerySelectCreateInput `json:"select,omitempty"` + Select *ServiceLevelEventsQuerySelectCreateInput `json:"select,omitempty"` // The NRQL condition to filter the events. Where NRQL `json:"where,omitempty"` } @@ -138,7 +138,7 @@ type ServiceLevelEventsQueryUpdateInput struct { // The NRDB event to fetch the data from. From NRQL `json:"from"` // The NRQL SELECT clause to aggregate events. Default is COUNT(*). - Select ServiceLevelEventsQuerySelectUpdateInput `json:"select,omitempty"` + Select *ServiceLevelEventsQuerySelectUpdateInput `json:"select,omitempty"` // The NRQL condition to filter the events. Where NRQL `json:"where,omitempty"` } From c340f8c4ead90a37bc0f148d144032c9cb4eda24 Mon Sep 17 00:00:00 2001 From: Lucas Messina Date: Thu, 22 Sep 2022 14:01:33 +0200 Subject: [PATCH 3/3] fix!: manually remove ID from update/delete in service levels methods --- pkg/servicelevel/servicelevel_api.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/servicelevel/servicelevel_api.go b/pkg/servicelevel/servicelevel_api.go index 46f87d0ff..8ba0754d0 100644 --- a/pkg/servicelevel/servicelevel_api.go +++ b/pkg/servicelevel/servicelevel_api.go @@ -113,27 +113,25 @@ const ServiceLevelCreateMutation = `mutation( } }` // Deletes an existing SLI by the GUID. +// iD optional field manually removed in favor of gUID to favor it's deprecation func (a *Servicelevel) ServiceLevelDelete( gUID common.EntityGUID, - iD string, ) (*ServiceLevelIndicator, error) { return a.ServiceLevelDeleteWithContext(context.Background(), gUID, - iD, ) } // Deletes an existing SLI by the GUID. +// iD optional field manually removed in favor of gUID to favor it's deprecation func (a *Servicelevel) ServiceLevelDeleteWithContext( ctx context.Context, gUID common.EntityGUID, - iD string, ) (*ServiceLevelIndicator, error) { resp := ServiceLevelDeleteQueryResponse{} vars := map[string]interface{}{ "guid": gUID, - "id": iD, } if err := a.client.NerdGraphQueryWithContext(ctx, ServiceLevelDeleteMutation, vars, &resp); err != nil { @@ -147,12 +145,11 @@ type ServiceLevelDeleteQueryResponse struct { ServiceLevelIndicator ServiceLevelIndicator `json:"ServiceLevelDelete"` } +// id optional field manually removed in favor of guid to favor it's deprecation const ServiceLevelDeleteMutation = `mutation( $guid: EntityGuid, - $id: ID, ) { serviceLevelDelete( guid: $guid, - id: $id, ) { createdAt createdBy { @@ -217,30 +214,28 @@ const ServiceLevelDeleteMutation = `mutation( } }` // Updates an existing SLI by the GUID. +// iD optional field manually removed in favor of gUID to favor it's deprecation func (a *Servicelevel) ServiceLevelUpdate( gUID common.EntityGUID, - iD string, indicator ServiceLevelIndicatorUpdateInput, ) (*ServiceLevelIndicator, error) { return a.ServiceLevelUpdateWithContext(context.Background(), gUID, - iD, indicator, ) } // Updates an existing SLI by the GUID. +// iD optional field manually removed in favor of gUID to favor it's deprecation func (a *Servicelevel) ServiceLevelUpdateWithContext( ctx context.Context, gUID common.EntityGUID, - iD string, indicator ServiceLevelIndicatorUpdateInput, ) (*ServiceLevelIndicator, error) { resp := ServiceLevelUpdateQueryResponse{} vars := map[string]interface{}{ "guid": gUID, - "id": iD, "indicator": indicator, } @@ -255,13 +250,12 @@ type ServiceLevelUpdateQueryResponse struct { ServiceLevelIndicator ServiceLevelIndicator `json:"ServiceLevelUpdate"` } +// id optional field manually removed in favor of guid to favor it's deprecation const ServiceLevelUpdateMutation = `mutation( $guid: EntityGuid, - $id: ID, $indicator: ServiceLevelIndicatorUpdateInput!, ) { serviceLevelUpdate( guid: $guid, - id: $id, indicator: $indicator, ) { createdAt