mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 16:49:01 +08:00
fix: nan and inf values in formula result (#5733)
This commit is contained in:
parent
a20794040a
commit
072693d57d
@ -146,6 +146,10 @@ func joinAndCalculate(
|
|||||||
return nil, fmt.Errorf("expected float64, got %T", newValue)
|
return nil, fmt.Errorf("expected float64, got %T", newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if math.IsNaN(val) || math.IsInf(val, 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
resultSeries.Points = append(resultSeries.Points, v3.Point{
|
resultSeries.Points = append(resultSeries.Points, v3.Point{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Value: val,
|
Value: val,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package postprocess
|
package postprocess
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -207,6 +206,7 @@ func TestProcessResults(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
results []*v3.Result
|
results []*v3.Result
|
||||||
want *v3.Result
|
want *v3.Result
|
||||||
|
expression string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "test1",
|
name: "test1",
|
||||||
@ -288,12 +288,68 @@ func TestProcessResults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expression: "A + B",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "test2",
|
||||||
|
results: []*v3.Result{
|
||||||
|
{
|
||||||
|
QueryName: "A",
|
||||||
|
Series: []*v3.Series{
|
||||||
|
{
|
||||||
|
Labels: map[string]string{},
|
||||||
|
Points: []v3.Point{
|
||||||
|
{
|
||||||
|
Timestamp: 1,
|
||||||
|
Value: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Timestamp: 2,
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
QueryName: "B",
|
||||||
|
Series: []*v3.Series{
|
||||||
|
{
|
||||||
|
Labels: map[string]string{},
|
||||||
|
Points: []v3.Point{
|
||||||
|
{
|
||||||
|
Timestamp: 1,
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Timestamp: 3,
|
||||||
|
Value: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: &v3.Result{
|
||||||
|
Series: []*v3.Series{
|
||||||
|
{
|
||||||
|
Labels: map[string]string{},
|
||||||
|
Points: []v3.Point{
|
||||||
|
{
|
||||||
|
Timestamp: 3,
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expression: "A/B",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
expression, err := govaluate.NewEvaluableExpression("A + B")
|
expression, err := govaluate.NewEvaluableExpression(tt.expression)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error parsing expression: %v", err)
|
t.Errorf("Error parsing expression: %v", err)
|
||||||
}
|
}
|
||||||
@ -835,10 +891,6 @@ func TestFormula(t *testing.T) {
|
|||||||
Timestamp: 5,
|
Timestamp: 5,
|
||||||
Value: 1,
|
Value: 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Timestamp: 7,
|
|
||||||
Value: math.Inf(1),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -855,10 +907,6 @@ func TestFormula(t *testing.T) {
|
|||||||
Timestamp: 2,
|
Timestamp: 2,
|
||||||
Value: 0.6923076923076923,
|
Value: 0.6923076923076923,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Timestamp: 3,
|
|
||||||
Value: math.Inf(1),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Timestamp: 4,
|
Timestamp: 4,
|
||||||
Value: 1,
|
Value: 1,
|
||||||
@ -997,62 +1045,6 @@ func TestFormula(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: &v3.Result{
|
want: &v3.Result{
|
||||||
Series: []*v3.Series{
|
Series: []*v3.Series{
|
||||||
{
|
|
||||||
Labels: map[string]string{
|
|
||||||
"host_name": "ip-10-420-69-1",
|
|
||||||
"state": "running",
|
|
||||||
},
|
|
||||||
Points: []v3.Point{
|
|
||||||
{
|
|
||||||
Timestamp: 1,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 2,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 4,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 5,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 7,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Labels: map[string]string{
|
|
||||||
"host_name": "ip-10-420-69-2",
|
|
||||||
"state": "idle",
|
|
||||||
},
|
|
||||||
Points: []v3.Point{
|
|
||||||
{
|
|
||||||
Timestamp: 1,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 2,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 3,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 4,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 5,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"host_name": "ip-10-420-69-1",
|
"host_name": "ip-10-420-69-1",
|
||||||
@ -1262,39 +1254,6 @@ func TestFormula(t *testing.T) {
|
|||||||
Timestamp: 5,
|
Timestamp: 5,
|
||||||
Value: 1,
|
Value: 1,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Timestamp: 7,
|
|
||||||
Value: math.Inf(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Labels: map[string]string{
|
|
||||||
"host_name": "ip-10-420-69-2",
|
|
||||||
"state": "idle",
|
|
||||||
"os.type": "linux",
|
|
||||||
},
|
|
||||||
Points: []v3.Point{
|
|
||||||
{
|
|
||||||
Timestamp: 1,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 2,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 3,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 4,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Timestamp: 5,
|
|
||||||
Value: math.Inf(0),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1537,10 +1496,6 @@ func TestFormula(t *testing.T) {
|
|||||||
Timestamp: 5,
|
Timestamp: 5,
|
||||||
Value: 51,
|
Value: 51,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Timestamp: 7,
|
|
||||||
Value: math.Inf(1),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1558,10 +1513,6 @@ func TestFormula(t *testing.T) {
|
|||||||
Timestamp: 2,
|
Timestamp: 2,
|
||||||
Value: 45.6923076923076923,
|
Value: 45.6923076923076923,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Timestamp: 3,
|
|
||||||
Value: math.Inf(1),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Timestamp: 4,
|
Timestamp: 4,
|
||||||
Value: 41,
|
Value: 41,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user