From 565cf34c2450eae8bb8798187a7a8d820b819324 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Thu, 4 Jul 2024 09:13:55 -0700 Subject: [PATCH] feat(debug): exports (#1148) --- internal/debug/httpdriver/metrics.go | 2 +- openmeter/debug/adapters.go | 12 ++++++++++++ openmeter/debug/httpdriver/handlers.go | 19 +++++++++++++++++++ openmeter/debug/httpdriver/types.go | 12 ++++++++++++ openmeter/debug/types.go | 7 +++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 openmeter/debug/adapters.go create mode 100644 openmeter/debug/httpdriver/handlers.go create mode 100644 openmeter/debug/httpdriver/types.go create mode 100644 openmeter/debug/types.go diff --git a/internal/debug/httpdriver/metrics.go b/internal/debug/httpdriver/metrics.go index 581b5ea11..6d212574c 100644 --- a/internal/debug/httpdriver/metrics.go +++ b/internal/debug/httpdriver/metrics.go @@ -65,7 +65,7 @@ func (h *debugHandler) GetMetrics() GetMetricsHandler { commonhttp.PlainTextResponseEncoder[string], httptransport.AppendOptions( h.options, - httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter) bool { + httptransport.WithErrorEncoder(func(ctx context.Context, err error, w http.ResponseWriter, _ *http.Request) bool { if _, ok := err.(*models.GenericUserError); ok { commonhttp.NewHTTPError( http.StatusBadRequest, diff --git a/openmeter/debug/adapters.go b/openmeter/debug/adapters.go new file mode 100644 index 000000000..8c0d314a0 --- /dev/null +++ b/openmeter/debug/adapters.go @@ -0,0 +1,12 @@ +package debug + +import ( + "github.com/openmeterio/openmeter/internal/debug" + "github.com/openmeterio/openmeter/openmeter/streaming" +) + +func NewDebugConnector( + streaming streaming.Connector, +) DebugConnector { + return debug.NewDebugConnector(streaming) +} diff --git a/openmeter/debug/httpdriver/handlers.go b/openmeter/debug/httpdriver/handlers.go new file mode 100644 index 000000000..4887cfbe6 --- /dev/null +++ b/openmeter/debug/httpdriver/handlers.go @@ -0,0 +1,19 @@ +package httpdriver + +import ( + "github.com/openmeterio/openmeter/internal/debug" + "github.com/openmeterio/openmeter/internal/debug/httpdriver" + "github.com/openmeterio/openmeter/openmeter/namespace/namespacedriver" + "github.com/openmeterio/openmeter/pkg/framework/transport/httptransport" +) + +type DebugHandler = httpdriver.DebugHandler +type GetMetricsHandler = httpdriver.GetMetricsHandler + +func NewDebugHandler( + namespaceDecoder namespacedriver.NamespaceDecoder, + connector debug.DebugConnector, + options ...httptransport.HandlerOption, +) DebugHandler { + return httpdriver.NewDebugHandler(namespaceDecoder, connector, options...) +} diff --git a/openmeter/debug/httpdriver/types.go b/openmeter/debug/httpdriver/types.go new file mode 100644 index 000000000..fd291d1fa --- /dev/null +++ b/openmeter/debug/httpdriver/types.go @@ -0,0 +1,12 @@ +package httpdriver + +import "github.com/openmeterio/openmeter/internal/debug/httpdriver" + +// requests +type GetMetricsHandlerRequest = httpdriver.GetMetricsHandlerRequest + +// responses +type GetMetricsHandlerResponse = httpdriver.GetMetricsHandlerResponse + +// params +type GetMetricsHandlerParams = httpdriver.GetMetricsHandlerParams diff --git a/openmeter/debug/types.go b/openmeter/debug/types.go new file mode 100644 index 000000000..7c81832eb --- /dev/null +++ b/openmeter/debug/types.go @@ -0,0 +1,7 @@ +package debug + +import ( + "github.com/openmeterio/openmeter/internal/debug" +) + +type DebugConnector = debug.DebugConnector