-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All CRS metrics are hardcoded to "gauge" type, this patch addresses that.
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package customresourcestate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNewCustomResourceMetrics(t *testing.T) { | ||
tests := []struct { | ||
r Resource | ||
wantErr bool | ||
name string | ||
}{ | ||
{ | ||
// https://github.com/kubernetes/kube-state-metrics/issues/1886 | ||
name: "dynamic metric type (not just hardcoded to gauge)", | ||
r: Resource{ | ||
GroupVersionKind: GroupVersionKind{ | ||
Group: "apps", | ||
Version: "v1", | ||
Kind: "Deployment", | ||
}, | ||
Labels: Labels{ | ||
LabelsFromPath: map[string][]string{ | ||
"name": {"metadata", "name"}, | ||
}, | ||
}, | ||
Metrics: []Generator{ | ||
{ | ||
Name: "test_metrics", | ||
Help: "metrics for testing", | ||
Each: Metric{ | ||
Type: MetricTypeInfo, | ||
Info: &MetricInfo{ | ||
MetricMeta: MetricMeta{ | ||
Path: []string{ | ||
"metadata", | ||
"annotations", | ||
}, | ||
}, | ||
LabelFromKey: "test", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
v, err := NewCustomResourceMetrics(tt.r) | ||
expectedError := v.(*customResourceMetrics).Families[0].Each.Type() != "info" | ||
if (err != nil) != tt.wantErr || expectedError { | ||
t.Errorf("NewCustomResourceMetrics() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters