Skip to content

Commit

Permalink
[receiver/awsfirehosereceiver] Add otlp_v1 into the unmarshalers map (#…
Browse files Browse the repository at this point in the history
…36125)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

After able to test E2E with
#35750,
I realized `otlp_v1` is still treated as an invalid record type because
it's missing from the unmarshalers map.

This PR is to add it into the map, enhance the error message output to
show the `record_type` and add a test yaml file.
  • Loading branch information
kaiyan-sheng authored Nov 4, 2024
1 parent 908ccf2 commit 58c0120
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .chloggen/add_otlp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component: awsfirehosereceiver
note: make otlp_v1 a valid record type

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35750]
issues: [35750, 36125]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
Expand Down
2 changes: 1 addition & 1 deletion receiver/awsfirehosereceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestLoadConfig(t *testing.T) {
for _, configType := range []string{
"cwmetrics", "cwlogs", "invalid",
"cwmetrics", "cwlogs", "otlp_v1", "invalid",
} {
t.Run(configType, func(t *testing.T) {
fileName := fmt.Sprintf("%s_config.yaml", configType)
Expand Down
4 changes: 3 additions & 1 deletion receiver/awsfirehosereceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func validateRecordType(recordType string) error {
// unmarshalers.
func defaultMetricsUnmarshalers(logger *zap.Logger) map[string]unmarshaler.MetricsUnmarshaler {
cwmsu := cwmetricstream.NewUnmarshaler(logger)
otlpv1msu := otlpmetricstream.NewUnmarshaler(logger)
return map[string]unmarshaler.MetricsUnmarshaler{
cwmsu.Type(): cwmsu,
cwmsu.Type(): cwmsu,
otlpv1msu.Type(): otlpv1msu,
}
}

Expand Down
3 changes: 2 additions & 1 deletion receiver/awsfirehosereceiver/metrics_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package awsfirehosereceiver // import "github.com/open-telemetry/opentelemetry-c

import (
"context"
"fmt"
"net/http"

"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -43,7 +44,7 @@ func newMetricsReceiver(
}
configuredUnmarshaler := unmarshalers[recordType]
if configuredUnmarshaler == nil {
return nil, errUnrecognizedRecordType
return nil, fmt.Errorf("%w: recordType = %s", errUnrecognizedRecordType, recordType)
}

mc := &metricsConsumer{
Expand Down
3 changes: 2 additions & 1 deletion receiver/awsfirehosereceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package awsfirehosereceiver
import (
"context"
"errors"
"fmt"
"net/http"
"testing"

Expand Down Expand Up @@ -43,7 +44,7 @@ func TestNewMetricsReceiver(t *testing.T) {
"WithInvalidRecordType": {
consumer: consumertest.NewNop(),
recordType: "test",
wantErr: errUnrecognizedRecordType,
wantErr: fmt.Errorf("%w: recordType = %s", errUnrecognizedRecordType, "test"),
},
}
for name, testCase := range testCases {
Expand Down
7 changes: 7 additions & 0 deletions receiver/awsfirehosereceiver/testdata/otlp_v1_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
awsfirehose:
endpoint: 0.0.0.0:4433
record_type: otlp_v1
access_key: "some_access_key"
tls:
cert_file: server.crt
key_file: server.key

0 comments on commit 58c0120

Please sign in to comment.