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

jaegerremote: Add WithSamplingStrategyFetcher option #4045

Merged
merged 16 commits into from Sep 29, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `NewMiddleware` function in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#2964)
- The `go.opentelemetry.io/contrib/exporters/autoexport` package to provide configuration of trace exporters with useful defaults and environment variable support. (#2753, #4100, #4130, #4132, #4134)
- `WithRouteTag` in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` adds HTTP route attribute to metrics. (#615)
- Add `WithSamplingStrategyFetcher` which sets custom fetcher implementation. (#4045)
- Add `WithSpanOptions` option in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#3768)
- Add testing support for Go 1.21. (#4233)

Expand Down
4 changes: 2 additions & 2 deletions samplers/jaegerremote/sampler_remote.go
Expand Up @@ -39,8 +39,8 @@ const (
defaultSamplingOperationNameLateBinding = true
)

// samplingStrategyFetcher is used to fetch sampling strategy updates from remote server.
type samplingStrategyFetcher interface {
// SamplingStrategyFetcher is used to fetch sampling strategy updates from remote server.
type SamplingStrategyFetcher interface {
Fetch(service string) ([]byte, error)
}

Expand Down
4 changes: 2 additions & 2 deletions samplers/jaegerremote/sampler_remote_options.go
Expand Up @@ -28,7 +28,7 @@ type config struct {
sampler trace.Sampler
samplingServerURL string
samplingRefreshInterval time.Duration
samplingFetcher samplingStrategyFetcher
samplingFetcher SamplingStrategyFetcher
samplingParser samplingStrategyParser
updaters []samplerUpdater
posParams perOperationSamplerParams
Expand Down Expand Up @@ -124,7 +124,7 @@ func WithLogger(logger logr.Logger) Option {
}

// samplingStrategyFetcher creates a Option that initializes sampling strategy fetcher.
morus12 marked this conversation as resolved.
Show resolved Hide resolved
func withSamplingStrategyFetcher(fetcher samplingStrategyFetcher) Option {
func WithSamplingStrategyFetcher(fetcher SamplingStrategyFetcher) Option {
return optionFunc(func(c *config) {
c.samplingFetcher = fetcher
})
Expand Down
20 changes: 17 additions & 3 deletions samplers/jaegerremote/sampler_remote_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"net/http"
"sync"
"testing"
"time"
Expand All @@ -46,7 +47,7 @@ func TestRemotelyControlledSampler_updateConcurrentSafe(t *testing.T) {
WithInitialSampler(initSampler),
WithSamplingServerURL("my url"),
WithSamplingRefreshInterval(time.Millisecond),
withSamplingStrategyFetcher(fetcher),
WithSamplingStrategyFetcher(fetcher),
withSamplingStrategyParser(parser),
withUpdaters(updaters...),
)
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestRemoteSamplerOptions(t *testing.T) {
WithInitialSampler(initSampler),
WithSamplingServerURL("my url"),
WithSamplingRefreshInterval(42*time.Second),
withSamplingStrategyFetcher(fetcher),
WithSamplingStrategyFetcher(fetcher),
withSamplingStrategyParser(parser),
withUpdaters(updaters...),
WithLogger(logger),
Expand Down Expand Up @@ -302,7 +303,7 @@ func TestRemotelyControlledSampler_ImmediatelyUpdateOnStartup(t *testing.T) {
WithInitialSampler(initSampler),
WithSamplingServerURL("my url"),
WithSamplingRefreshInterval(10*time.Minute),
withSamplingStrategyFetcher(fetcher),
WithSamplingStrategyFetcher(fetcher),
withSamplingStrategyParser(parser),
withUpdaters(updaters...),
)
Expand Down Expand Up @@ -586,3 +587,16 @@ func TestSamplingStrategyParserImpl_Error(t *testing.T) {
require.Error(t, err, "output: %+v", val)
require.Contains(t, err.Error(), `unknown value "foo_bar"`)
}

func TestDefaultSamplingStrategyFetcher_Panic(t *testing.T) {
defaultTransport := http.DefaultTransport
http.DefaultTransport = http.NewFileTransport(http.Dir("/"))

t.Cleanup(func() {
http.DefaultTransport = defaultTransport
})

require.Panics(t, func() {
morus12 marked this conversation as resolved.
Show resolved Hide resolved
newHTTPSamplingStrategyFetcher("")
})
}