@@ -52,19 +52,26 @@ func (h *CompoundHandler) Monitor(ctx context.Context) (MonitorResult, error) {
5252
5353 for _ , group := range groups {
5454 groupCount := len (group )
55- dataPoint := clientoptl .NewDataPoint ().
56- AddDimension (RESOURCE , h .metric .Spec .Target .Resource ).
57- AddDimension (GROUP , h .metric .Spec .Target .Group ).
58- AddDimension (VERSION , h .metric .Spec .Target .Version ).
59- SetValue (int64 (groupCount ))
55+ dataPoint := clientoptl .NewDataPoint ().SetValue (int64 (groupCount ))
6056
61- if h .clusterName != nil {
57+ // Add base dimensions only if they have a non-empty value
58+ if h .metric .Spec .Target .Resource != "" {
59+ dataPoint .AddDimension (RESOURCE , h .metric .Spec .Target .Resource )
60+ }
61+ if h .metric .Spec .Target .Group != "" {
62+ dataPoint .AddDimension (GROUP , h .metric .Spec .Target .Group )
63+ }
64+ if h .metric .Spec .Target .Version != "" {
65+ dataPoint .AddDimension (VERSION , h .metric .Spec .Target .Version )
66+ }
67+ if h .clusterName != nil && * h .clusterName != "" {
6268 dataPoint .AddDimension (CLUSTER , * h .clusterName )
6369 }
6470
6571 // Add projected dimensions for this specific group
6672 for _ , pField := range group {
67- if pField .error == nil {
73+ // Add projected dimension only if the value is non-empty and no error occurred
74+ if pField .error == nil && pField .value != "" {
6875 dataPoint .AddDimension (pField .name , pField .value )
6976 } else {
7077 // Optionally log or handle projection errors
0 commit comments