Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1alpha1/managedmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type ManagedMetricSpec struct {
// Defines which managed resources to observe
// +optional
Target *GroupVersionKind `json:"target,omitempty"`
// Defines dimensions of the metric. All specified fields must be nested strings. Nested slices are not supported.
// If not specified, only status.conditions of the CR will be used as dimension.
// +optional
Dimensions map[string]string `json:"dimensions,omitempty"`
// Define labels of your object to adapt filters of the query
// +optional
LabelSelector string `json:"labelSelector,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/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 @@ -65,6 +65,13 @@ spec:
description: Sets the description that will be used to identify the
metric in Dynatrace(or other providers)
type: string
dimensions:
additionalProperties:
type: string
description: |-
Defines dimensions of the metric. All specified fields must be nested strings. Nested slices are not supported.
If not specified, only status.conditions of the CR will be used as dimension.
type: object
fieldSelector:
description: Define fields of your object to adapt filters of the
query
Expand Down
1 change: 1 addition & 0 deletions internal/controller/managedmetric_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func getClusterInfo(config *rest.Config) (string, error) {
clusterName := parts[0]

return clusterName, nil

}

// OrchestratorFactory is a function type for creating orchestrators
Expand Down
23 changes: 12 additions & 11 deletions internal/orchestrator/managedhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"slices"
"strconv"
"strings"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -59,25 +58,27 @@ 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)
objMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&cr.MangedResource)
if err != nil {
return "", err
}
dataPoint.AddDimension(KIND, cr.MangedResource.Kind)
dataPoint.AddDimension(GROUP, gv.Group)
dataPoint.AddDimension(VERSION, gv.Version)

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)
continue
}
dataPoint.AddDimension(key, s)
}

// 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)

Expand Down