From e922abe9cbf9cfe0b748206b3f395401168ff8a9 Mon Sep 17 00:00:00 2001 From: Sindy Li Date: Fri, 6 Sep 2024 00:53:35 -0700 Subject: [PATCH] [exporter] [chore] move exporter.exporterhelper.request to internal (#11042) #### Description This PR moves `exporter/exporterhelper/request.go` to `exporter/internal/request.go` to avoid circular dependency. Context: As part of the effort to move from a queue->batch pushing model to a queue->batch pulling model in exporter, we will be depending on `Request` from `exporter/exporterbatcher`. However, `exporter/exporterhelper` already depends on `exporter/exporterbatcher`, so we need to move `Request` out of `exporter/exporterhelper` #### Link to tracking issue https://github.com/open-telemetry/opentelemetry-collector/issues/10368 #### Testing Ran `opentelemetry-collector$ make` to make sure all tests still pass. --- exporter/exporterhelper/exporterhelper.go | 24 +++++++++++++++++++ .../{exporterhelper => internal}/request.go | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 exporter/exporterhelper/exporterhelper.go rename exporter/{exporterhelper => internal}/request.go (92%) diff --git a/exporter/exporterhelper/exporterhelper.go b/exporter/exporterhelper/exporterhelper.go new file mode 100644 index 00000000000..0890ec71af1 --- /dev/null +++ b/exporter/exporterhelper/exporterhelper.go @@ -0,0 +1,24 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package exporterhelper // import "go.opentelemetry.io/collector/exporter/exporterhelper" +import "go.opentelemetry.io/collector/exporter/internal" + +// Request represents a single request that can be sent to an external endpoint. +// Experimental: This API is at the early stage of development and may change without backward compatibility +// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. +type Request = internal.Request + +// RequestErrorHandler is an optional interface that can be implemented by Request to provide a way handle partial +// temporary failures. For example, if some items failed to process and can be retried, this interface allows to +// return a new Request that contains the items left to be sent. Otherwise, the original Request should be returned. +// If not implemented, the original Request will be returned assuming the error is applied to the whole Request. +// Experimental: This API is at the early stage of development and may change without backward compatibility +// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. +type RequestErrorHandler = internal.RequestErrorHandler + +// extractPartialRequest returns a new Request that may contain the items left to be sent +// if only some items failed to process and can be retried. Otherwise, it returns the original Request. +func extractPartialRequest(req Request, err error) Request { + return internal.ExtractPartialRequest(req, err) +} diff --git a/exporter/exporterhelper/request.go b/exporter/internal/request.go similarity index 92% rename from exporter/exporterhelper/request.go rename to exporter/internal/request.go index 74f0186541f..319f9946f95 100644 --- a/exporter/exporterhelper/request.go +++ b/exporter/internal/request.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package exporterhelper // import "go.opentelemetry.io/collector/exporter/exporterhelper" +package internal // import "go.opentelemetry.io/collector/exporter/internal" import ( "context" @@ -34,7 +34,7 @@ type RequestErrorHandler interface { // extractPartialRequest returns a new Request that may contain the items left to be sent // if only some items failed to process and can be retried. Otherwise, it returns the original Request. -func extractPartialRequest(req Request, err error) Request { +func ExtractPartialRequest(req Request, err error) Request { if errReq, ok := req.(RequestErrorHandler); ok { return errReq.OnError(err) }