Skip to content

Commit

Permalink
[chore] use status type on splunkhecreceiver (#21276)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored May 3, 2023
1 parent fe7b097 commit cbf7218
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
7 changes: 4 additions & 3 deletions receiver/splunkhecreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver/internal/metadata"
)

func TestLoadConfig(t *testing.T) {
Expand All @@ -39,11 +40,11 @@ func TestLoadConfig(t *testing.T) {
expected component.Config
}{
{
id: component.NewID(typeStr),
id: component.NewID(metadata.Type),
expected: createDefaultConfig(),
},
{
id: component.NewIDWithName(typeStr, "allsettings"),
id: component.NewIDWithName(metadata.Type, "allsettings"),
expected: &Config{
HTTPServerSettings: confighttp.HTTPServerSettings{
Endpoint: "localhost:8088",
Expand All @@ -62,7 +63,7 @@ func TestLoadConfig(t *testing.T) {
},
},
{
id: component.NewIDWithName(typeStr, "tls"),
id: component.NewIDWithName(metadata.Type, "tls"),
expected: &Config{
HTTPServerSettings: confighttp.HTTPServerSettings{
Endpoint: ":8088",
Expand Down
5 changes: 1 addition & 4 deletions receiver/splunkhecreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ import (
// This file implements factory for Splunk HEC receiver.

const (
// The value of "type" key in configuration.
typeStr = "splunk_hec"

// Default endpoints to bind to.
defaultEndpoint = ":8088"
)

// NewFactory creates a factory for Splunk HEC receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
typeStr,
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.Stability),
receiver.WithLogs(createLogsReceiver, metadata.Stability))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion receiver/splunkhecreceiver/metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type: splunkhecreceiver
type: splunk_hec

status:
class: receiver
Expand Down
13 changes: 7 additions & 6 deletions receiver/splunkhecreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver/internal/metadata"
)

const (
Expand Down Expand Up @@ -255,7 +256,7 @@ func (r *splunkReceiver) handleRawReq(resp http.ResponseWriter, req *http.Reques
}

if req.ContentLength == 0 {
r.obsrecv.EndLogsOp(ctx, typeStr, 0, nil)
r.obsrecv.EndLogsOp(ctx, metadata.Type, 0, nil)
r.failRequest(ctx, resp, http.StatusBadRequest, noDataRespBody, 0, nil)
return
}
Expand Down Expand Up @@ -286,7 +287,7 @@ func (r *splunkReceiver) handleRawReq(resp http.ResponseWriter, req *http.Reques
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, slLen, consumerErr)
} else {
resp.WriteHeader(http.StatusOK)
r.obsrecv.EndLogsOp(ctx, typeStr, slLen, nil)
r.obsrecv.EndLogsOp(ctx, metadata.Type, slLen, nil)
}
}

Expand Down Expand Up @@ -378,7 +379,7 @@ func (r *splunkReceiver) consumeMetrics(ctx context.Context, events []*splunk.Ev
md, _ := splunkHecToMetricsData(r.settings.Logger, events, resourceCustomizer, r.config)

decodeErr := r.metricsConsumer.ConsumeMetrics(ctx, md)
r.obsrecv.EndMetricsOp(ctx, typeStr, len(events), decodeErr)
r.obsrecv.EndMetricsOp(ctx, metadata.Type, len(events), decodeErr)

if decodeErr != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), decodeErr)
Expand All @@ -400,7 +401,7 @@ func (r *splunkReceiver) consumeLogs(ctx context.Context, events []*splunk.Event
}

decodeErr := r.logsConsumer.ConsumeLogs(ctx, ld)
r.obsrecv.EndLogsOp(ctx, typeStr, len(events), decodeErr)
r.obsrecv.EndLogsOp(ctx, metadata.Type, len(events), decodeErr)
if decodeErr != nil {
r.failRequest(ctx, resp, http.StatusInternalServerError, errInternalServerError, len(events), decodeErr)
} else {
Expand Down Expand Up @@ -443,9 +444,9 @@ func (r *splunkReceiver) failRequest(
}

if r.metricsConsumer == nil {
r.obsrecv.EndLogsOp(ctx, typeStr, numRecordsReceived, err)
r.obsrecv.EndLogsOp(ctx, metadata.Type, numRecordsReceived, err)
} else {
r.obsrecv.EndMetricsOp(ctx, typeStr, numRecordsReceived, err)
r.obsrecv.EndMetricsOp(ctx, metadata.Type, numRecordsReceived, err)
}

if r.settings.Logger.Core().Enabled(zap.DebugLevel) {
Expand Down

0 comments on commit cbf7218

Please sign in to comment.