mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
Merge pull request #308 from Ladicle/handle-nan
Fix NaN not to be cast to int64
This commit is contained in:
commit
c45a40bec0
1 changed files with 8 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ package provider
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
|
"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
|
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{
|
return &custom_metrics.MetricValue{
|
||||||
DescribedObject: ref,
|
DescribedObject: ref,
|
||||||
Metric: custom_metrics.MetricIdentifier{
|
Metric: custom_metrics.MetricIdentifier{
|
||||||
|
|
@ -90,7 +97,7 @@ func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.Name
|
||||||
},
|
},
|
||||||
// TODO(directxman12): use the right timestamp
|
// TODO(directxman12): use the right timestamp
|
||||||
Timestamp: metav1.Time{time.Now()},
|
Timestamp: metav1.Time{time.Now()},
|
||||||
Value: *resource.NewMilliQuantity(int64(value*1000.0), resource.DecimalSI),
|
Value: *q,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue