From b8007181a2152b19d20878a4c4ba2e594b3d49e3 Mon Sep 17 00:00:00 2001 From: justinsb Date: Fri, 28 Jun 2024 13:33:56 -0400 Subject: [PATCH] monitoringdashboard: add dashboardFilters --- .../v1beta1/monitoringdashboard_types.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 7 +++ ...ards.monitoring.cnrm.cloud.google.com.yaml | 23 ++++++++ docs/releasenotes/release-1.120.md | 1 + .../dashboard_generated.mappings.go | 55 +++++++++---------- .../direct/monitoring/dashboard_mappings.go | 9 +++ ...ated_export_monitoringdashboardfull.golden | 7 +++ ...object_monitoringdashboardfull.golden.yaml | 7 +++ .../monitoringdashboardfull/_http.log | 36 ++++++++++++ .../monitoringdashboardfull/create.yaml | 7 +++ 10 files changed, 124 insertions(+), 30 deletions(-) diff --git a/apis/monitoring/v1beta1/monitoringdashboard_types.go b/apis/monitoring/v1beta1/monitoringdashboard_types.go index 53e69c91fa..4f3a87b0f8 100644 --- a/apis/monitoring/v1beta1/monitoringdashboard_types.go +++ b/apis/monitoring/v1beta1/monitoringdashboard_types.go @@ -815,10 +815,10 @@ type MonitoringDashboardSpec struct { // arranged vertically. ColumnLayout *ColumnLayout `json:"columnLayout,omitempty"` - /*NOTYET // Filters to reduce the amount of data charted based on the filter criteria. DashboardFilters []DashboardFilter `json:"dashboardFilters,omitempty"` + /*NOTYET // Labels applied to the dashboard Labels []Dashboard_LabelsEntry `json:"labels,omitempty"` */ diff --git a/apis/monitoring/v1beta1/zz_generated.deepcopy.go b/apis/monitoring/v1beta1/zz_generated.deepcopy.go index 27a55b3231..7d63c34928 100644 --- a/apis/monitoring/v1beta1/zz_generated.deepcopy.go +++ b/apis/monitoring/v1beta1/zz_generated.deepcopy.go @@ -432,6 +432,13 @@ func (in *MonitoringDashboardSpec) DeepCopyInto(out *MonitoringDashboardSpec) { *out = new(ColumnLayout) (*in).DeepCopyInto(*out) } + if in.DashboardFilters != nil { + in, out := &in.DashboardFilters, &out.DashboardFilters + *out = make([]DashboardFilter, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } diff --git a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_monitoringdashboards.monitoring.cnrm.cloud.google.com.yaml b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_monitoringdashboards.monitoring.cnrm.cloud.google.com.yaml index f9e6e68798..9502a6ed65 100644 --- a/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_monitoringdashboards.monitoring.cnrm.cloud.google.com.yaml +++ b/config/crds/resources/apiextensions.k8s.io_v1_customresourcedefinition_monitoringdashboards.monitoring.cnrm.cloud.google.com.yaml @@ -2295,6 +2295,29 @@ spec: type: object type: array type: object + dashboardFilters: + description: Filters to reduce the amount of data charted based on + the filter criteria. + items: + properties: + filterType: + description: The specified filter type + type: string + labelKey: + description: Required. The key for the label + type: string + stringValue: + description: A variable-length string value. + type: string + templateVariable: + description: The placeholder text that can be referenced in + a filter string or MQL query. If omitted, the dashboard filter + will be applied to all relevant widgets in the dashboard. + type: string + required: + - labelKey + type: object + type: array displayName: description: Required. The mutable, human-readable name. type: string diff --git a/docs/releasenotes/release-1.120.md b/docs/releasenotes/release-1.120.md index 335ac51e31..fc17ac5062 100644 --- a/docs/releasenotes/release-1.120.md +++ b/docs/releasenotes/release-1.120.md @@ -29,6 +29,7 @@ output fields from GCP APIs are in `status.observedState.*` * `MonitoringDashboard` + * Added `dashboardFilters` support. * Added `alertChart` widgets. * Added `collapsibleGroup` widgets. * Added `pieChart` widgets. diff --git a/pkg/controller/direct/monitoring/dashboard_generated.mappings.go b/pkg/controller/direct/monitoring/dashboard_generated.mappings.go index 18d49675f5..02ab0749fc 100644 --- a/pkg/controller/direct/monitoring/dashboard_generated.mappings.go +++ b/pkg/controller/direct/monitoring/dashboard_generated.mappings.go @@ -109,33 +109,30 @@ func ColumnLayout_Column_ToProto(mapCtx *MapContext, in *krm.ColumnLayout_Column out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto) return out } - -// func DashboardFilter_FromProto(mapCtx *MapContext, in *pb.DashboardFilter) *krm.DashboardFilter { -// if in == nil { -// return nil -// } -// out := &krm.DashboardFilter{} -// out.LabelKey = LazyPtr(in.GetLabelKey()) -// out.TemplateVariable = LazyPtr(in.GetTemplateVariable()) -// out.StringValue = LazyPtr(in.GetStringValue()) -// out.FilterType = Enum_FromProto(mapCtx, in.FilterType) -// return out -// } - -// func DashboardFilter_ToProto(mapCtx *MapContext, in *krm.DashboardFilter) *pb.DashboardFilter { -// if in == nil { -// return nil -// } -// out := &pb.DashboardFilter{} -// out.LabelKey = ValueOf(in.LabelKey) -// out.TemplateVariable = ValueOf(in.TemplateVariable) -// if oneof := DashboardFilter_StringValue_ToProto(mapCtx, in.StringValue); oneof != nil { -// out.DefaultValue = oneof -// } -// out.FilterType = Enum_ToProto[pb.DashboardFilter_FilterType](mapCtx, in.FilterType) -// return out -// } - +func DashboardFilter_FromProto(mapCtx *MapContext, in *pb.DashboardFilter) *krm.DashboardFilter { + if in == nil { + return nil + } + out := &krm.DashboardFilter{} + out.LabelKey = LazyPtr(in.GetLabelKey()) + out.TemplateVariable = LazyPtr(in.GetTemplateVariable()) + out.StringValue = LazyPtr(in.GetStringValue()) + out.FilterType = Enum_FromProto(mapCtx, in.FilterType) + return out +} +func DashboardFilter_ToProto(mapCtx *MapContext, in *krm.DashboardFilter) *pb.DashboardFilter { + if in == nil { + return nil + } + out := &pb.DashboardFilter{} + out.LabelKey = ValueOf(in.LabelKey) + out.TemplateVariable = ValueOf(in.TemplateVariable) + if oneof := DashboardFilter_StringValue_ToProto(mapCtx, in.StringValue); oneof != nil { + out.DefaultValue = oneof + } + out.FilterType = Enum_ToProto[pb.DashboardFilter_FilterType](mapCtx, in.FilterType) + return out +} func GridLayout_FromProto(mapCtx *MapContext, in *pb.GridLayout) *krm.GridLayout { if in == nil { return nil @@ -205,7 +202,7 @@ func MonitoringDashboardSpec_FromProto(mapCtx *MapContext, in *pb.Dashboard) *kr out.MosaicLayout = MosaicLayout_FromProto(mapCtx, in.GetMosaicLayout()) out.RowLayout = RowLayout_FromProto(mapCtx, in.GetRowLayout()) out.ColumnLayout = ColumnLayout_FromProto(mapCtx, in.GetColumnLayout()) - // MISSING: DashboardFilters + out.DashboardFilters = Slice_FromProto(mapCtx, in.DashboardFilters, DashboardFilter_FromProto) // MISSING: Labels return out } @@ -229,7 +226,7 @@ func MonitoringDashboardSpec_ToProto(mapCtx *MapContext, in *krm.MonitoringDashb if oneof := ColumnLayout_ToProto(mapCtx, in.ColumnLayout); oneof != nil { out.Layout = &pb.Dashboard_ColumnLayout{ColumnLayout: oneof} } - // MISSING: DashboardFilters + out.DashboardFilters = Slice_ToProto(mapCtx, in.DashboardFilters, DashboardFilter_ToProto) // MISSING: Labels return out } diff --git a/pkg/controller/direct/monitoring/dashboard_mappings.go b/pkg/controller/direct/monitoring/dashboard_mappings.go index ea4174143c..d8bfb1d573 100644 --- a/pkg/controller/direct/monitoring/dashboard_mappings.go +++ b/pkg/controller/direct/monitoring/dashboard_mappings.go @@ -206,3 +206,12 @@ func TimeSeriesQuery_PrometheusQuery_ToProto(mapCtx *MapContext, in *string) *pb out.PrometheusQuery = *in return out } + +func DashboardFilter_StringValue_ToProto(mapCtx *MapContext, in *string) *pb.DashboardFilter_StringValue { + if in == nil { + return nil + } + out := &pb.DashboardFilter_StringValue{} + out.StringValue = *in + return out +} diff --git a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_export_monitoringdashboardfull.golden b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_export_monitoringdashboardfull.golden index dbc496876a..abb0e892b5 100644 --- a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_export_monitoringdashboardfull.golden +++ b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_export_monitoringdashboardfull.golden @@ -104,6 +104,13 @@ spec: - v1 - v2 title: ErrorReporting Widget + dashboardFilters: + - filterType: RESOURCE_LABEL + labelKey: instance_id + stringValue: "3133577226154888113" + templateVariable: iid + - filterType: RESOURCE_LABEL + labelKey: zone displayName: monitoringdashboard-full projectRef: external: ${projectId} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_object_monitoringdashboardfull.golden.yaml b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_object_monitoringdashboardfull.golden.yaml index 5bbd5d642f..8431101e4a 100644 --- a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_object_monitoringdashboardfull.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_generated_object_monitoringdashboardfull.golden.yaml @@ -112,6 +112,13 @@ spec: - v1 - v2 title: ErrorReporting Widget + dashboardFilters: + - filterType: RESOURCE_LABEL + labelKey: instance_id + stringValue: "3133577226154888113" + templateVariable: iid + - filterType: RESOURCE_LABEL + labelKey: zone displayName: monitoringdashboard-full projectRef: external: ${projectId} diff --git a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_http.log b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_http.log index c24d30bff3..2fe58a4d84 100644 --- a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/_http.log @@ -356,6 +356,18 @@ x-goog-request-params: parent=projects%2F${projectId} } ] }, + "dashboardFilters": [ + { + "filterType": 1, + "labelKey": "instance_id", + "stringValue": "3133577226154888113", + "templateVariable": "iid" + }, + { + "filterType": 1, + "labelKey": "zone" + } + ], "displayName": "monitoringdashboard-full", "name": "projects/${projectId}/dashboards/monitoringdashboard-${uniqueId}" } @@ -538,6 +550,18 @@ X-Xss-Protection: 0 } ] }, + "dashboardFilters": [ + { + "filterType": "RESOURCE_LABEL", + "labelKey": "instance_id", + "stringValue": "3133577226154888113", + "templateVariable": "iid" + }, + { + "filterType": "RESOURCE_LABEL", + "labelKey": "zone" + } + ], "displayName": "monitoringdashboard-full", "etag": "abcdef0123A=", "name": "projects/${projectNumber}/dashboards/monitoringdashboard-${uniqueId}" @@ -728,6 +752,18 @@ X-Xss-Protection: 0 } ] }, + "dashboardFilters": [ + { + "filterType": "RESOURCE_LABEL", + "labelKey": "instance_id", + "stringValue": "3133577226154888113", + "templateVariable": "iid" + }, + { + "filterType": "RESOURCE_LABEL", + "labelKey": "zone" + } + ], "displayName": "monitoringdashboard-full", "etag": "abcdef0123A=", "name": "projects/${projectNumber}/dashboards/monitoringdashboard-${uniqueId}" diff --git a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/create.yaml b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/create.yaml index 5819ee6d14..d1231cca07 100644 --- a/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/create.yaml +++ b/pkg/test/resourcefixture/testdata/basic/monitoring/v1beta1/monitoringdashboard/monitoringdashboardfull/create.yaml @@ -17,6 +17,13 @@ kind: MonitoringDashboard metadata: name: monitoringdashboard-${uniqueId} spec: + dashboardFilters: + - filterType: RESOURCE_LABEL + labelKey: instance_id + stringValue: "3133577226154888113" + templateVariable: iid + - filterType: RESOURCE_LABEL + labelKey: zone displayName: "monitoringdashboard-full" columnLayout: columns: