forked from aws/amazon-cloudwatch-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop unsupported NaN, Inf, and out of range values. (aws#847)
- Loading branch information
Showing
14 changed files
with
262 additions
and
92 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
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,55 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package util | ||
|
||
import ( | ||
"errors" | ||
"math" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent/metric/distribution/regular" | ||
) | ||
|
||
func TestToOtelValue(t *testing.T) { | ||
distribution := regular.NewRegularDistribution() | ||
testCases := []struct { | ||
input interface{} | ||
want interface{} | ||
wantErr error | ||
}{ | ||
// ints | ||
{input: 5, want: int64(5)}, | ||
{input: int8(5), want: int64(5)}, | ||
{input: int16(5), want: int64(5)}, | ||
{input: int32(5), want: int64(5)}, | ||
{input: int64(5), want: int64(5)}, | ||
// uints | ||
{input: uint(5), want: int64(5)}, | ||
{input: uint8(5), want: int64(5)}, | ||
{input: uint16(5), want: int64(5)}, | ||
{input: uint32(5), want: int64(5)}, | ||
{input: uint64(5), want: int64(5)}, | ||
// floats | ||
{input: float32(5.5), want: 5.5}, | ||
{input: 5.5, want: 5.5}, | ||
// bool | ||
{input: false, want: int64(0)}, | ||
{input: true, want: int64(1)}, | ||
// distribution | ||
{input: distribution, want: distribution}, | ||
// unsupported floats | ||
{input: math.NaN(), want: nil, wantErr: errors.New("unsupported value: NaN")}, | ||
{input: math.Inf(1), want: nil, wantErr: errors.New("unsupported value: +Inf")}, | ||
{input: math.Inf(-1), want: nil, wantErr: errors.New("unsupported value: -Inf")}, | ||
// unsupported types | ||
{input: "test", want: nil, wantErr: errors.New("unsupported type: string")}, | ||
} | ||
for _, testCase := range testCases { | ||
got, err := ToOtelValue(testCase.input) | ||
assert.Equal(t, testCase.wantErr, err) | ||
assert.Equal(t, testCase.want, got) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package distribution | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsAcceptedValue(t *testing.T) { | ||
testCases := []struct { | ||
input float64 | ||
want bool | ||
}{ | ||
{input: MinValue * 1.0001, want: false}, | ||
{input: MinValue, want: true}, | ||
{input: MaxValue, want: true}, | ||
{input: MaxValue * 1.0001, want: false}, | ||
{input: math.Pow(2, 300), want: true}, | ||
{input: math.NaN(), want: false}, | ||
{input: math.Inf(1), want: false}, | ||
{input: math.Inf(-1), want: false}, | ||
} | ||
for _, testCase := range testCases { | ||
assert.Equal(t, testCase.want, IsSupportedValue(testCase.input, MinValue, MaxValue)) | ||
} | ||
} |
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
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
Oops, something went wrong.