From 5a6322b4ce92a6bf59f93d26a48d51c97afb4512 Mon Sep 17 00:00:00 2001 From: Aya Igarashi Date: Tue, 11 Aug 2020 20:49:27 +0900 Subject: [PATCH] Fix NaN not to be cast to int64 --- pkg/custom-provider/provider.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/custom-provider/provider.go b/pkg/custom-provider/provider.go index 50fa42d8..814d5650 100644 --- a/pkg/custom-provider/provider.go +++ b/pkg/custom-provider/provider.go @@ -19,6 +19,7 @@ package provider import ( "context" "fmt" + "math" "time" "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider" @@ -83,6 +84,12 @@ func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.Name return nil, err } + var q *resource.Quantity + if math.IsNaN(float64(value)) { + q = resource.NewQuantity(0, resource.DecimalSI) + } else { + q = resource.NewMilliQuantity(int64(value*1000.0), resource.DecimalSI) + } return &custom_metrics.MetricValue{ DescribedObject: ref, Metric: custom_metrics.MetricIdentifier{ @@ -90,7 +97,7 @@ func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.Name }, // TODO(directxman12): use the right timestamp Timestamp: metav1.Time{time.Now()}, - Value: *resource.NewMilliQuantity(int64(value*1000.0), resource.DecimalSI), + Value: *q, }, nil }