Skip to content

Commit

Permalink
monitoringdashboard: alertPolicyNames should be refs
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Jul 1, 2024
1 parent 3e7d6de commit 62649da
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 108 deletions.
6 changes: 2 additions & 4 deletions apis/monitoring/v1beta1/monitoringdashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,8 @@ type IncidentList struct {
// The resource type and labels are used for filtering.
MonitoredResources []MonitoredResource `json:"monitoredResources,omitempty"`

// Optional. A list of alert policy names to filter the incident list by.
// Don't include the project ID prefix in the policy name. For
// example, use `alertPolicies/utilization`.
PolicyNames []string `json:"policyNames,omitempty"`
// Optional. A list of alert policies to filter the incident list by.
PolicyRefs []refs.MonitoringAlertPolicyRef `json:"policyRefs,omitempty"`
}

// +kcc:proto=google.api.MonitoredResource
Expand Down
6 changes: 3 additions & 3 deletions apis/monitoring/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,39 @@ spec:
type: string
type: object
type: array
policyNames:
description: Optional. A list of alert policy
names to filter the incident list by. Don't
include the project ID prefix in the policy
name. For example, use `alertPolicies/utilization`.
policyRefs:
description: Optional. A list of alert policies
to filter the incident list by.
items:
type: string
oneOf:
- not:
required:
- external
required:
- name
- not:
anyOf:
- required:
- name
- required:
- namespace
required:
- external
properties:
external:
description: The MonitoringAlertPolicy link
in the form "projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]",
when not managed by KCC.
type: string
name:
description: The `name` field of a `MonitoringAlertPolicy`
resource.
type: string
namespace:
description: The `namespace` field of a
`MonitoringAlertPolicy` resource.
type: string
type: object
type: array
type: object
logsPanel:
Expand Down Expand Up @@ -3191,13 +3217,39 @@ spec:
type: string
type: object
type: array
policyNames:
description: Optional. A list of alert policy names
to filter the incident list by. Don't include the
project ID prefix in the policy name. For example,
use `alertPolicies/utilization`.
policyRefs:
description: Optional. A list of alert policies to filter
the incident list by.
items:
type: string
oneOf:
- not:
required:
- external
required:
- name
- not:
anyOf:
- required:
- name
- required:
- namespace
required:
- external
properties:
external:
description: The MonitoringAlertPolicy link in
the form "projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]",
when not managed by KCC.
type: string
name:
description: The `name` field of a `MonitoringAlertPolicy`
resource.
type: string
namespace:
description: The `namespace` field of a `MonitoringAlertPolicy`
resource.
type: string
type: object
type: array
type: object
logsPanel:
Expand Down Expand Up @@ -5978,13 +6030,39 @@ spec:
type: string
type: object
type: array
policyNames:
description: Optional. A list of alert policy names
to filter the incident list by. Don't include
the project ID prefix in the policy name. For
example, use `alertPolicies/utilization`.
policyRefs:
description: Optional. A list of alert policies
to filter the incident list by.
items:
type: string
oneOf:
- not:
required:
- external
required:
- name
- not:
anyOf:
- required:
- name
- required:
- namespace
required:
- external
properties:
external:
description: The MonitoringAlertPolicy link
in the form "projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]",
when not managed by KCC.
type: string
name:
description: The `name` field of a `MonitoringAlertPolicy`
resource.
type: string
namespace:
description: The `namespace` field of a `MonitoringAlertPolicy`
resource.
type: string
type: object
type: array
type: object
logsPanel:
Expand Down Expand Up @@ -8914,13 +8992,39 @@ spec:
type: string
type: object
type: array
policyNames:
description: Optional. A list of alert policy
names to filter the incident list by. Don't
include the project ID prefix in the policy
name. For example, use `alertPolicies/utilization`.
policyRefs:
description: Optional. A list of alert policies
to filter the incident list by.
items:
type: string
oneOf:
- not:
required:
- external
required:
- name
- not:
anyOf:
- required:
- name
- required:
- namespace
required:
- external
properties:
external:
description: The MonitoringAlertPolicy link
in the form "projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[ALERT_POLICY_ID]",
when not managed by KCC.
type: string
name:
description: The `name` field of a `MonitoringAlertPolicy`
resource.
type: string
namespace:
description: The `namespace` field of a
`MonitoringAlertPolicy` resource.
type: string
type: object
type: array
type: object
logsPanel:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions pkg/controller/direct/monitoring/dashboard_generated.mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,7 @@ func GridLayout_ToProto(mapCtx *MapContext, in *krm.GridLayout) *pb.GridLayout {
out.Widgets = Slice_ToProto(mapCtx, in.Widgets, Widget_ToProto)
return out
}
func IncidentList_FromProto(mapCtx *MapContext, in *pb.IncidentList) *krm.IncidentList {
if in == nil {
return nil
}
out := &krm.IncidentList{}
out.MonitoredResources = Slice_FromProto(mapCtx, in.MonitoredResources, MonitoredResource_FromProto)
out.PolicyNames = in.PolicyNames
return out
}
func IncidentList_ToProto(mapCtx *MapContext, in *krm.IncidentList) *pb.IncidentList {
if in == nil {
return nil
}
out := &pb.IncidentList{}
out.MonitoredResources = Slice_ToProto(mapCtx, in.MonitoredResources, MonitoredResource_ToProto)
out.PolicyNames = in.PolicyNames
return out
}

func LogsPanel_FromProto(mapCtx *MapContext, in *pb.LogsPanel) *krm.LogsPanel {
if in == nil {
return nil
Expand Down
23 changes: 23 additions & 0 deletions pkg/controller/direct/monitoring/dashboard_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,26 @@ func DashboardFilter_StringValue_ToProto(mapCtx *MapContext, in *string) *pb.Das
out.StringValue = *in
return out
}

func IncidentList_FromProto(mapCtx *MapContext, in *pb.IncidentList) *krm.IncidentList {
if in == nil {
return nil
}
out := &krm.IncidentList{}
out.MonitoredResources = Slice_FromProto(mapCtx, in.MonitoredResources, MonitoredResource_FromProto)
for _, policyName := range in.PolicyNames {
out.PolicyRefs = append(out.PolicyRefs, refs.MonitoringAlertPolicyRef{External: policyName})
}
return out
}
func IncidentList_ToProto(mapCtx *MapContext, in *krm.IncidentList) *pb.IncidentList {
if in == nil {
return nil
}
out := &pb.IncidentList{}
out.MonitoredResources = Slice_ToProto(mapCtx, in.MonitoredResources, MonitoredResource_ToProto)
for _, policyRef := range in.PolicyRefs {
out.PolicyNames = append(out.PolicyNames, policyRef.External)
}
return out
}
15 changes: 15 additions & 0 deletions pkg/controller/direct/monitoring/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ func (r *refNormalizer) VisitField(path string, v any) error {
}
}

if alertChart, ok := v.(*krm.IncidentList); ok {
for i, policyRef := range alertChart.PolicyRefs {
if ref, err := normalizeMonitoringAlertPolicyRef(r.ctx, r.kube, r.src, r.project, &policyRef); err != nil {
return err
} else {
prefix := fmt.Sprintf("projects/%s/", r.project.ProjectID)
if !strings.HasPrefix(ref.External, prefix) {
return fmt.Errorf("resolve alertPolicy (%q) in incidentList was not in same project", ref.External)
}
ref.External = strings.TrimPrefix(ref.External, prefix)
alertChart.PolicyRefs[i] = *ref
}
}
}

if projectRef, ok := v.(*refs.ProjectRef); ok {
if ref, err := normalizeProjectRef(r.ctx, r.kube, r.src, projectRef); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ spec:
project_id: my-project
zone: us-central1-a
type: gce_instance
policyNames:
- foo
- bar
policyRefs:
- external: alertPolicies/${alertPolicyID}
title: IncidentList Widget
dashboardFilters:
- filterType: RESOURCE_LABEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ spec:
project_id: my-project
zone: us-central1-a
type: gce_instance
policyNames:
- foo
- bar
policyRefs:
- name: monitoringalertpolicy-${uniqueId}
title: IncidentList Widget
dashboardFilters:
- filterType: RESOURCE_LABEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ x-goog-request-params: parent=projects%2F${projectId}
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down Expand Up @@ -607,8 +606,7 @@ X-Xss-Protection: 0
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down Expand Up @@ -842,8 +840,7 @@ X-Xss-Protection: 0
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down Expand Up @@ -1065,8 +1062,7 @@ x-goog-request-params: dashboard.name=projects%2F${projectId}%2Fdashboards%2Fmon
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down Expand Up @@ -1293,8 +1289,7 @@ X-Xss-Protection: 0
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down Expand Up @@ -1528,8 +1523,7 @@ X-Xss-Protection: 0
}
],
"policyNames": [
"foo",
"bar"
"alertPolicies/${alertPolicyID}"
]
},
"title": "IncidentList Widget"
Expand Down
Loading

0 comments on commit 62649da

Please sign in to comment.