From 7f295d8d332b1c02e78a356c3339f5751dacd2bd 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 + .../v1beta1/monitoringdashboard_types.go | 21 +++ .../v1beta1/zz_generated.deepcopy.go | 38 +++++ .../dashboard_generated.mappings.go | 55 +++--- .../direct/monitoring/dashboard_mappings.go | 8 + ...ated_export_monitoringdashboardfull.golden | 7 + ...object_monitoringdashboardfull.golden.yaml | 7 + .../monitoringdashboardfull/_http.log | 156 ++++++++++++++++++ .../monitoringdashboardfull/create.yaml | 7 + .../monitoring/monitoringdashboard.md | 65 ++++++++ 13 files changed, 367 insertions(+), 30 deletions(-) diff --git a/apis/monitoring/v1beta1/monitoringdashboard_types.go b/apis/monitoring/v1beta1/monitoringdashboard_types.go index 89b4259351..d295fd7bc5 100644 --- a/apis/monitoring/v1beta1/monitoringdashboard_types.go +++ b/apis/monitoring/v1beta1/monitoringdashboard_types.go @@ -810,10 +810,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 2ed8807085..c56698bb9d 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 97a9224a5a..67e53f1a84 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 @@ -2942,6 +2942,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/clients/generated/apis/monitoring/v1beta1/monitoringdashboard_types.go b/pkg/clients/generated/apis/monitoring/v1beta1/monitoringdashboard_types.go index 90b41711e5..7f91b5ff67 100644 --- a/pkg/clients/generated/apis/monitoring/v1beta1/monitoringdashboard_types.go +++ b/pkg/clients/generated/apis/monitoring/v1beta1/monitoringdashboard_types.go @@ -136,6 +136,23 @@ type DashboardColumns struct { Widgets []DashboardWidgets `json:"widgets,omitempty"` } +type DashboardDashboardFilters struct { + /* The specified filter type */ + // +optional + FilterType *string `json:"filterType,omitempty"` + + /* Required. The key for the label */ + LabelKey string `json:"labelKey"` + + /* A variable-length string value. */ + // +optional + StringValue *string `json:"stringValue,omitempty"` + + /* 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. */ + // +optional + TemplateVariable *string `json:"templateVariable,omitempty"` +} + type DashboardDataSets struct { /* A template string for naming `TimeSeries` in the resulting data set. This should be a string with interpolations of the form `${label_name}`, which will resolve to the label's value. */ // +optional @@ -782,6 +799,10 @@ type MonitoringDashboardSpec struct { // +optional ColumnLayout *DashboardColumnLayout `json:"columnLayout,omitempty"` + /* Filters to reduce the amount of data charted based on the filter criteria. */ + // +optional + DashboardFilters []DashboardDashboardFilters `json:"dashboardFilters,omitempty"` + /* Required. The mutable, human-readable name. */ DisplayName string `json:"displayName"` diff --git a/pkg/clients/generated/apis/monitoring/v1beta1/zz_generated.deepcopy.go b/pkg/clients/generated/apis/monitoring/v1beta1/zz_generated.deepcopy.go index 0170a30462..67d2a0de8b 100644 --- a/pkg/clients/generated/apis/monitoring/v1beta1/zz_generated.deepcopy.go +++ b/pkg/clients/generated/apis/monitoring/v1beta1/zz_generated.deepcopy.go @@ -684,6 +684,37 @@ func (in *DashboardColumns) DeepCopy() *DashboardColumns { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DashboardDashboardFilters) DeepCopyInto(out *DashboardDashboardFilters) { + *out = *in + if in.FilterType != nil { + in, out := &in.FilterType, &out.FilterType + *out = new(string) + **out = **in + } + if in.StringValue != nil { + in, out := &in.StringValue, &out.StringValue + *out = new(string) + **out = **in + } + if in.TemplateVariable != nil { + in, out := &in.TemplateVariable, &out.TemplateVariable + *out = new(string) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DashboardDashboardFilters. +func (in *DashboardDashboardFilters) DeepCopy() *DashboardDashboardFilters { + if in == nil { + return nil + } + out := new(DashboardDashboardFilters) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DashboardDataSets) DeepCopyInto(out *DashboardDataSets) { *out = *in @@ -2104,6 +2135,13 @@ func (in *MonitoringDashboardSpec) DeepCopyInto(out *MonitoringDashboardSpec) { *out = new(DashboardColumnLayout) (*in).DeepCopyInto(*out) } + if in.DashboardFilters != nil { + in, out := &in.DashboardFilters, &out.DashboardFilters + *out = make([]DashboardDashboardFilters, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.GridLayout != nil { in, out := &in.GridLayout, &out.GridLayout *out = new(DashboardGridLayout) diff --git a/pkg/controller/direct/monitoring/dashboard_generated.mappings.go b/pkg/controller/direct/monitoring/dashboard_generated.mappings.go index 83df3d984f..5e3a9acb4f 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 fede68452a..3b422c9a60 100644 --- a/pkg/controller/direct/monitoring/dashboard_mappings.go +++ b/pkg/controller/direct/monitoring/dashboard_mappings.go @@ -217,6 +217,14 @@ func TimeSeriesTable_ColumnSettings_FromProto(mapCtx *MapContext, in *pb.TimeSer // We want to always output the visible field, i.e. `visible: false` // We probably can automate this, because the visible field is required. out.Visible = PtrTo(in.GetVisible()) + 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 110ddc9fc7..08d6bdb9c0 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 @@ -120,6 +120,13 @@ spec: resource.type="gce_instance" metricVisualization: NUMBER title: TimeSeriesTable 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 6cbe8ca4ef..4df8bcceba 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 @@ -128,6 +128,13 @@ spec: resource.type="gce_instance" metricVisualization: NUMBER title: TimeSeriesTable 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 39fdcda1fb..e8ae9ea093 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 @@ -384,6 +384,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}" } @@ -594,6 +606,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}" @@ -812,6 +836,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}" @@ -984,11 +1020,51 @@ x-goog-request-params: dashboard.name=projects%2F${projectId}%2Fdashboards%2Fmon ] }, "title": "ErrorReporting Widget" + }, + { + "timeSeriesTable": { + "columnSettings": [ + { + "column": "column1", + "visible": true + }, + { + "column": "column2" + } + ], + "dataSets": [ + { + "timeSeriesQuery": { + "timeSeriesFilter": { + "aggregation": { + "alignmentPeriod": "60s", + "perSeriesAligner": 2 + }, + "filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"" + } + } + } + ], + "metricVisualization": 1 + }, + "title": "TimeSeriesTable Widget" } ] } ] }, + "dashboardFilters": [ + { + "filterType": 1, + "labelKey": "instance_id", + "stringValue": "3133577226154888113", + "templateVariable": "iid" + }, + { + "filterType": 1, + "labelKey": "zone" + } + ], "displayName": "monitoringdashboard-full", "name": "projects/${projectId}/dashboards/monitoringdashboard-${uniqueId}" } @@ -1166,11 +1242,51 @@ X-Xss-Protection: 0 ] }, "title": "ErrorReporting Widget" + }, + { + "timeSeriesTable": { + "columnSettings": [ + { + "column": "column1", + "visible": true + }, + { + "column": "column2" + } + ], + "dataSets": [ + { + "timeSeriesQuery": { + "timeSeriesFilter": { + "aggregation": { + "alignmentPeriod": "60s", + "perSeriesAligner": "ALIGN_RATE" + }, + "filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"" + } + } + } + ], + "metricVisualization": "NUMBER" + }, + "title": "TimeSeriesTable Widget" } ] } ] }, + "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}" @@ -1356,11 +1472,51 @@ X-Xss-Protection: 0 ] }, "title": "ErrorReporting Widget" + }, + { + "timeSeriesTable": { + "columnSettings": [ + { + "column": "column1", + "visible": true + }, + { + "column": "column2" + } + ], + "dataSets": [ + { + "timeSeriesQuery": { + "timeSeriesFilter": { + "aggregation": { + "alignmentPeriod": "60s", + "perSeriesAligner": "ALIGN_RATE" + }, + "filter": "metric.type=\"compute.googleapis.com/instance/disk/read_bytes_count\" resource.type=\"gce_instance\"" + } + } + } + ], + "metricVisualization": "NUMBER" + }, + "title": "TimeSeriesTable Widget" } ] } ] }, + "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 41a923a623..a83972a3cd 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: diff --git a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringdashboard.md b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringdashboard.md index 961a9533c5..827488b230 100644 --- a/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringdashboard.md +++ b/scripts/generate-google3-docs/resource-reference/generated/resource-docs/monitoring/monitoringdashboard.md @@ -373,6 +373,11 @@ columnLayout: yAxis: label: string scale: string +dashboardFilters: +- filterType: string + labelKey: string + stringValue: string + templateVariable: string displayName: string gridLayout: columns: integer @@ -5187,6 +5192,66 @@ rowLayout:

{% verbatim %}The axis scale. By default, a linear scale is used.{% endverbatim %}

+ + +

dashboardFilters

+

Optional

+ + +

list (object)

+

{% verbatim %}Filters to reduce the amount of data charted based on the filter criteria.{% endverbatim %}

+ + + + +

dashboardFilters[]

+

Optional

+ + +

object

+

{% verbatim %}{% endverbatim %}

+ + + + +

dashboardFilters[].filterType

+

Optional

+ + +

string

+

{% verbatim %}The specified filter type{% endverbatim %}

+ + + + +

dashboardFilters[].labelKey

+

Required*

+ + +

string

+

{% verbatim %}Required. The key for the label{% endverbatim %}

+ + + + +

dashboardFilters[].stringValue

+

Optional

+ + +

string

+

{% verbatim %}A variable-length string value.{% endverbatim %}

+ + + + +

dashboardFilters[].templateVariable

+

Optional

+ + +

string

+

{% verbatim %}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.{% endverbatim %}

+ +

displayName