Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ type Config struct {
// New services should leave this false (the default). Set to true only if you
// have existing OpenTracing instrumentation that hasn't been migrated to OTEL.
OTLPUseOpenTracingBridge bool `envconfig:"OTLP_USE_OPENTRACING_BRIDGE" default:"false"`

// Throughput tuning

// DisableHTTPCompression disables gzip/zstd compression for HTTP gateway responses
DisableHTTPCompression bool `envconfig:"DISABLE_HTTP_COMPRESSION" default:"false"`
// HTTPCompressionMinSize is the minimum response body size (bytes) before compression is applied.
// Responses smaller than this are sent uncompressed. Applies to both gzip and zstd.
Comment thread
ankurs marked this conversation as resolved.
HTTPCompressionMinSize int `envconfig:"HTTP_COMPRESSION_MIN_SIZE" default:"256"`
Comment thread
ankurs marked this conversation as resolved.
// ResponseTimeLogLevel sets the log level for per-request response time logging.
// Valid values: "debug", "info", "warn", "error". Invalid values default to "info".
ResponseTimeLogLevel string `envconfig:"RESPONSE_TIME_LOG_LEVEL" default:"info"`
// ResponseTimeLogErrorOnly when true, only logs response time for requests that return an error.
// Successful requests are not logged. Default behavior logs all requests.
ResponseTimeLogErrorOnly bool `envconfig:"RESPONSE_TIME_LOG_ERROR_ONLY" default:"false"`
}

// Validate checks the configuration for common misconfigurations and returns
Expand Down
16 changes: 14 additions & 2 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"golang.org/x/sync/errgroup"

"github.com/go-coldbrew/core/config"
"github.com/go-coldbrew/interceptors"

Check failure on line 20 in core.go

View workflow job for this annotation

GitHub Actions / test

missing go.sum entry for module providing package github.com/go-coldbrew/interceptors (imported by github.com/go-coldbrew/core); to add:

Check failure on line 20 in core.go

View workflow job for this annotation

GitHub Actions / build

missing go.sum entry for module providing package github.com/go-coldbrew/interceptors (imported by github.com/go-coldbrew/core); to add:
"github.com/go-coldbrew/log"
"github.com/go-coldbrew/log/loggers"
"github.com/go-coldbrew/options"
Expand Down Expand Up @@ -111,6 +111,11 @@
if !c.config.DisableAutoMaxProcs {
SetupAutoMaxProcs()
}
// Auto-disable NewRelic when no license key is configured to avoid
// interceptor overhead for services that don't use NR.
if !c.config.DisableNewRelic && c.config.NewRelicLicenseKey == "" {
Comment thread
ankurs marked this conversation as resolved.
Outdated
Comment thread
ankurs marked this conversation as resolved.
Outdated
c.config.DisableNewRelic = true
}
if !c.config.DisableNewRelic {
err := SetupNewRelic(nrName, c.config.NewRelicLicenseKey, c.config.NewRelicDistributedTracing)
if err != nil {
Expand All @@ -121,7 +126,7 @@
SetupEnvironment(c.config.Environment)
SetupReleaseName(c.config.ReleaseName)
SetupHystrixPrometheus()
ConfigureInterceptors(c.config.DoNotLogGRPCReflection, c.config.TraceHeaderName)
ConfigureInterceptors(c.config.DoNotLogGRPCReflection, c.config.TraceHeaderName, c.config.ResponseTimeLogLevel, c.config.ResponseTimeLogErrorOnly)
if !c.config.DisableSignalHandler {
dur := time.Second * 10
if c.config.ShutdownDurationInSeconds > 0 {
Expand Down Expand Up @@ -390,7 +395,14 @@
// Start HTTP server (and proxy calls to gRPC server endpoint)
gatewayAddr := fmt.Sprintf("%s:%d", c.config.ListenHost, c.config.HTTPPort)
promHandler := promhttp.Handler()
gzipHandler := gzhttp.GzipHandler(tracingWrapper(mux))
var gzipHandler http.Handler = tracingWrapper(mux)
if !c.config.DisableHTTPCompression {
wrapper, err := gzhttp.NewWrapper(gzhttp.MinSize(c.config.HTTPCompressionMinSize))
if err != nil {
return nil, fmt.Errorf("failed to create compression handler: %v", err)
Comment thread
ankurs marked this conversation as resolved.
Outdated
}
gzipHandler = wrapper(gzipHandler)
}
Comment thread
ankurs marked this conversation as resolved.
Outdated
gwServer := &http.Server{
Addr: gatewayAddr,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion core_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,5 +1165,5 @@ func TestSetupOpenTelemetry_MissingServiceName(t *testing.T) {
}

func TestConfigureInterceptors_BothBranches(t *testing.T) {
ConfigureInterceptors(true, "X-My-Trace")
ConfigureInterceptors(true, "X-My-Trace", "info", false)
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ github.com/go-coldbrew/errors v0.2.6 h1:rNOI+XcxuyrN/t3e7zDBVUVzcYBNmhyjatsnJg9M
github.com/go-coldbrew/errors v0.2.6/go.mod h1:jFXeN7Q74fggbIEZu/68vhRX1ob2zfc+2sy0osVfBlY=
github.com/go-coldbrew/hystrixprometheus v0.1.2 h1:WSt4FtYr8xNDKgdGWYpMfXGFIK7zdDSBwDSbpuPhBHI=
github.com/go-coldbrew/hystrixprometheus v0.1.2/go.mod h1:OrNRHHxZagpmQXNp//oHKOemGSU0ScOqEcJgeKbJ+wg=
github.com/go-coldbrew/interceptors v0.1.13 h1:YVHOldoe3I1VqtGfAwn0jhpiPmSfA/irVpNJOCFfICc=
github.com/go-coldbrew/interceptors v0.1.13/go.mod h1:brTTe9j2BSpavK0zDqU2cVvIf8LAdMyu+7vNeVsL5Vk=
github.com/go-coldbrew/log v0.2.8 h1:aF+vw23zMyh5S9vhhofERiaPpSDyeJH1Tv1CYREn/a0=
github.com/go-coldbrew/log v0.2.8/go.mod h1:RKvGzMZMt7FpQ9u36adkDigRxkOvRj1diwgAgRJZH4E=
github.com/go-coldbrew/options v0.2.6 h1:Nr93v7PbO+EYLHhzA8biGumaTTSHLHqTYLg70n/foXE=
Expand Down
14 changes: 10 additions & 4 deletions initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ func SetupHystrixPrometheus() {
})
}

// ConfigureInterceptors configures the interceptors package with the provided
// DoNotLogGRPCReflection is a boolean that indicates whether to log the grpc.reflection.v1alpha.ServerReflection service calls in logs
// traceHeaderName is the name of the header to use for tracing (e.g. X-Trace-Id) - if empty, defaults to X-Trace-Id
func ConfigureInterceptors(DoNotLogGRPCReflection bool, traceHeaderName string) {
// ConfigureInterceptors configures the interceptors package with the provided settings.
func ConfigureInterceptors(DoNotLogGRPCReflection bool, traceHeaderName string, responseTimeLogLevel string, responseTimeLogErrorOnly bool) {
if DoNotLogGRPCReflection {
interceptors.FilterMethods = append(
interceptors.FilterMethods,
Expand All @@ -334,6 +332,14 @@ func ConfigureInterceptors(DoNotLogGRPCReflection bool, traceHeaderName string)
if traceHeaderName != "" {
notifier.SetTraceHeaderName(traceHeaderName)
}
if responseTimeLogLevel != "" {
level, err := loggers.ParseLevel(responseTimeLogLevel)
if err != nil {
Comment thread
ankurs marked this conversation as resolved.
level = loggers.InfoLevel
}
interceptors.SetResponseTimeLogLevel(context.Background(), level)
}
interceptors.SetResponseTimeLogErrorOnly(responseTimeLogErrorOnly)
}

// SetupAutoMaxProcs sets up the GOMAXPROCS to match Linux container CPU quota
Expand Down
Loading