Skip to content

Commit 1032430

Browse files
committed
fixup! Handle unit length valueFrom values
1 parent bd2ea7a commit 1032430

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type compiledMetric interface {
143143
Type() metric.Type
144144
}
145145

146-
// newCompiledMetric returns a compiledMetric depending on given the metric type.
146+
// newCompiledMetric returns a compiledMetric depending on the given metric type.
147147
func newCompiledMetric(m Metric) (compiledMetric, error) {
148148
switch m.Type {
149149
case MetricTypeGauge:
@@ -217,6 +217,7 @@ func (c *compiledGauge) Values(v interface{}) (result []eachValue, errs []error)
217217
switch iter := v.(type) {
218218
case map[string]interface{}:
219219
for key, it := range iter {
220+
// TODO: Handle multi-length valueFrom paths (https://github.com/kubernetes/kube-state-metrics/pull/1958#discussion_r1099243161).
220221
// Try to deduce `valueFrom`'s value from the current element.
221222
var ev *eachValue
222223
var err error
@@ -226,7 +227,7 @@ func (c *compiledGauge) Values(v interface{}) (result []eachValue, errs []error)
226227
sValueFrom := c.ValueFrom.String()
227228
// No comma means we're looking at a unit-length path (in an array).
228229
if !strings.Contains(sValueFrom, ",") &&
229-
sValueFrom[0] == '[' &&
230+
sValueFrom[0] == '[' && sValueFrom[len(sValueFrom)-1] == ']' &&
230231
// "[...]" and not "[]".
231232
len(sValueFrom) > 2 {
232233
extractedValueFrom := sValueFrom[1 : len(sValueFrom)-1]

0 commit comments

Comments
 (0)