From 2e9909a223252296fc6039362b405bb5794a98a7 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 7 Oct 2024 00:38:21 +0530 Subject: [PATCH 1/5] feat(dashboard): Added a new field in dashboards -> variable -> options called --- pkg/dashboards/dashboard.go | 1 + pkg/dashboards/dashboards_api.go | 2 ++ pkg/dashboards/dashboards_api_integration_test.go | 6 +++++- pkg/dashboards/types.go | 4 ++++ pkg/entities/entities_api.go | 1 + pkg/entities/types.go | 2 ++ 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/dashboards/dashboard.go b/pkg/dashboards/dashboard.go index 0395c5f8f..7785848bf 100644 --- a/pkg/dashboards/dashboard.go +++ b/pkg/dashboards/dashboard.go @@ -100,6 +100,7 @@ const getDashboardEntityQuery = `query ($guid: EntityGuid!) { } name options { + excluded ignoreTimeRange } nrqlQuery { diff --git a/pkg/dashboards/dashboards_api.go b/pkg/dashboards/dashboards_api.go index 18e0bac6d..15da5c4d0 100644 --- a/pkg/dashboards/dashboards_api.go +++ b/pkg/dashboards/dashboards_api.go @@ -2118,6 +2118,7 @@ const DashboardCreateMutation = `mutation( query } options { + excluded ignoreTimeRange } replacementStrategy @@ -4294,6 +4295,7 @@ const DashboardUpdateMutation = `mutation( query } options { + excluded ignoreTimeRange } replacementStrategy diff --git a/pkg/dashboards/dashboards_api_integration_test.go b/pkg/dashboards/dashboards_api_integration_test.go index cfa9edc2f..6edeb617e 100644 --- a/pkg/dashboards/dashboards_api_integration_test.go +++ b/pkg/dashboards/dashboards_api_integration_test.go @@ -315,6 +315,7 @@ func TestIntegrationDashboard_Variables(t *testing.T) { Name: "variable", Options: &DashboardVariableOptionsInput{ IgnoreTimeRange: true, + Excluded: true, }, NRQLQuery: &DashboardVariableNRQLQueryInput{ AccountIDs: []int{testAccountID}, @@ -350,7 +351,9 @@ func TestIntegrationDashboard_Variables(t *testing.T) { if dash.Variables[0].Options.IgnoreTimeRange != dashboardInput.Variables[0].Options.IgnoreTimeRange { t.Errorf("Expected value to be %v but got %v\n", dashboardInput.Variables[0].Options.IgnoreTimeRange, dash.Variables[0].Options.IgnoreTimeRange) } - + if dash.Variables[0].Options.Excluded != dashboardInput.Variables[0].Options.Excluded { + t.Errorf("Expected value to be %v but got %v\n", dashboardInput.Variables[0].Options.Excluded, dash.Variables[0].Options.Excluded) + } // Input and Pages are different types so we can not easily compare them... assert.Equal(t, len(dashboardInput.Pages), len(dash.Pages)) require.Equal(t, 1, len(dash.Pages)) @@ -397,6 +400,7 @@ func TestIntegrationDashboard_Variables(t *testing.T) { Name: "variableUpdated", Options: &DashboardVariableOptionsInput{ IgnoreTimeRange: true, + Excluded: true, }, NRQLQuery: &DashboardVariableNRQLQueryInput{ AccountIDs: []int{testAccountID}, diff --git a/pkg/dashboards/types.go b/pkg/dashboards/types.go index f87b6ee7c..679a139a1 100644 --- a/pkg/dashboards/types.go +++ b/pkg/dashboards/types.go @@ -507,12 +507,16 @@ type DashboardVariableNRQLQueryInput struct { // DashboardVariableOptions - Options applied to the variable. type DashboardVariableOptions struct { + // With this turned on, query condition defined with the variable will not be included in the query. + Excluded bool `json:"excluded,omitempty"` // Only applies to variables of type NRQL. With this turned on, the time range for the NRQL query will override the time picker on dashboards and other pages. Turn this off to use the time picker as normal. IgnoreTimeRange bool `json:"ignoreTimeRange,omitempty"` } // DashboardVariableOptionsInput - Options applied to the variable type DashboardVariableOptionsInput struct { + // With this turned on, query condition defined with the variable will not be included in the query. + Excluded bool `json:"excluded"` // Only applies to variables of type NRQL. With this turned on, the time range for the NRQL query will override the time picker on dashboards and other pages. Turn this off to use the time picker as normal. IgnoreTimeRange bool `json:"ignoreTimeRange"` } diff --git a/pkg/entities/entities_api.go b/pkg/entities/entities_api.go index d5cc8b220..c0b632162 100644 --- a/pkg/entities/entities_api.go +++ b/pkg/entities/entities_api.go @@ -4002,6 +4002,7 @@ const getEntityQuery = `query( query } options { + excluded ignoreTimeRange } replacementStrategy diff --git a/pkg/entities/types.go b/pkg/entities/types.go index 44128db25..56b76e15b 100644 --- a/pkg/entities/types.go +++ b/pkg/entities/types.go @@ -5312,6 +5312,8 @@ type DashboardVariableNRQLQuery struct { // DashboardVariableOptions - Options applied to the variable. type DashboardVariableOptions struct { + // With this turned on, query condition defined with the variable will not be included in the query. + Excluded bool `json:"excluded,omitempty"` // Only applies to variables of type NRQL. With this turned on, the time range for the NRQL query will override the time picker on dashboards and other pages. Turn this off to use the time picker as normal. IgnoreTimeRange bool `json:"ignoreTimeRange,omitempty"` } From ec6d4d39c68450a2cc32c2872ea364573e027ccc Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 7 Oct 2024 15:48:51 +0530 Subject: [PATCH 2/5] chore(dashboards): changed options fields to pointers --- pkg/dashboards/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/dashboards/types.go b/pkg/dashboards/types.go index 679a139a1..7da90f527 100644 --- a/pkg/dashboards/types.go +++ b/pkg/dashboards/types.go @@ -516,9 +516,9 @@ type DashboardVariableOptions struct { // DashboardVariableOptionsInput - Options applied to the variable type DashboardVariableOptionsInput struct { // With this turned on, query condition defined with the variable will not be included in the query. - Excluded bool `json:"excluded"` + Excluded *bool `json:"excluded,omitempty"` // Only applies to variables of type NRQL. With this turned on, the time range for the NRQL query will override the time picker on dashboards and other pages. Turn this off to use the time picker as normal. - IgnoreTimeRange bool `json:"ignoreTimeRange"` + IgnoreTimeRange *bool `json:"ignoreTimeRange,omitempty"` } // DashboardWidgetConfigurationInput - Typed configuration for known visualizations. At most one may be populated. From 073c578d29e20044a0713a101cfc7d0e89e75008 Mon Sep 17 00:00:00 2001 From: shashank-reddy-nr Date: Mon, 14 Oct 2024 09:32:04 +0530 Subject: [PATCH 3/5] fix(dashboards): fixed integration tests of dashboards --- .../dashboards_api_integration_test.go | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/dashboards/dashboards_api_integration_test.go b/pkg/dashboards/dashboards_api_integration_test.go index 6edeb617e..52277e6e9 100644 --- a/pkg/dashboards/dashboards_api_integration_test.go +++ b/pkg/dashboards/dashboards_api_integration_test.go @@ -276,6 +276,8 @@ func TestIntegrationDashboard_Variables(t *testing.T) { // Test vars dashboardName := "newrelic-client-go test-dashboard-" + mock.RandSeq(5) + ignoreTimeRangeValue := true + excludedValue := true dashboardInput := DashboardInput{ Description: "Test description", Name: dashboardName, @@ -314,8 +316,8 @@ func TestIntegrationDashboard_Variables(t *testing.T) { }, Name: "variable", Options: &DashboardVariableOptionsInput{ - IgnoreTimeRange: true, - Excluded: true, + IgnoreTimeRange: &ignoreTimeRangeValue, + Excluded: &excludedValue, }, NRQLQuery: &DashboardVariableNRQLQueryInput{ AccountIDs: []int{testAccountID}, @@ -348,11 +350,11 @@ func TestIntegrationDashboard_Variables(t *testing.T) { assert.Equal(t, dashboardInput.Name, dash.Name) assert.Equal(t, entities.DashboardEntityPermissions(string(dashboardInput.Permissions)), dash.Permissions) - if dash.Variables[0].Options.IgnoreTimeRange != dashboardInput.Variables[0].Options.IgnoreTimeRange { - t.Errorf("Expected value to be %v but got %v\n", dashboardInput.Variables[0].Options.IgnoreTimeRange, dash.Variables[0].Options.IgnoreTimeRange) + if dash.Variables[0].Options.IgnoreTimeRange != *dashboardInput.Variables[0].Options.IgnoreTimeRange { + t.Errorf("Expected value to be %v but got %v\n", *dashboardInput.Variables[0].Options.IgnoreTimeRange, dash.Variables[0].Options.IgnoreTimeRange) } - if dash.Variables[0].Options.Excluded != dashboardInput.Variables[0].Options.Excluded { - t.Errorf("Expected value to be %v but got %v\n", dashboardInput.Variables[0].Options.Excluded, dash.Variables[0].Options.Excluded) + if dash.Variables[0].Options.Excluded != *dashboardInput.Variables[0].Options.Excluded { + t.Errorf("Expected value to be %v but got %v\n", *dashboardInput.Variables[0].Options.Excluded, dash.Variables[0].Options.Excluded) } // Input and Pages are different types so we can not easily compare them... assert.Equal(t, len(dashboardInput.Pages), len(dash.Pages)) @@ -365,6 +367,8 @@ func TestIntegrationDashboard_Variables(t *testing.T) { assert.Greater(t, len(dash.Pages[0].Widgets[0].RawConfiguration), 1) // Test: DashboardUpdate + ignoreTimeRangeValue = false + excludedValue = false updatedDashboard := DashboardInput{ Name: dash.Name, Permissions: result.EntityResult.Permissions, @@ -399,8 +403,8 @@ func TestIntegrationDashboard_Variables(t *testing.T) { }, Name: "variableUpdated", Options: &DashboardVariableOptionsInput{ - IgnoreTimeRange: true, - Excluded: true, + IgnoreTimeRange: &ignoreTimeRangeValue, + Excluded: &excludedValue, }, NRQLQuery: &DashboardVariableNRQLQueryInput{ AccountIDs: []int{testAccountID}, From 99f73bbec8d6618e35b43dc0c40ee779437f7ee5 Mon Sep 17 00:00:00 2001 From: Vinay Reddy Godhala Date: Thu, 17 Oct 2024 22:08:36 +0530 Subject: [PATCH 4/5] feat(dashboards): Added excluded variable in struct --- pkg/dashboards/dashboards_types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/dashboards/dashboards_types.go b/pkg/dashboards/dashboards_types.go index e1a9271f2..b6689af5f 100644 --- a/pkg/dashboards/dashboards_types.go +++ b/pkg/dashboards/dashboards_types.go @@ -323,6 +323,7 @@ type RawConfiguration struct { // RawConfigurationPlatformOptions represents the platform widget options type RawConfigurationPlatformOptions struct { IgnoreTimeRange bool `json:"ignoreTimeRange,omitempty"` + Excluded bool `json:"excluded,omitempty"` } type DashboardWidgetLegend struct { From 7ff3e7f4efc4cd5c83d1c5cf8fe36259199fe798 Mon Sep 17 00:00:00 2001 From: Vinay Reddy Godhala Date: Wed, 23 Oct 2024 12:19:30 +0530 Subject: [PATCH 5/5] feat(dashboards): removed variable in struct --- pkg/dashboards/dashboards_types.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/dashboards/dashboards_types.go b/pkg/dashboards/dashboards_types.go index b6689af5f..e1a9271f2 100644 --- a/pkg/dashboards/dashboards_types.go +++ b/pkg/dashboards/dashboards_types.go @@ -323,7 +323,6 @@ type RawConfiguration struct { // RawConfigurationPlatformOptions represents the platform widget options type RawConfigurationPlatformOptions struct { IgnoreTimeRange bool `json:"ignoreTimeRange,omitempty"` - Excluded bool `json:"excluded,omitempty"` } type DashboardWidgetLegend struct {