mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-11-03 02:20:04 +00:00
- Go module: github.com/SigNoz/signoz-otel-collector → github.com/hanzoai/otel-collector - All signoz-prefixed packages → o11y-prefixed - Docker: signoz/* → ghcr.io/hanzoai/otel-collector - ClickHouse exporter → Hanzo Datastore - Env vars: SIGNOZ_* → HANZO_* - Directory renames for all processor/receiver/exporter packages
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cwmetricstream
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func TestType(t *testing.T) {
|
|
unmarshaler := NewUnmarshaler(zap.NewNop())
|
|
require.Equal(t, TypeStr, unmarshaler.Type())
|
|
}
|
|
|
|
func TestUnmarshal(t *testing.T) {
|
|
unmarshaler := NewUnmarshaler(zap.NewNop())
|
|
testCases := map[string]struct {
|
|
filename string
|
|
wantResourceCount int
|
|
wantMetricCount int
|
|
wantDatapointCount int
|
|
wantErr error
|
|
}{
|
|
"WithMultipleRecords": {
|
|
filename: "multiple_records",
|
|
wantResourceCount: 6,
|
|
// each cwMetric gets converted into 1 gauge per stat value
|
|
// and there are 4 stat values right now
|
|
wantMetricCount: 33 * 4,
|
|
wantDatapointCount: 127 * 4,
|
|
},
|
|
"WithSingleRecord": {
|
|
filename: "single_record",
|
|
wantResourceCount: 1,
|
|
wantMetricCount: 1 * 4,
|
|
wantDatapointCount: 1 * 4,
|
|
},
|
|
"WithInvalidRecords": {
|
|
filename: "invalid_records",
|
|
wantErr: errInvalidRecords,
|
|
},
|
|
"WithSomeInvalidRecords": {
|
|
filename: "some_invalid_records",
|
|
wantResourceCount: 5,
|
|
wantMetricCount: 35 * 4,
|
|
wantDatapointCount: 88 * 4,
|
|
},
|
|
}
|
|
for name, testCase := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
record, err := os.ReadFile(filepath.Join(".", "testdata", testCase.filename))
|
|
require.NoError(t, err)
|
|
|
|
records := [][]byte{record}
|
|
|
|
got, err := unmarshaler.Unmarshal(records)
|
|
if testCase.wantErr != nil {
|
|
require.Error(t, err)
|
|
require.Equal(t, testCase.wantErr, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
require.NotNil(t, got)
|
|
require.Equal(t, testCase.wantResourceCount, got.ResourceMetrics().Len())
|
|
gotMetricCount := 0
|
|
gotDatapointCount := 0
|
|
for i := 0; i < got.ResourceMetrics().Len(); i++ {
|
|
rm := got.ResourceMetrics().At(i)
|
|
require.Equal(t, 1, rm.ScopeMetrics().Len())
|
|
ilm := rm.ScopeMetrics().At(0)
|
|
gotMetricCount += ilm.Metrics().Len()
|
|
for j := 0; j < ilm.Metrics().Len(); j++ {
|
|
metric := ilm.Metrics().At(j)
|
|
gotDatapointCount += metric.Gauge().DataPoints().Len()
|
|
}
|
|
}
|
|
require.Equal(t, testCase.wantMetricCount, gotMetricCount)
|
|
require.Equal(t, testCase.wantDatapointCount, gotDatapointCount)
|
|
}
|
|
})
|
|
}
|
|
}
|