-
Notifications
You must be signed in to change notification settings - Fork 2
Add dimensions managedmetrics #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -59,25 +59,48 @@ func (h *ManagedHandler) sendStatusBasedMetricValue(ctx context.Context) (string | |
| // Create a new data point for each resource | ||
| dataPoint := clientoptl.NewDataPoint() | ||
|
|
||
| // Add GVK dimensions from resource | ||
| gv, err := schema.ParseGroupVersion(cr.MangedResource.APIVersion) | ||
| if err != nil { | ||
| return "", err | ||
| // Preserve old logic so that if custom dimensions are not set, we use status.conditions | ||
| // as default dimensions | ||
| if h.metric.Spec.Dimensions == nil { | ||
| gv, err := schema.ParseGroupVersion(cr.MangedResource.APIVersion) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| dataPoint.AddDimension(KIND, cr.MangedResource.Kind) | ||
| dataPoint.AddDimension(GROUP, gv.Group) | ||
| dataPoint.AddDimension(VERSION, gv.Version) | ||
|
|
||
| for typ, state := range cr.Status { | ||
| t := strings.ToLower(typ) | ||
| if t == "ready" || t == "synced" { | ||
| dataPoint.AddDimension(t, strconv.FormatBool(state)) | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: redundant empty line |
||
| } else { | ||
| objMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&cr.MangedResource) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| u := &unstructured.Unstructured{Object: objMap} | ||
|
|
||
| for key, expr := range h.metric.Spec.Dimensions { | ||
| s, _, err := nestedPrimitiveValue(*u, expr) | ||
| if err != nil { | ||
| fmt.Printf("WARN: Could not parse expression '%s' for dimension field '%s'. Error: %v\n", key, expr, err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use the |
||
| continue | ||
| } | ||
| dataPoint.AddDimension(key, s) | ||
| } | ||
| } | ||
| dataPoint.AddDimension(KIND, cr.MangedResource.Kind) | ||
| dataPoint.AddDimension(GROUP, gv.Group) | ||
| dataPoint.AddDimension(VERSION, gv.Version) | ||
|
|
||
| // Add cluster dimension if available | ||
| if h.clusterName != nil { | ||
| dataPoint.AddDimension(CLUSTER, *h.clusterName) | ||
| } | ||
|
|
||
| // Add status conditions as dimensions | ||
| for typ, state := range cr.Status { | ||
| dataPoint.AddDimension(strings.ToLower(typ), strconv.FormatBool(state)) | ||
| } | ||
|
|
||
| // Set the value to 1 for each resource | ||
| dataPoint.SetValue(1) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.