Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headerbp needs to be exported to be interopted with #674

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
14 changes: 10 additions & 4 deletions internal/headerbp/headerbp.go → headerbp/headerbp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"fmt"
"strings"
"sync"

//lint:ignore SA1019 This library is internal only, not actually deprecated
"github.com/reddit/baseplate.go/internalv2compat"
)

const (
Expand All @@ -22,6 +19,15 @@ const (
// ErrNewInternalHeaderNotAllowed is returned by a client when the call tries to set an internal header is not allowlisted
var ErrNewInternalHeaderNotAllowed = fmt.Errorf("cannot send new internal headers on requests")

var setHeaderbpV2Context = func(ctx context.Context, _ map[string]string) context.Context {
return ctx
}

// SetV2BaseplateHeadersSetter sets the function to use to set baseplate headers in the v2 library.
func SetV2BaseplateHeadersSetter(setter func(context.Context, map[string]string) context.Context) {
setHeaderbpV2Context = setter
}

// IsBaseplateHeader returns true if the header is for baseplate and should be propagated
func IsBaseplateHeader(key string) bool {
if len(key) < len(headerPrefixLower) {
Expand Down Expand Up @@ -92,7 +98,7 @@ func (h *IncomingHeaders) SetOnContext(ctx context.Context) context.Context {
h.service,
h.method,
).Observe(float64(h.estimatedSizeBytes))
ctx = internalv2compat.SetV2BaseplateHeadersToContext(ctx, h.headers)
ctx = setHeaderbpV2Context(ctx, h.headers)
return HeadersToContext(ctx, h.headers)
}

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions httpbp/client_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (

"github.com/avast/retry-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/reddit/baseplate.go/headerbp"

"github.com/reddit/baseplate.go/breakerbp"
"github.com/reddit/baseplate.go/internal/headerbp"

//lint:ignore SA1019 This library is internal only, not actually deprecated
"github.com/reddit/baseplate.go/internalv2compat"
"github.com/reddit/baseplate.go/retrybp"
Expand Down
2 changes: 1 addition & 1 deletion httpbp/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

"github.com/go-kit/kit/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/reddit/baseplate.go/headerbp"

"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/errorsbp"
"github.com/reddit/baseplate.go/internal/headerbp"
//lint:ignore SA1019 This library is internal only, not actually deprecated
"github.com/reddit/baseplate.go/internalv2compat"
"github.com/reddit/baseplate.go/log"
Expand Down
2 changes: 1 addition & 1 deletion httpbp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/reddit/baseplate.go/headerbp"

"github.com/reddit/baseplate.go"
"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/httpbp"
"github.com/reddit/baseplate.go/internal/headerbp"
"github.com/reddit/baseplate.go/log"
"github.com/reddit/baseplate.go/secrets"
)
Expand Down
13 changes: 0 additions & 13 deletions internalv2compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package internalv2compat

import (
"context"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -138,15 +137,3 @@ func V2TracingHTTPServerMiddleware() func(name string, next http.Handler) http.H
defer v2Tracing.Unlock()
return v2Tracing.httpServerMiddleware
}

var setHeaderbpV2Context = func(ctx context.Context, _ map[string]string) context.Context {
return ctx
}

func SetV2BaseplateHeadersSetter(setter func(context.Context, map[string]string) context.Context) {
setHeaderbpV2Context = setter
}

func SetV2BaseplateHeadersToContext(ctx context.Context, headers map[string]string) context.Context {
return setHeaderbpV2Context(ctx, headers)
}
3 changes: 1 addition & 2 deletions thriftbp/client_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (
"github.com/apache/thrift/lib/go/thrift"
"github.com/avast/retry-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/reddit/baseplate.go/internal/headerbp"

"github.com/reddit/baseplate.go/breakerbp"
"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/errorsbp"
"github.com/reddit/baseplate.go/headerbp"
"github.com/reddit/baseplate.go/internal/gen-go/reddit/baseplate"
"github.com/reddit/baseplate.go/internal/thriftint"

Expand Down
3 changes: 1 addition & 2 deletions thriftbp/client_middlewares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"github.com/apache/thrift/lib/go/thrift"
"github.com/avast/retry-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/reddit/baseplate.go/internal/headerbp"

"github.com/reddit/baseplate.go"
"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/headerbp"
"github.com/reddit/baseplate.go/internal/faults"
baseplatethrift "github.com/reddit/baseplate.go/internal/gen-go/reddit/baseplate"
"github.com/reddit/baseplate.go/internal/prometheusbpint/spectest"
Expand Down
3 changes: 1 addition & 2 deletions thriftbp/server_middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (

"github.com/apache/thrift/lib/go/thrift"
"github.com/prometheus/client_golang/prometheus"
"github.com/reddit/baseplate.go/internal/headerbp"

"github.com/reddit/baseplate.go/ecinterface"
"github.com/reddit/baseplate.go/errorsbp"
"github.com/reddit/baseplate.go/headerbp"
"github.com/reddit/baseplate.go/internal/gen-go/reddit/baseplate"
"github.com/reddit/baseplate.go/internal/thriftint"
//lint:ignore SA1019 This library is internal only, not actually deprecated
Expand Down
2 changes: 1 addition & 1 deletion thriftbp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/apache/thrift/lib/go/thrift"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/reddit/baseplate.go/headerbp"

"github.com/reddit/baseplate.go/ecinterface"
baseplatethrift "github.com/reddit/baseplate.go/internal/gen-go/reddit/baseplate"
"github.com/reddit/baseplate.go/internal/headerbp"
"github.com/reddit/baseplate.go/thriftbp"
"github.com/reddit/baseplate.go/thriftbp/thrifttest"
)
Expand Down
Loading