From d8185ac6e8fc95770341ff7bab76a47b86c52b1f Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Mon, 17 Jun 2024 10:53:09 -0400 Subject: [PATCH] Rename strategy store to sampling strategy provider (#5634) ## Which problem is this PR solving? - The original naming was confusing, as both static & adaptive implementations were returning, but not storing the sampling strategies. There was also another confusion between "strategy store" (aka provider) and "sampling store" (an actual storage that records throughputs and calculated strategies but only for adaptive sampling). ## Description of the changes - Rename packages, interfaces, methods, and variables - Move `calculationstrategy` package inside `adaptive` as it's not used anywhere else ## How was this change tested? - `go run ./cmd/collector` and `go run ./cmd/all-in-one` must compile Signed-off-by: Yuri Shkuro --- cmd/all-in-one/main.go | 38 +++--- cmd/collector/app/collector.go | 78 ++++++------ cmd/collector/app/collector_test.go | 72 +++++------ cmd/collector/app/sampling/grpc_handler.go | 10 +- .../empty_test.go | 2 +- .../factory.go | 8 +- .../interface.go | 6 +- cmd/collector/app/server/grpc.go | 6 +- cmd/collector/app/server/grpc_test.go | 28 ++--- cmd/collector/app/server/http.go | 18 +-- cmd/collector/app/server/http_test.go | 26 ++-- cmd/collector/app/server/test.go | 6 +- cmd/collector/main.go | 38 +++--- cmd/internal/env/command.go | 8 +- pkg/clientcfg/clientcfghttp/cfgmgr.go | 8 +- pkg/clientcfg/clientcfghttp/cfgmgr_test.go | 8 +- pkg/clientcfg/clientcfghttp/handler_test.go | 32 ++--- .../adaptive/aggregator.go | 4 +- .../adaptive/aggregator_test.go | 0 .../adaptive/cache.go | 0 .../adaptive/cache_test.go | 0 .../calculationstrategy/interface.go | 0 .../calculationstrategy/interface_test.go | 0 .../calculationstrategy/package_test.go | 0 .../percentage_increase_capped_calculator.go | 0 ...centage_increase_capped_calculator_test.go | 0 .../adaptive/factory.go | 17 +-- .../adaptive/factory_test.go | 8 +- .../adaptive/floatutils.go | 0 .../adaptive/floatutils_test.go | 0 .../adaptive/options.go | 0 .../adaptive/options_test.go | 0 .../adaptive/package_test.go | 0 .../adaptive/processor.go | 14 +-- .../adaptive/processor_test.go | 10 +- .../adaptive/provider.go} | 12 +- .../adaptive/weightvectorcache.go | 0 .../adaptive/weightvectorcache_test.go | 0 .../factory.go | 29 +++-- .../factory_config.go | 2 +- .../factory_config_test.go | 2 +- .../factory_test.go | 12 +- .../package_test.go | 2 +- .../static/constants.go | 0 .../static/factory.go | 12 +- .../static/factory_test.go | 4 +- ...StrategiesDeprecatedBehavior_ServiceA.json | 0 ...StrategiesDeprecatedBehavior_ServiceB.json | 0 ...viceNoPerOperationStrategies_ServiceA.json | 0 ...viceNoPerOperationStrategies_ServiceB.json | 0 .../static/fixtures/bad_strategies.json | 0 .../fixtures/missing-service-types.json | 0 .../static/fixtures/operation_strategies.json | 0 .../fixtures/service_no_per_operation.json | 0 .../static/fixtures/strategies.json | 0 .../static/options.go | 0 .../static/package_test.go | 0 .../static/provider.go} | 34 +++--- .../static/provider_test.go} | 112 +++++++++--------- .../static/strategy.go | 0 60 files changed, 336 insertions(+), 330 deletions(-) rename cmd/collector/app/sampling/{strategystore => samplingstrategy}/empty_test.go (96%) rename cmd/collector/app/sampling/{strategystore => samplingstrategy}/factory.go (83%) rename cmd/collector/app/sampling/{strategystore => samplingstrategy}/interface.go (93%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/aggregator.go (97%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/aggregator_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/cache.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/cache_test.go (100%) rename plugin/sampling/{ => strategyprovider/adaptive}/calculationstrategy/interface.go (100%) rename plugin/sampling/{ => strategyprovider/adaptive}/calculationstrategy/interface_test.go (100%) rename plugin/sampling/{ => strategyprovider/adaptive}/calculationstrategy/package_test.go (100%) rename plugin/sampling/{ => strategyprovider/adaptive}/calculationstrategy/percentage_increase_capped_calculator.go (100%) rename plugin/sampling/{ => strategyprovider/adaptive}/calculationstrategy/percentage_increase_capped_calculator_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/factory.go (84%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/factory_test.go (96%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/floatutils.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/floatutils_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/options.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/options_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/package_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/processor.go (97%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/processor_test.go (99%) rename plugin/sampling/{strategystore/adaptive/strategy_store.go => strategyprovider/adaptive/provider.go} (87%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/weightvectorcache.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/adaptive/weightvectorcache_test.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/factory.go (76%) rename plugin/sampling/{strategystore => strategyprovider}/factory_config.go (98%) rename plugin/sampling/{strategystore => strategyprovider}/factory_config_test.go (98%) rename plugin/sampling/{strategystore => strategyprovider}/factory_test.go (94%) rename plugin/sampling/{strategystore => strategyprovider}/package_test.go (96%) rename plugin/sampling/{strategystore => strategyprovider}/static/constants.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/factory.go (79%) rename plugin/sampling/{strategystore => strategyprovider}/static/factory_test.go (95%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceA.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceB.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/TestServiceNoPerOperationStrategies_ServiceA.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/TestServiceNoPerOperationStrategies_ServiceB.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/bad_strategies.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/missing-service-types.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/operation_strategies.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/service_no_per_operation.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/fixtures/strategies.json (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/options.go (100%) rename plugin/sampling/{strategystore => strategyprovider}/static/package_test.go (100%) rename plugin/sampling/{strategystore/static/strategy_store.go => strategyprovider/static/provider.go} (89%) rename plugin/sampling/{strategystore/static/strategy_store_test.go => strategyprovider/static/provider_test.go} (81%) rename plugin/sampling/{strategystore => strategyprovider}/static/strategy.go (100%) diff --git a/cmd/all-in-one/main.go b/cmd/all-in-one/main.go index 7a1cae101f3..185c74a74ab 100644 --- a/cmd/all-in-one/main.go +++ b/cmd/all-in-one/main.go @@ -46,7 +46,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/pkg/version" metricsPlugin "github.com/jaegertracing/jaeger/plugin/metrics" - ss "github.com/jaegertracing/jaeger/plugin/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider" "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" "github.com/jaegertracing/jaeger/storage/dependencystore" @@ -68,13 +68,13 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } - strategyStoreFactoryConfig, err := ss.FactoryConfigFromEnv() + samplingStrategyFactoryConfig, err := ss.FactoryConfigFromEnv() if err != nil { - log.Fatalf("Cannot initialize sampling strategy store factory config: %v", err) + log.Fatalf("Cannot initialize sampling strategy factory config: %v", err) } - strategyStoreFactory, err := ss.NewFactory(*strategyStoreFactoryConfig) + samplingStrategyFactory, err := ss.NewFactory(*samplingStrategyFactoryConfig) if err != nil { - log.Fatalf("Cannot initialize sampling strategy store factory: %v", err) + log.Fatalf("Cannot initialize sampling strategy factory: %v", err) } fc := metricsPlugin.FactoryConfigFromEnv() @@ -133,13 +133,13 @@ by default uses only in-memory database.`, logger.Fatal("Failed to create sampling store factory", zap.Error(err)) } - strategyStoreFactory.InitFromViper(v, logger) - if err := strategyStoreFactory.Initialize(collectorMetricsFactory, ssFactory, logger); err != nil { - logger.Fatal("Failed to init sampling strategy store factory", zap.Error(err)) + samplingStrategyFactory.InitFromViper(v, logger) + if err := samplingStrategyFactory.Initialize(collectorMetricsFactory, ssFactory, logger); err != nil { + logger.Fatal("Failed to init sampling strategy factory", zap.Error(err)) } - strategyStore, aggregator, err := strategyStoreFactory.CreateStrategyStore() + samplingProvider, samplingAggregator, err := samplingStrategyFactory.CreateStrategyProvider() if err != nil { - logger.Fatal("Failed to create sampling strategy store", zap.Error(err)) + logger.Fatal("Failed to create sampling strategy provider", zap.Error(err)) } aOpts := new(agentApp.Builder).InitFromViper(v) @@ -161,14 +161,14 @@ by default uses only in-memory database.`, // collector c := collectorApp.New(&collectorApp.CollectorParams{ - ServiceName: "jaeger-collector", - Logger: logger, - MetricsFactory: collectorMetricsFactory, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - Aggregator: aggregator, - HealthCheck: svc.HC(), - TenancyMgr: tm, + ServiceName: "jaeger-collector", + Logger: logger, + MetricsFactory: collectorMetricsFactory, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + SamplingAggregator: samplingAggregator, + HealthCheck: svc.HC(), + TenancyMgr: tm, }) if err := c.Start(cOpts); err != nil { log.Fatal(err) @@ -238,7 +238,7 @@ by default uses only in-memory database.`, agentGrpcRep.AddFlags, collectorFlags.AddFlags, queryApp.AddFlags, - strategyStoreFactory.AddFlags, + samplingStrategyFactory.AddFlags, metricsReaderFactory.AddFlags, ) diff --git a/cmd/collector/app/collector.go b/cmd/collector/app/collector.go index 68b3cac8bb9..e32748868fd 100644 --- a/cmd/collector/app/collector.go +++ b/cmd/collector/app/collector.go @@ -28,7 +28,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/flags" "github.com/jaegertracing/jaeger/cmd/collector/app/handler" "github.com/jaegertracing/jaeger/cmd/collector/app/processor" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/cmd/collector/app/server" "github.com/jaegertracing/jaeger/internal/safeexpvar" "github.com/jaegertracing/jaeger/model" @@ -46,16 +46,16 @@ const ( // Collector returns the collector as a manageable unit of work type Collector struct { // required to start a new collector - serviceName string - logger *zap.Logger - metricsFactory metrics.Factory - spanWriter spanstore.Writer - strategyStore strategystore.StrategyStore - aggregator strategystore.Aggregator - hCheck *healthcheck.HealthCheck - spanProcessor processor.SpanProcessor - spanHandlers *SpanHandlers - tenancyMgr *tenancy.Manager + serviceName string + logger *zap.Logger + metricsFactory metrics.Factory + spanWriter spanstore.Writer + samplingProvider samplingstrategy.Provider + samplingAggregator samplingstrategy.Aggregator + hCheck *healthcheck.HealthCheck + spanProcessor processor.SpanProcessor + spanHandlers *SpanHandlers + tenancyMgr *tenancy.Manager // state, read only hServer *http.Server @@ -69,27 +69,27 @@ type Collector struct { // CollectorParams to construct a new Jaeger Collector. type CollectorParams struct { - ServiceName string - Logger *zap.Logger - MetricsFactory metrics.Factory - SpanWriter spanstore.Writer - StrategyStore strategystore.StrategyStore - Aggregator strategystore.Aggregator - HealthCheck *healthcheck.HealthCheck - TenancyMgr *tenancy.Manager + ServiceName string + Logger *zap.Logger + MetricsFactory metrics.Factory + SpanWriter spanstore.Writer + SamplingProvider samplingstrategy.Provider + SamplingAggregator samplingstrategy.Aggregator + HealthCheck *healthcheck.HealthCheck + TenancyMgr *tenancy.Manager } // New constructs a new collector component, ready to be started func New(params *CollectorParams) *Collector { return &Collector{ - serviceName: params.ServiceName, - logger: params.Logger, - metricsFactory: params.MetricsFactory, - spanWriter: params.SpanWriter, - strategyStore: params.StrategyStore, - aggregator: params.Aggregator, - hCheck: params.HealthCheck, - tenancyMgr: params.TenancyMgr, + serviceName: params.ServiceName, + logger: params.Logger, + metricsFactory: params.MetricsFactory, + spanWriter: params.SpanWriter, + samplingProvider: params.SamplingProvider, + samplingAggregator: params.SamplingAggregator, + hCheck: params.HealthCheck, + tenancyMgr: params.TenancyMgr, } } @@ -104,9 +104,9 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { } var additionalProcessors []ProcessSpan - if c.aggregator != nil { + if c.samplingAggregator != nil { additionalProcessors = append(additionalProcessors, func(span *model.Span, _ /* tenant */ string) { - c.aggregator.HandleRootSpan(span, c.logger) + c.samplingAggregator.HandleRootSpan(span, c.logger) }) } @@ -117,7 +117,7 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { HostPort: options.GRPC.HostPort, Handler: c.spanHandlers.GRPCHandler, TLSConfig: options.GRPC.TLS, - SamplingStore: c.strategyStore, + SamplingProvider: c.samplingProvider, Logger: c.logger, MaxReceiveMessageLength: options.GRPC.MaxReceiveMessageLength, MaxConnectionAge: options.GRPC.MaxConnectionAge, @@ -129,13 +129,13 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { c.grpcServer = grpcServer httpServer, err := server.StartHTTPServer(&server.HTTPServerParams{ - HostPort: options.HTTP.HostPort, - Handler: c.spanHandlers.JaegerBatchesHandler, - TLSConfig: options.HTTP.TLS, - HealthCheck: c.hCheck, - MetricsFactory: c.metricsFactory, - SamplingStore: c.strategyStore, - Logger: c.logger, + HostPort: options.HTTP.HostPort, + Handler: c.spanHandlers.JaegerBatchesHandler, + TLSConfig: options.HTTP.TLS, + HealthCheck: c.hCheck, + MetricsFactory: c.metricsFactory, + SamplingProvider: c.samplingProvider, + Logger: c.logger, }) if err != nil { return fmt.Errorf("could not start HTTP server: %w", err) @@ -213,8 +213,8 @@ func (c *Collector) Close() error { } // aggregator does not exist for all strategy stores. only Close() if exists. - if c.aggregator != nil { - if err := c.aggregator.Close(); err != nil { + if c.samplingAggregator != nil { + if err := c.samplingAggregator.Close(); err != nil { c.logger.Error("failed to close aggregator.", zap.Error(err)) } } diff --git a/cmd/collector/app/collector_test.go b/cmd/collector/app/collector_test.go index 84eb3718015..413c7c46e7a 100644 --- a/cmd/collector/app/collector_test.go +++ b/cmd/collector/app/collector_test.go @@ -75,17 +75,17 @@ func TestNewCollector(t *testing.T) { baseMetrics := metricstest.NewFactory(time.Hour) defer baseMetrics.Backend.Stop() spanWriter := &fakeSpanWriter{} - strategyStore := &mockStrategyStore{} + samplingProvider := &mockSamplingProvider{} tm := &tenancy.Manager{} c := New(&CollectorParams{ - ServiceName: "collector", - Logger: logger, - MetricsFactory: baseMetrics, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - HealthCheck: hc, - TenancyMgr: tm, + ServiceName: "collector", + Logger: logger, + MetricsFactory: baseMetrics, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + HealthCheck: hc, + TenancyMgr: tm, }) collectorOpts := optionsForEphemeralPorts() @@ -102,17 +102,17 @@ func TestCollector_StartErrors(t *testing.T) { baseMetrics := metricstest.NewFactory(time.Hour) defer baseMetrics.Backend.Stop() spanWriter := &fakeSpanWriter{} - strategyStore := &mockStrategyStore{} + samplingProvider := &mockSamplingProvider{} tm := &tenancy.Manager{} c := New(&CollectorParams{ - ServiceName: "collector", - Logger: logger, - MetricsFactory: baseMetrics, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - HealthCheck: hc, - TenancyMgr: tm, + ServiceName: "collector", + Logger: logger, + MetricsFactory: baseMetrics, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + HealthCheck: hc, + TenancyMgr: tm, }) err := c.Start(options) require.Error(t, err) @@ -144,13 +144,13 @@ func TestCollector_StartErrors(t *testing.T) { run("OTLP/HTTP", options, "could not start OTLP receiver") } -type mockStrategyStore struct{} +type mockSamplingProvider struct{} -func (*mockStrategyStore) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { +func (*mockSamplingProvider) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { return &api_v2.SamplingStrategyResponse{}, nil } -func (*mockStrategyStore) Close() error { +func (*mockSamplingProvider) Close() error { return nil } @@ -161,17 +161,17 @@ func TestCollector_PublishOpts(t *testing.T) { metricsFactory := metricstest.NewFactory(time.Second) defer metricsFactory.Backend.Stop() spanWriter := &fakeSpanWriter{} - strategyStore := &mockStrategyStore{} + samplingProvider := &mockSamplingProvider{} tm := &tenancy.Manager{} c := New(&CollectorParams{ - ServiceName: "collector", - Logger: logger, - MetricsFactory: metricsFactory, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - HealthCheck: hc, - TenancyMgr: tm, + ServiceName: "collector", + Logger: logger, + MetricsFactory: metricsFactory, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + HealthCheck: hc, + TenancyMgr: tm, }) collectorOpts := optionsForEphemeralPorts() collectorOpts.NumWorkers = 24 @@ -191,19 +191,19 @@ func TestAggregator(t *testing.T) { baseMetrics := metricstest.NewFactory(time.Hour) defer baseMetrics.Backend.Stop() spanWriter := &fakeSpanWriter{} - strategyStore := &mockStrategyStore{} + samplingProvider := &mockSamplingProvider{} agg := &mockAggregator{} tm := &tenancy.Manager{} c := New(&CollectorParams{ - ServiceName: "collector", - Logger: logger, - MetricsFactory: baseMetrics, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - HealthCheck: hc, - Aggregator: agg, - TenancyMgr: tm, + ServiceName: "collector", + Logger: logger, + MetricsFactory: baseMetrics, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + HealthCheck: hc, + SamplingAggregator: agg, + TenancyMgr: tm, }) collectorOpts := optionsForEphemeralPorts() collectorOpts.NumWorkers = 10 diff --git a/cmd/collector/app/sampling/grpc_handler.go b/cmd/collector/app/sampling/grpc_handler.go index 1110bf37497..50427ee7494 100644 --- a/cmd/collector/app/sampling/grpc_handler.go +++ b/cmd/collector/app/sampling/grpc_handler.go @@ -17,23 +17,23 @@ package sampling import ( "context" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) // GRPCHandler is sampling strategy handler for gRPC. type GRPCHandler struct { - store strategystore.StrategyStore + samplingProvider samplingstrategy.Provider } // NewGRPCHandler creates a handler that controls sampling strategies for services. -func NewGRPCHandler(store strategystore.StrategyStore) GRPCHandler { +func NewGRPCHandler(provider samplingstrategy.Provider) GRPCHandler { return GRPCHandler{ - store: store, + samplingProvider: provider, } } // GetSamplingStrategy returns sampling decision from store. func (s GRPCHandler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) { - return s.store.GetSamplingStrategy(ctx, param.GetServiceName()) + return s.samplingProvider.GetSamplingStrategy(ctx, param.GetServiceName()) } diff --git a/cmd/collector/app/sampling/strategystore/empty_test.go b/cmd/collector/app/sampling/samplingstrategy/empty_test.go similarity index 96% rename from cmd/collector/app/sampling/strategystore/empty_test.go rename to cmd/collector/app/sampling/samplingstrategy/empty_test.go index 268682b4400..73c514c15e7 100644 --- a/cmd/collector/app/sampling/strategystore/empty_test.go +++ b/cmd/collector/app/sampling/samplingstrategy/empty_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package samplingstrategy import ( "testing" diff --git a/cmd/collector/app/sampling/strategystore/factory.go b/cmd/collector/app/sampling/samplingstrategy/factory.go similarity index 83% rename from cmd/collector/app/sampling/strategystore/factory.go rename to cmd/collector/app/sampling/samplingstrategy/factory.go index 4a4059c4f5f..353512b0f72 100644 --- a/cmd/collector/app/sampling/strategystore/factory.go +++ b/cmd/collector/app/sampling/samplingstrategy/factory.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package samplingstrategy import ( "go.uber.org/zap" @@ -21,7 +21,7 @@ import ( "github.com/jaegertracing/jaeger/storage" ) -// Factory defines an interface for a factory that can create implementations of different strategy storage components. +// Factory defines an interface for a factory that can create implementations of different sampling strategy components. // Implementations are also encouraged to implement plugin.Configurable interface. // // # See also @@ -31,8 +31,8 @@ type Factory interface { // Initialize performs internal initialization of the factory. Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error - // CreateStrategyStore initializes the StrategyStore and returns it. - CreateStrategyStore() (StrategyStore, Aggregator, error) + // CreateStrategyProvider initializes and returns Provider and optionallty Aggregator. + CreateStrategyProvider() (Provider, Aggregator, error) // Close closes the factory Close() error diff --git a/cmd/collector/app/sampling/strategystore/interface.go b/cmd/collector/app/sampling/samplingstrategy/interface.go similarity index 93% rename from cmd/collector/app/sampling/strategystore/interface.go rename to cmd/collector/app/sampling/samplingstrategy/interface.go index 9d2c3fb271b..4b599dd3060 100644 --- a/cmd/collector/app/sampling/strategystore/interface.go +++ b/cmd/collector/app/sampling/samplingstrategy/interface.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package samplingstrategy import ( "context" @@ -24,8 +24,8 @@ import ( "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) -// StrategyStore keeps track of service specific sampling strategies. -type StrategyStore interface { +// Provider keeps track of service specific sampling strategies. +type Provider interface { // Close() from io.Closer stops the processor from calculating probabilities. io.Closer diff --git a/cmd/collector/app/server/grpc.go b/cmd/collector/app/server/grpc.go index bbd8bca4ae3..d81fdb7ebf6 100644 --- a/cmd/collector/app/server/grpc.go +++ b/cmd/collector/app/server/grpc.go @@ -29,7 +29,7 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/handler" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) @@ -39,7 +39,7 @@ type GRPCServerParams struct { TLSConfig tlscfg.Options HostPort string Handler *handler.GRPCHandler - SamplingStore strategystore.StrategyStore + SamplingProvider samplingstrategy.Provider Logger *zap.Logger OnError func(error) MaxReceiveMessageLength int @@ -94,7 +94,7 @@ func serveGRPC(server *grpc.Server, listener net.Listener, params *GRPCServerPar healthServer := health.NewServer() api_v2.RegisterCollectorServiceServer(server, params.Handler) - api_v2.RegisterSamplingManagerServer(server, sampling.NewGRPCHandler(params.SamplingStore)) + api_v2.RegisterSamplingManagerServer(server, sampling.NewGRPCHandler(params.SamplingProvider)) healthServer.SetServingStatus("jaeger.api_v2.CollectorService", grpc_health_v1.HealthCheckResponse_SERVING) healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING) diff --git a/cmd/collector/app/server/grpc_test.go b/cmd/collector/app/server/grpc_test.go index 7aad04daa97..487c6bc0216 100644 --- a/cmd/collector/app/server/grpc_test.go +++ b/cmd/collector/app/server/grpc_test.go @@ -39,10 +39,10 @@ import ( func TestFailToListen(t *testing.T) { logger, _ := zap.NewDevelopment() server, err := StartGRPCServer(&GRPCServerParams{ - HostPort: ":-1", - Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingStore: &mockSamplingStore{}, - Logger: logger, + HostPort: ":-1", + Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), + SamplingProvider: &mockSamplingProvider{}, + Logger: logger, }) assert.Nil(t, server) require.EqualError(t, err, "failed to listen on gRPC port: listen tcp: address -1: invalid port") @@ -59,9 +59,9 @@ func TestFailServe(t *testing.T) { server := grpc.NewServer() defer server.Stop() serveGRPC(server, lis, &GRPCServerParams{ - Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingStore: &mockSamplingStore{}, - Logger: logger, + Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), + SamplingProvider: &mockSamplingProvider{}, + Logger: logger, OnError: func(_ error) { assert.Len(t, logs.All(), 1) assert.Equal(t, "Could not launch gRPC service", logs.All()[0].Message) @@ -75,7 +75,7 @@ func TestSpanCollector(t *testing.T) { logger, _ := zap.NewDevelopment() params := &GRPCServerParams{ Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingStore: &mockSamplingStore{}, + SamplingProvider: &mockSamplingProvider{}, Logger: logger, MaxReceiveMessageLength: 1024 * 1024, } @@ -99,9 +99,9 @@ func TestSpanCollector(t *testing.T) { func TestCollectorStartWithTLS(t *testing.T) { logger, _ := zap.NewDevelopment() params := &GRPCServerParams{ - Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingStore: &mockSamplingStore{}, - Logger: logger, + Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), + SamplingProvider: &mockSamplingProvider{}, + Logger: logger, TLSConfig: tlscfg.Options{ Enabled: true, CertPath: testCertKeyLocation + "/example-server-cert.pem", @@ -118,9 +118,9 @@ func TestCollectorStartWithTLS(t *testing.T) { func TestCollectorReflection(t *testing.T) { logger, _ := zap.NewDevelopment() params := &GRPCServerParams{ - Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), - SamplingStore: &mockSamplingStore{}, - Logger: logger, + Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}), + SamplingProvider: &mockSamplingProvider{}, + Logger: logger, } server, err := StartGRPCServer(params) diff --git a/cmd/collector/app/server/http.go b/cmd/collector/app/server/http.go index f903c048f10..a8579f4f6cd 100644 --- a/cmd/collector/app/server/http.go +++ b/cmd/collector/app/server/http.go @@ -24,7 +24,7 @@ import ( "go.uber.org/zap/zapcore" "github.com/jaegertracing/jaeger/cmd/collector/app/handler" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" clientcfgHandler "github.com/jaegertracing/jaeger/pkg/clientcfg/clientcfghttp" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/healthcheck" @@ -35,13 +35,13 @@ import ( // HTTPServerParams to construct a new Jaeger Collector HTTP Server type HTTPServerParams struct { - TLSConfig tlscfg.Options - HostPort string - Handler handler.JaegerBatchesHandler - SamplingStore strategystore.StrategyStore - MetricsFactory metrics.Factory - HealthCheck *healthcheck.HealthCheck - Logger *zap.Logger + TLSConfig tlscfg.Options + HostPort string + Handler handler.JaegerBatchesHandler + SamplingProvider samplingstrategy.Provider + MetricsFactory metrics.Factory + HealthCheck *healthcheck.HealthCheck + Logger *zap.Logger // ReadTimeout sets the respective parameter of http.Server ReadTimeout time.Duration @@ -88,7 +88,7 @@ func serveHTTP(server *http.Server, listener net.Listener, params *HTTPServerPar cfgHandler := clientcfgHandler.NewHTTPHandler(clientcfgHandler.HTTPHandlerParams{ ConfigManager: &clientcfgHandler.ConfigManager{ - SamplingStrategyStore: params.SamplingStore, + SamplingProvider: params.SamplingProvider, // TODO provide baggage manager }, MetricsFactory: params.MetricsFactory, diff --git a/cmd/collector/app/server/http_test.go b/cmd/collector/app/server/http_test.go index 20a71289fde..ce4088970bb 100644 --- a/cmd/collector/app/server/http_test.go +++ b/cmd/collector/app/server/http_test.go @@ -72,11 +72,11 @@ func TestSpanCollectorHTTP(t *testing.T) { defer mFact.Backend.Stop() logger, _ := zap.NewDevelopment() params := &HTTPServerParams{ - Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}), - SamplingStore: &mockSamplingStore{}, - MetricsFactory: mFact, - HealthCheck: healthcheck.New(), - Logger: logger, + Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}), + SamplingProvider: &mockSamplingProvider{}, + MetricsFactory: mFact, + HealthCheck: healthcheck.New(), + Logger: logger, } server := httptest.NewServer(nil) @@ -198,13 +198,13 @@ func TestSpanCollectorHTTPS(t *testing.T) { mFact := metricstest.NewFactory(time.Hour) defer mFact.Backend.Stop() params := &HTTPServerParams{ - HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP), - Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}), - SamplingStore: &mockSamplingStore{}, - MetricsFactory: mFact, - HealthCheck: healthcheck.New(), - Logger: logger, - TLSConfig: test.TLS, + HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP), + Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}), + SamplingProvider: &mockSamplingProvider{}, + MetricsFactory: mFact, + HealthCheck: healthcheck.New(), + Logger: logger, + TLSConfig: test.TLS, } defer params.TLSConfig.Close() @@ -262,7 +262,7 @@ func TestStartHTTPServerParams(t *testing.T) { params := &HTTPServerParams{ HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP), Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}), - SamplingStore: &mockSamplingStore{}, + SamplingProvider: &mockSamplingProvider{}, MetricsFactory: mFact, HealthCheck: healthcheck.New(), Logger: logger, diff --git a/cmd/collector/app/server/test.go b/cmd/collector/app/server/test.go index 338e5365730..f1acc24c7f9 100644 --- a/cmd/collector/app/server/test.go +++ b/cmd/collector/app/server/test.go @@ -22,13 +22,13 @@ import ( "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) -type mockSamplingStore struct{} +type mockSamplingProvider struct{} -func (mockSamplingStore) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { +func (mockSamplingProvider) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { return nil, nil } -func (mockSamplingStore) Close() error { +func (mockSamplingProvider) Close() error { return nil } diff --git a/cmd/collector/main.go b/cmd/collector/main.go index 51c1d8ffe7e..d315ff618c2 100644 --- a/cmd/collector/main.go +++ b/cmd/collector/main.go @@ -37,7 +37,7 @@ import ( "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/tenancy" "github.com/jaegertracing/jaeger/pkg/version" - ss "github.com/jaegertracing/jaeger/plugin/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider" "github.com/jaegertracing/jaeger/plugin/storage" "github.com/jaegertracing/jaeger/ports" ) @@ -51,11 +51,11 @@ func main() { if err != nil { log.Fatalf("Cannot initialize storage factory: %v", err) } - strategyStoreFactoryConfig, err := ss.FactoryConfigFromEnv() + samplingStrategyFactoryConfig, err := ss.FactoryConfigFromEnv() if err != nil { log.Fatalf("Cannot initialize sampling strategy store factory config: %v", err) } - strategyStoreFactory, err := ss.NewFactory(*strategyStoreFactoryConfig) + samplingStrategyFactory, err := ss.NewFactory(*samplingStrategyFactoryConfig) if err != nil { log.Fatalf("Cannot initialize sampling strategy store factory: %v", err) } @@ -85,16 +85,16 @@ func main() { ssFactory, err := storageFactory.CreateSamplingStoreFactory() if err != nil { - logger.Fatal("Failed to create sampling store factory", zap.Error(err)) + logger.Fatal("Failed to create sampling strategy factory", zap.Error(err)) } - strategyStoreFactory.InitFromViper(v, logger) - if err := strategyStoreFactory.Initialize(metricsFactory, ssFactory, logger); err != nil { - logger.Fatal("Failed to init sampling strategy store factory", zap.Error(err)) + samplingStrategyFactory.InitFromViper(v, logger) + if err := samplingStrategyFactory.Initialize(metricsFactory, ssFactory, logger); err != nil { + logger.Fatal("Failed to init sampling strategy factory", zap.Error(err)) } - strategyStore, aggregator, err := strategyStoreFactory.CreateStrategyStore() + samplingProvider, samplingAggregator, err := samplingStrategyFactory.CreateStrategyProvider() if err != nil { - logger.Fatal("Failed to create sampling strategy store", zap.Error(err)) + logger.Fatal("Failed to create sampling strategy provider", zap.Error(err)) } collectorOpts, err := new(flags.CollectorOptions).InitFromViper(v, logger) if err != nil { @@ -103,14 +103,14 @@ func main() { tm := tenancy.NewManager(&collectorOpts.GRPC.Tenancy) collector := app.New(&app.CollectorParams{ - ServiceName: serviceName, - Logger: logger, - MetricsFactory: metricsFactory, - SpanWriter: spanWriter, - StrategyStore: strategyStore, - Aggregator: aggregator, - HealthCheck: svc.HC(), - TenancyMgr: tm, + ServiceName: serviceName, + Logger: logger, + MetricsFactory: metricsFactory, + SpanWriter: spanWriter, + SamplingProvider: samplingProvider, + SamplingAggregator: samplingAggregator, + HealthCheck: svc.HC(), + TenancyMgr: tm, }) // Start all Collector services if err := collector.Start(collectorOpts); err != nil { @@ -130,7 +130,7 @@ func main() { if err := storageFactory.Close(); err != nil { logger.Error("Failed to close storage factory", zap.Error(err)) } - if err := strategyStoreFactory.Close(); err != nil { + if err := samplingStrategyFactory.Close(); err != nil { logger.Error("Failed to close sampling strategy store factory", zap.Error(err)) } }) @@ -150,7 +150,7 @@ func main() { svc.AddFlags, flags.AddFlags, storageFactory.AddPipelineFlags, - strategyStoreFactory.AddFlags, + samplingStrategyFactory.AddFlags, ) if err := command.Execute(); err != nil { diff --git a/cmd/internal/env/command.go b/cmd/internal/env/command.go index fb32aebaf5d..44e55b32adc 100644 --- a/cmd/internal/env/command.go +++ b/cmd/internal/env/command.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/pflag" "github.com/jaegertracing/jaeger/plugin/metrics" - "github.com/jaegertracing/jaeger/plugin/sampling/strategystore" + "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider" "github.com/jaegertracing/jaeger/plugin/storage" ) @@ -77,11 +77,11 @@ func Command() *cobra.Command { "The type of backend used for service dependencies storage.", ) fs.String( - strategystore.SamplingTypeEnvVar, + strategyprovider.SamplingTypeEnvVar, "file", fmt.Sprintf( strings.ReplaceAll(samplingTypeDescription, "\n", " "), - strings.Join(strategystore.AllSamplingTypes, ", "), + strings.Join(strategyprovider.AllSamplingTypes, ", "), ), ) fs.String( @@ -90,7 +90,7 @@ func Command() *cobra.Command { fmt.Sprintf( strings.ReplaceAll(samplingStorageTypeDescription, "\n", " "), strings.Join(storage.AllSamplingStorageTypes(), ", "), - strategystore.SamplingTypeEnvVar, + strategyprovider.SamplingTypeEnvVar, ), ) fs.String( diff --git a/pkg/clientcfg/clientcfghttp/cfgmgr.go b/pkg/clientcfg/clientcfghttp/cfgmgr.go index 621162a36fe..a34d19a7ba6 100644 --- a/pkg/clientcfg/clientcfghttp/cfgmgr.go +++ b/pkg/clientcfg/clientcfghttp/cfgmgr.go @@ -18,20 +18,20 @@ import ( "context" "errors" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" "github.com/jaegertracing/jaeger/thrift-gen/baggage" ) // ConfigManager implements ClientConfigManager. type ConfigManager struct { - SamplingStrategyStore strategystore.StrategyStore - BaggageManager baggage.BaggageRestrictionManager + SamplingProvider samplingstrategy.Provider + BaggageManager baggage.BaggageRestrictionManager } // GetSamplingStrategy implements ClientConfigManager.GetSamplingStrategy. func (c *ConfigManager) GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) { - return c.SamplingStrategyStore.GetSamplingStrategy(ctx, serviceName) + return c.SamplingProvider.GetSamplingStrategy(ctx, serviceName) } // GetBaggageRestrictions implements ClientConfigManager.GetBaggageRestrictions. diff --git a/pkg/clientcfg/clientcfghttp/cfgmgr_test.go b/pkg/clientcfg/clientcfghttp/cfgmgr_test.go index 53dd14e7868..172c7f0f276 100644 --- a/pkg/clientcfg/clientcfghttp/cfgmgr_test.go +++ b/pkg/clientcfg/clientcfghttp/cfgmgr_test.go @@ -26,18 +26,18 @@ import ( "github.com/jaegertracing/jaeger/thrift-gen/baggage" ) -type mockSamplingStore struct { +type mockSamplingProvider struct { samplingResponse *api_v2.SamplingStrategyResponse } -func (m *mockSamplingStore) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { +func (m *mockSamplingProvider) GetSamplingStrategy(context.Context, string /* serviceName */) (*api_v2.SamplingStrategyResponse, error) { if m.samplingResponse == nil { return nil, errors.New("no mock response provided") } return m.samplingResponse, nil } -func (*mockSamplingStore) Close() error { +func (*mockSamplingProvider) Close() error { return nil } @@ -55,7 +55,7 @@ func (m *mockBaggageMgr) GetBaggageRestrictions(context.Context, string /* servi func TestConfigManager(t *testing.T) { bgm := &mockBaggageMgr{} mgr := &ConfigManager{ - SamplingStrategyStore: &mockSamplingStore{ + SamplingProvider: &mockSamplingProvider{ samplingResponse: &api_v2.SamplingStrategyResponse{}, }, BaggageManager: bgm, diff --git a/pkg/clientcfg/clientcfghttp/handler_test.go b/pkg/clientcfg/clientcfghttp/handler_test.go index e08293b1d37..6afc30d61b2 100644 --- a/pkg/clientcfg/clientcfghttp/handler_test.go +++ b/pkg/clientcfg/clientcfghttp/handler_test.go @@ -36,11 +36,11 @@ import ( ) type testServer struct { - metricsFactory *metricstest.Factory - samplingStore *mockSamplingStore - bgMgr *mockBaggageMgr - server *httptest.Server - handler *HTTPHandler + metricsFactory *metricstest.Factory + samplingProvider *mockSamplingProvider + bgMgr *mockBaggageMgr + server *httptest.Server + handler *HTTPHandler } func withServer( @@ -50,11 +50,11 @@ func withServer( testFn func(server *testServer), ) { metricsFactory := metricstest.NewFactory(0) - samplingStore := &mockSamplingStore{samplingResponse: mockSamplingResponse} + samplingProvider := &mockSamplingProvider{samplingResponse: mockSamplingResponse} bgMgr := &mockBaggageMgr{baggageResponse: mockBaggageResponse} cfgMgr := &ConfigManager{ - SamplingStrategyStore: samplingStore, - BaggageManager: bgMgr, + SamplingProvider: samplingProvider, + BaggageManager: bgMgr, } handler := NewHTTPHandler(HTTPHandlerParams{ ConfigManager: cfgMgr, @@ -67,11 +67,11 @@ func withServer( server := httptest.NewServer(r) defer server.Close() testFn(&testServer{ - metricsFactory: metricsFactory, - samplingStore: samplingStore, - bgMgr: bgMgr, - server: server, - handler: handler, + metricsFactory: metricsFactory, + samplingProvider: samplingProvider, + bgMgr: bgMgr, + server: server, + handler: handler, }) } @@ -112,15 +112,15 @@ func testHTTPHandler(t *testing.T, basePath string) { objResp := &tSampling092.SamplingStrategyResponse{} require.NoError(t, json.Unmarshal(body, objResp)) assert.EqualValues(t, - ts.samplingStore.samplingResponse.GetStrategyType(), + ts.samplingProvider.samplingResponse.GetStrategyType(), objResp.GetStrategyType()) assert.EqualValues(t, - ts.samplingStore.samplingResponse.GetRateLimitingSampling().GetMaxTracesPerSecond(), + ts.samplingProvider.samplingResponse.GetRateLimitingSampling().GetMaxTracesPerSecond(), objResp.GetRateLimitingSampling().GetMaxTracesPerSecond()) } else { objResp, err := p2json.SamplingStrategyResponseFromJSON(body) require.NoError(t, err) - assert.EqualValues(t, ts.samplingStore.samplingResponse, objResp) + assert.EqualValues(t, ts.samplingProvider.samplingResponse, objResp) } }) } diff --git a/plugin/sampling/strategystore/adaptive/aggregator.go b/plugin/sampling/strategyprovider/adaptive/aggregator.go similarity index 97% rename from plugin/sampling/strategystore/adaptive/aggregator.go rename to plugin/sampling/strategyprovider/adaptive/aggregator.go index f933be71cf6..97b8e69399c 100644 --- a/plugin/sampling/strategystore/adaptive/aggregator.go +++ b/plugin/sampling/strategyprovider/adaptive/aggregator.go @@ -21,7 +21,7 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" span_model "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/hostname" "github.com/jaegertracing/jaeger/pkg/metrics" @@ -48,7 +48,7 @@ type aggregator struct { // NewAggregator creates a throughput aggregator that simply emits metrics // about the number of operations seen over the aggregationInterval. -func NewAggregator(options Options, logger *zap.Logger, metricsFactory metrics.Factory, participant leaderelection.ElectionParticipant, store samplingstore.Store) (strategystore.Aggregator, error) { +func NewAggregator(options Options, logger *zap.Logger, metricsFactory metrics.Factory, participant leaderelection.ElectionParticipant, store samplingstore.Store) (samplingstrategy.Aggregator, error) { hostname, err := hostname.AsIdentifier() if err != nil { return nil, err diff --git a/plugin/sampling/strategystore/adaptive/aggregator_test.go b/plugin/sampling/strategyprovider/adaptive/aggregator_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/aggregator_test.go rename to plugin/sampling/strategyprovider/adaptive/aggregator_test.go diff --git a/plugin/sampling/strategystore/adaptive/cache.go b/plugin/sampling/strategyprovider/adaptive/cache.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/cache.go rename to plugin/sampling/strategyprovider/adaptive/cache.go diff --git a/plugin/sampling/strategystore/adaptive/cache_test.go b/plugin/sampling/strategyprovider/adaptive/cache_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/cache_test.go rename to plugin/sampling/strategyprovider/adaptive/cache_test.go diff --git a/plugin/sampling/calculationstrategy/interface.go b/plugin/sampling/strategyprovider/adaptive/calculationstrategy/interface.go similarity index 100% rename from plugin/sampling/calculationstrategy/interface.go rename to plugin/sampling/strategyprovider/adaptive/calculationstrategy/interface.go diff --git a/plugin/sampling/calculationstrategy/interface_test.go b/plugin/sampling/strategyprovider/adaptive/calculationstrategy/interface_test.go similarity index 100% rename from plugin/sampling/calculationstrategy/interface_test.go rename to plugin/sampling/strategyprovider/adaptive/calculationstrategy/interface_test.go diff --git a/plugin/sampling/calculationstrategy/package_test.go b/plugin/sampling/strategyprovider/adaptive/calculationstrategy/package_test.go similarity index 100% rename from plugin/sampling/calculationstrategy/package_test.go rename to plugin/sampling/strategyprovider/adaptive/calculationstrategy/package_test.go diff --git a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go b/plugin/sampling/strategyprovider/adaptive/calculationstrategy/percentage_increase_capped_calculator.go similarity index 100% rename from plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go rename to plugin/sampling/strategyprovider/adaptive/calculationstrategy/percentage_increase_capped_calculator.go diff --git a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go b/plugin/sampling/strategyprovider/adaptive/calculationstrategy/percentage_increase_capped_calculator_test.go similarity index 100% rename from plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go rename to plugin/sampling/strategyprovider/adaptive/calculationstrategy/percentage_increase_capped_calculator_test.go diff --git a/plugin/sampling/strategystore/adaptive/factory.go b/plugin/sampling/strategyprovider/adaptive/factory.go similarity index 84% rename from plugin/sampling/strategystore/adaptive/factory.go rename to plugin/sampling/strategyprovider/adaptive/factory.go index baead570e3a..232a007d198 100644 --- a/plugin/sampling/strategystore/adaptive/factory.go +++ b/plugin/sampling/strategyprovider/adaptive/factory.go @@ -21,7 +21,7 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/distributedlock" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin" @@ -30,9 +30,12 @@ import ( "github.com/jaegertracing/jaeger/storage/samplingstore" ) -var _ plugin.Configurable = (*Factory)(nil) +var ( + _ plugin.Configurable = (*Factory)(nil) + _ samplingstrategy.Factory = (*Factory)(nil) +) -// Factory implements strategystore.Factory for an adaptive strategy store. +// Factory implements samplingstrategy.Factory for an adaptive strategy store. type Factory struct { options *Options logger *zap.Logger @@ -63,7 +66,7 @@ func (f *Factory) InitFromViper(v *viper.Viper, _ *zap.Logger) { f.options.InitFromViper(v) } -// Initialize implements strategystore.Factory +// Initialize implements samplingstrategy.Factory func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error { if ssFactory == nil { return errors.New("sampling store factory is nil. Please configure a backend that supports adaptive sampling") @@ -89,9 +92,9 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.S return nil } -// CreateStrategyStore implements strategystore.Factory -func (f *Factory) CreateStrategyStore() (strategystore.StrategyStore, strategystore.Aggregator, error) { - s := NewStrategyStore(*f.options, f.logger, f.participant, f.store) +// CreateStrategyProvider implements samplingstrategy.Factory +func (f *Factory) CreateStrategyProvider() (samplingstrategy.Provider, samplingstrategy.Aggregator, error) { + s := NewProvider(*f.options, f.logger, f.participant, f.store) a, err := NewAggregator(*f.options, f.logger, f.metricsFactory, f.participant, f.store) if err != nil { return nil, nil, err diff --git a/plugin/sampling/strategystore/adaptive/factory_test.go b/plugin/sampling/strategyprovider/adaptive/factory_test.go similarity index 96% rename from plugin/sampling/strategystore/adaptive/factory_test.go rename to plugin/sampling/strategyprovider/adaptive/factory_test.go index df1d54fda1a..68db90da9f8 100644 --- a/plugin/sampling/strategystore/adaptive/factory_test.go +++ b/plugin/sampling/strategyprovider/adaptive/factory_test.go @@ -25,7 +25,7 @@ import ( "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model" - ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/distributedlock" lmocks "github.com/jaegertracing/jaeger/pkg/distributedlock/mocks" @@ -72,9 +72,9 @@ func TestFactory(t *testing.T) { assert.Equal(t, time.Second*2, f.options.FollowerLeaseRefreshInterval) require.NoError(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{}, zap.NewNop())) - store, aggregator, err := f.CreateStrategyStore() + provider, aggregator, err := f.CreateStrategyProvider() require.NoError(t, err) - require.NoError(t, store.Close()) + require.NoError(t, provider.Close()) require.NoError(t, aggregator.Close()) require.NoError(t, f.Close()) } @@ -96,7 +96,7 @@ func TestBadConfigFail(t *testing.T) { f.InitFromViper(v, zap.NewNop()) require.NoError(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{}, zap.NewNop())) - _, _, err := f.CreateStrategyStore() + _, _, err := f.CreateStrategyProvider() require.Error(t, err) require.NoError(t, f.Close()) } diff --git a/plugin/sampling/strategystore/adaptive/floatutils.go b/plugin/sampling/strategyprovider/adaptive/floatutils.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/floatutils.go rename to plugin/sampling/strategyprovider/adaptive/floatutils.go diff --git a/plugin/sampling/strategystore/adaptive/floatutils_test.go b/plugin/sampling/strategyprovider/adaptive/floatutils_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/floatutils_test.go rename to plugin/sampling/strategyprovider/adaptive/floatutils_test.go diff --git a/plugin/sampling/strategystore/adaptive/options.go b/plugin/sampling/strategyprovider/adaptive/options.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/options.go rename to plugin/sampling/strategyprovider/adaptive/options.go diff --git a/plugin/sampling/strategystore/adaptive/options_test.go b/plugin/sampling/strategyprovider/adaptive/options_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/options_test.go rename to plugin/sampling/strategyprovider/adaptive/options_test.go diff --git a/plugin/sampling/strategystore/adaptive/package_test.go b/plugin/sampling/strategyprovider/adaptive/package_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/package_test.go rename to plugin/sampling/strategyprovider/adaptive/package_test.go diff --git a/plugin/sampling/strategystore/adaptive/processor.go b/plugin/sampling/strategyprovider/adaptive/processor.go similarity index 97% rename from plugin/sampling/strategystore/adaptive/processor.go rename to plugin/sampling/strategyprovider/adaptive/processor.go index 4a56966d777..af22d3e6c22 100644 --- a/plugin/sampling/strategystore/adaptive/processor.go +++ b/plugin/sampling/strategyprovider/adaptive/processor.go @@ -26,8 +26,8 @@ import ( "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model" "github.com/jaegertracing/jaeger/pkg/metrics" - "github.com/jaegertracing/jaeger/plugin/sampling/calculationstrategy" "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection" + "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" "github.com/jaegertracing/jaeger/storage/samplingstore" ) @@ -141,7 +141,7 @@ func newPostAggregator( } // GetSamplingStrategy implements protobuf endpoint for retrieving sampling strategy for a service. -func (p *StrategyStore) GetSamplingStrategy(_ context.Context, service string) (*api_v2.SamplingStrategyResponse, error) { +func (p *Provider) GetSamplingStrategy(_ context.Context, service string) (*api_v2.SamplingStrategyResponse, error) { p.RLock() defer p.RUnlock() if strategy, ok := p.strategyResponses[service]; ok { @@ -159,7 +159,7 @@ func (p *PostAggregator) Start() error { return nil } -func (p *StrategyStore) loadProbabilities() { +func (p *Provider) loadProbabilities() { // TODO GetLatestProbabilities API can be changed to return the latest measured qps for initialization probabilities, err := p.storage.GetLatestProbabilities() if err != nil { @@ -173,7 +173,7 @@ func (p *StrategyStore) loadProbabilities() { // runUpdateProbabilitiesLoop is a loop that reads probabilities from storage. // The follower updates its local cache with the latest probabilities and serves them. -func (p *StrategyStore) runUpdateProbabilitiesLoop() { +func (p *Provider) runUpdateProbabilitiesLoop() { select { case <-time.After(addJitter(p.followerRefreshInterval)): // continue after jitter delay @@ -201,7 +201,7 @@ func (p *PostAggregator) isLeader() bool { return p.electionParticipant.IsLeader() } -func (p *StrategyStore) isLeader() bool { +func (p *Provider) isLeader() bool { return p.electionParticipant.IsLeader() } @@ -470,7 +470,7 @@ func (p *PostAggregator) isUsingAdaptiveSampling( } // generateStrategyResponses generates and caches SamplingStrategyResponse from the calculated sampling probabilities. -func (p *StrategyStore) generateStrategyResponses() { +func (p *Provider) generateStrategyResponses() { p.RLock() strategies := make(map[string]*api_v2.SamplingStrategyResponse) for svc, opProbabilities := range p.probabilities { @@ -496,7 +496,7 @@ func (p *StrategyStore) generateStrategyResponses() { p.strategyResponses = strategies } -func (p *StrategyStore) generateDefaultSamplingStrategyResponse() *api_v2.SamplingStrategyResponse { +func (p *Provider) generateDefaultSamplingStrategyResponse() *api_v2.SamplingStrategyResponse { return &api_v2.SamplingStrategyResponse{ StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC, OperationSampling: &api_v2.PerOperationSamplingStrategies{ diff --git a/plugin/sampling/strategystore/adaptive/processor_test.go b/plugin/sampling/strategyprovider/adaptive/processor_test.go similarity index 99% rename from plugin/sampling/strategystore/adaptive/processor_test.go rename to plugin/sampling/strategyprovider/adaptive/processor_test.go index b9b587f26cf..af7ec5cae04 100644 --- a/plugin/sampling/strategystore/adaptive/processor_test.go +++ b/plugin/sampling/strategyprovider/adaptive/processor_test.go @@ -29,8 +29,8 @@ import ( "github.com/jaegertracing/jaeger/internal/metricstest" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/pkg/testutils" - "github.com/jaegertracing/jaeger/plugin/sampling/calculationstrategy" epmocks "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection/mocks" + "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks" ) @@ -420,7 +420,7 @@ func TestLoadProbabilities(t *testing.T) { mockStorage := &smocks.Store{} mockStorage.On("GetLatestProbabilities").Return(make(model.ServiceOperationProbabilities), nil) - p := &StrategyStore{storage: mockStorage} + p := &Provider{storage: mockStorage} require.Nil(t, p.probabilities) p.loadProbabilities() require.NotNil(t, p.probabilities) @@ -434,7 +434,7 @@ func TestRunUpdateProbabilitiesLoop(t *testing.T) { mockEP.On("Close").Return(nil) mockEP.On("IsLeader").Return(false) - p := &StrategyStore{ + p := &Provider{ storage: mockStorage, shutdown: make(chan struct{}), followerRefreshInterval: time.Millisecond, @@ -488,7 +488,7 @@ func TestRealisticRunCalculationLoop(t *testing.T) { AggregationBuckets: 1, Delay: time.Second * 10, } - s := NewStrategyStore(cfg, logger, mockEP, mockStorage) + s := NewProvider(cfg, logger, mockEP, mockStorage) s.Start() for i := 0; i < 100; i++ { @@ -564,7 +564,7 @@ func TestGenerateStrategyResponses(t *testing.T) { "GET": 0.5, }, } - p := &StrategyStore{ + p := &Provider{ probabilities: probabilities, Options: Options{ InitialSamplingProbability: 0.001, diff --git a/plugin/sampling/strategystore/adaptive/strategy_store.go b/plugin/sampling/strategyprovider/adaptive/provider.go similarity index 87% rename from plugin/sampling/strategystore/adaptive/strategy_store.go rename to plugin/sampling/strategyprovider/adaptive/provider.go index 6a8749c9dc8..61cd02470ff 100644 --- a/plugin/sampling/strategystore/adaptive/strategy_store.go +++ b/plugin/sampling/strategyprovider/adaptive/provider.go @@ -28,7 +28,7 @@ import ( const defaultFollowerProbabilityInterval = 20 * time.Second -type StrategyStore struct { +type Provider struct { sync.RWMutex Options @@ -51,9 +51,9 @@ type StrategyStore struct { bgFinished sync.WaitGroup } -// NewStrategyStore creates a strategy store that holds adaptive sampling strategies. -func NewStrategyStore(options Options, logger *zap.Logger, participant leaderelection.ElectionParticipant, store samplingstore.Store) *StrategyStore { - return &StrategyStore{ +// NewProvider creates a strategy store that holds adaptive sampling strategies. +func NewProvider(options Options, logger *zap.Logger, participant leaderelection.ElectionParticipant, store samplingstore.Store) *Provider { + return &Provider{ Options: options, storage: store, probabilities: make(model.ServiceOperationProbabilities), @@ -66,7 +66,7 @@ func NewStrategyStore(options Options, logger *zap.Logger, participant leaderele } // Start initializes and starts the sampling service which regularly loads sampling probabilities and generates strategies. -func (ss *StrategyStore) Start() error { +func (ss *Provider) Start() error { ss.logger.Info("starting adaptive sampling service") ss.loadProbabilities() ss.generateStrategyResponses() @@ -81,7 +81,7 @@ func (ss *StrategyStore) Start() error { } // Close stops the service from loading probabilities and generating strategies. -func (ss *StrategyStore) Close() error { +func (ss *Provider) Close() error { ss.logger.Info("stopping adaptive sampling service") close(ss.shutdown) ss.bgFinished.Wait() diff --git a/plugin/sampling/strategystore/adaptive/weightvectorcache.go b/plugin/sampling/strategyprovider/adaptive/weightvectorcache.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/weightvectorcache.go rename to plugin/sampling/strategyprovider/adaptive/weightvectorcache.go diff --git a/plugin/sampling/strategystore/adaptive/weightvectorcache_test.go b/plugin/sampling/strategyprovider/adaptive/weightvectorcache_test.go similarity index 100% rename from plugin/sampling/strategystore/adaptive/weightvectorcache_test.go rename to plugin/sampling/strategyprovider/adaptive/weightvectorcache_test.go diff --git a/plugin/sampling/strategystore/factory.go b/plugin/sampling/strategyprovider/factory.go similarity index 76% rename from plugin/sampling/strategystore/factory.go rename to plugin/sampling/strategyprovider/factory.go index d7fe77b2710..895df5a49ac 100644 --- a/plugin/sampling/strategystore/factory.go +++ b/plugin/sampling/strategyprovider/factory.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package strategyprovider import ( "errors" @@ -22,11 +22,11 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin" - "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/adaptive" - "github.com/jaegertracing/jaeger/plugin/sampling/strategystore/static" + "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive" + "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/static" "github.com/jaegertracing/jaeger/storage" ) @@ -41,13 +41,16 @@ const ( // AllSamplingTypes lists all types of sampling factories. var AllSamplingTypes = []string{samplingTypeFile, samplingTypeAdaptive} -var _ plugin.Configurable = (*Factory)(nil) +var ( + _ plugin.Configurable = (*Factory)(nil) + _ samplingstrategy.Factory = (*Factory)(nil) +) -// Factory implements strategystore.Factory interface as a meta-factory for strategy storage components. +// Factory implements samplingstrategy.Factory interface as a meta-factory for strategy storage components. type Factory struct { FactoryConfig - factories map[Kind]strategystore.Factory + factories map[Kind]samplingstrategy.Factory } // NewFactory creates the meta-factory. @@ -56,7 +59,7 @@ func NewFactory(config FactoryConfig) (*Factory, error) { uniqueTypes := map[Kind]struct{}{ f.StrategyStoreType: {}, } - f.factories = make(map[Kind]strategystore.Factory) + f.factories = make(map[Kind]samplingstrategy.Factory) for t := range uniqueTypes { ff, err := f.getFactoryOfType(t) if err != nil { @@ -67,7 +70,7 @@ func NewFactory(config FactoryConfig) (*Factory, error) { return f, nil } -func (*Factory) getFactoryOfType(factoryType Kind) (strategystore.Factory, error) { +func (*Factory) getFactoryOfType(factoryType Kind) (samplingstrategy.Factory, error) { switch factoryType { case samplingTypeFile: return static.NewFactory(), nil @@ -96,7 +99,7 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) { } } -// Initialize implements strategystore.Factory +// Initialize implements samplingstrategy.Factory func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error { for _, factory := range f.factories { if err := factory.Initialize(metricsFactory, ssFactory, logger); err != nil { @@ -106,13 +109,13 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.S return nil } -// CreateStrategyStore implements strategystore.Factory -func (f *Factory) CreateStrategyStore() (strategystore.StrategyStore, strategystore.Aggregator, error) { +// CreateStrategyProvider implements samplingstrategy.Factory +func (f *Factory) CreateStrategyProvider() (samplingstrategy.Provider, samplingstrategy.Aggregator, error) { factory, ok := f.factories[f.StrategyStoreType] if !ok { return nil, nil, fmt.Errorf("no %s strategy store registered", f.StrategyStoreType) } - return factory.CreateStrategyStore() + return factory.CreateStrategyProvider() } // Close closes all factories. diff --git a/plugin/sampling/strategystore/factory_config.go b/plugin/sampling/strategyprovider/factory_config.go similarity index 98% rename from plugin/sampling/strategystore/factory_config.go rename to plugin/sampling/strategyprovider/factory_config.go index d3acc1a9595..e1ddab231ce 100644 --- a/plugin/sampling/strategystore/factory_config.go +++ b/plugin/sampling/strategyprovider/factory_config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package strategyprovider import ( "fmt" diff --git a/plugin/sampling/strategystore/factory_config_test.go b/plugin/sampling/strategyprovider/factory_config_test.go similarity index 98% rename from plugin/sampling/strategystore/factory_config_test.go rename to plugin/sampling/strategyprovider/factory_config_test.go index 2fa86b96c3f..cf997b85b6c 100644 --- a/plugin/sampling/strategystore/factory_config_test.go +++ b/plugin/sampling/strategyprovider/factory_config_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package strategyprovider import ( "testing" diff --git a/plugin/sampling/strategystore/factory_test.go b/plugin/sampling/strategyprovider/factory_test.go similarity index 94% rename from plugin/sampling/strategystore/factory_test.go rename to plugin/sampling/strategyprovider/factory_test.go index 9af5850109a..1095390d010 100644 --- a/plugin/sampling/strategystore/factory_test.go +++ b/plugin/sampling/strategyprovider/factory_test.go @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package strategyprovider import ( "errors" @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/distributedlock" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin" @@ -77,20 +77,20 @@ func TestNewFactory(t *testing.T) { f.factories[Kind(tc.strategyStoreType)] = mock require.NoError(t, f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop())) - _, _, err = f.CreateStrategyStore() + _, _, err = f.CreateStrategyProvider() require.NoError(t, err) require.NoError(t, f.Close()) // force the mock to return errors mock.retError = true require.EqualError(t, f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop()), "error initializing store") - _, _, err = f.CreateStrategyStore() + _, _, err = f.CreateStrategyProvider() require.EqualError(t, err, "error creating store") require.EqualError(t, f.Close(), "error closing store") // request something that doesn't exist f.StrategyStoreType = "doesntexist" - _, _, err = f.CreateStrategyStore() + _, _, err = f.CreateStrategyProvider() require.EqualError(t, err, "no doesntexist strategy store registered") } } @@ -132,7 +132,7 @@ func (f *mockFactory) InitFromViper(v *viper.Viper, logger *zap.Logger) { f.logger = logger } -func (f *mockFactory) CreateStrategyStore() (ss.StrategyStore, ss.Aggregator, error) { +func (f *mockFactory) CreateStrategyProvider() (ss.Provider, ss.Aggregator, error) { if f.retError { return nil, nil, errors.New("error creating store") } diff --git a/plugin/sampling/strategystore/package_test.go b/plugin/sampling/strategyprovider/package_test.go similarity index 96% rename from plugin/sampling/strategystore/package_test.go rename to plugin/sampling/strategyprovider/package_test.go index 3cf20eab7f3..bb98c21dc30 100644 --- a/plugin/sampling/strategystore/package_test.go +++ b/plugin/sampling/strategyprovider/package_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package strategystore +package strategyprovider import ( "testing" diff --git a/plugin/sampling/strategystore/static/constants.go b/plugin/sampling/strategyprovider/static/constants.go similarity index 100% rename from plugin/sampling/strategystore/static/constants.go rename to plugin/sampling/strategyprovider/static/constants.go diff --git a/plugin/sampling/strategystore/static/factory.go b/plugin/sampling/strategyprovider/static/factory.go similarity index 79% rename from plugin/sampling/strategystore/static/factory.go rename to plugin/sampling/strategyprovider/static/factory.go index 3f16548459d..fdf3f2a49e7 100644 --- a/plugin/sampling/strategystore/static/factory.go +++ b/plugin/sampling/strategyprovider/static/factory.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" - "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin" "github.com/jaegertracing/jaeger/storage" @@ -28,7 +28,7 @@ import ( var _ plugin.Configurable = (*Factory)(nil) -// Factory implements strategystore.Factory for a static strategy store. +// Factory implements samplingstrategy.Factory for a static strategy store. type Factory struct { options *Options logger *zap.Logger @@ -52,15 +52,15 @@ func (f *Factory) InitFromViper(v *viper.Viper, _ *zap.Logger) { f.options.InitFromViper(v) } -// Initialize implements strategystore.Factory +// Initialize implements samplingstrategy.Factory func (f *Factory) Initialize(_ metrics.Factory, _ storage.SamplingStoreFactory, logger *zap.Logger) error { f.logger = logger return nil } -// CreateStrategyStore implements strategystore.Factory -func (f *Factory) CreateStrategyStore() (strategystore.StrategyStore, strategystore.Aggregator, error) { - s, err := NewStrategyStore(*f.options, f.logger) +// CreateStrategyStore implements samplingstrategy.Factory +func (f *Factory) CreateStrategyProvider() (samplingstrategy.Provider, samplingstrategy.Aggregator, error) { + s, err := NewProvider(*f.options, f.logger) if err != nil { return nil, nil, err } diff --git a/plugin/sampling/strategystore/static/factory_test.go b/plugin/sampling/strategyprovider/static/factory_test.go similarity index 95% rename from plugin/sampling/strategystore/static/factory_test.go rename to plugin/sampling/strategyprovider/static/factory_test.go index 11b169c4818..aa5c738a39a 100644 --- a/plugin/sampling/strategystore/static/factory_test.go +++ b/plugin/sampling/strategyprovider/static/factory_test.go @@ -20,7 +20,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap" - ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/pkg/config" "github.com/jaegertracing/jaeger/pkg/metrics" "github.com/jaegertracing/jaeger/plugin" @@ -38,7 +38,7 @@ func TestFactory(t *testing.T) { f.InitFromViper(v, zap.NewNop()) require.NoError(t, f.Initialize(metrics.NullFactory, nil, zap.NewNop())) - _, _, err := f.CreateStrategyStore() + _, _, err := f.CreateStrategyProvider() require.NoError(t, err) require.NoError(t, f.Close()) } diff --git a/plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceA.json b/plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceA.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceA.json rename to plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceA.json diff --git a/plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceB.json b/plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceB.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceB.json rename to plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategiesDeprecatedBehavior_ServiceB.json diff --git a/plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategies_ServiceA.json b/plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategies_ServiceA.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategies_ServiceA.json rename to plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategies_ServiceA.json diff --git a/plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategies_ServiceB.json b/plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategies_ServiceB.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/TestServiceNoPerOperationStrategies_ServiceB.json rename to plugin/sampling/strategyprovider/static/fixtures/TestServiceNoPerOperationStrategies_ServiceB.json diff --git a/plugin/sampling/strategystore/static/fixtures/bad_strategies.json b/plugin/sampling/strategyprovider/static/fixtures/bad_strategies.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/bad_strategies.json rename to plugin/sampling/strategyprovider/static/fixtures/bad_strategies.json diff --git a/plugin/sampling/strategystore/static/fixtures/missing-service-types.json b/plugin/sampling/strategyprovider/static/fixtures/missing-service-types.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/missing-service-types.json rename to plugin/sampling/strategyprovider/static/fixtures/missing-service-types.json diff --git a/plugin/sampling/strategystore/static/fixtures/operation_strategies.json b/plugin/sampling/strategyprovider/static/fixtures/operation_strategies.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/operation_strategies.json rename to plugin/sampling/strategyprovider/static/fixtures/operation_strategies.json diff --git a/plugin/sampling/strategystore/static/fixtures/service_no_per_operation.json b/plugin/sampling/strategyprovider/static/fixtures/service_no_per_operation.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/service_no_per_operation.json rename to plugin/sampling/strategyprovider/static/fixtures/service_no_per_operation.json diff --git a/plugin/sampling/strategystore/static/fixtures/strategies.json b/plugin/sampling/strategyprovider/static/fixtures/strategies.json similarity index 100% rename from plugin/sampling/strategystore/static/fixtures/strategies.json rename to plugin/sampling/strategyprovider/static/fixtures/strategies.json diff --git a/plugin/sampling/strategystore/static/options.go b/plugin/sampling/strategyprovider/static/options.go similarity index 100% rename from plugin/sampling/strategystore/static/options.go rename to plugin/sampling/strategyprovider/static/options.go diff --git a/plugin/sampling/strategystore/static/package_test.go b/plugin/sampling/strategyprovider/static/package_test.go similarity index 100% rename from plugin/sampling/strategystore/static/package_test.go rename to plugin/sampling/strategyprovider/static/package_test.go diff --git a/plugin/sampling/strategystore/static/strategy_store.go b/plugin/sampling/strategyprovider/static/provider.go similarity index 89% rename from plugin/sampling/strategystore/static/strategy_store.go rename to plugin/sampling/strategyprovider/static/provider.go index 05debf2d720..87466471078 100644 --- a/plugin/sampling/strategystore/static/strategy_store.go +++ b/plugin/sampling/strategyprovider/static/provider.go @@ -29,7 +29,7 @@ import ( "go.uber.org/zap" - ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" + ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy" "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) @@ -37,7 +37,7 @@ import ( // it un-marshals to nil pointer. var nullJSON = []byte("null") -type strategyStore struct { +type samplingProvider struct { logger *zap.Logger storedStrategies atomic.Value // holds *storedStrategies @@ -54,10 +54,10 @@ type storedStrategies struct { type strategyLoader func() ([]byte, error) -// NewStrategyStore creates a strategy store that holds static sampling strategies. -func NewStrategyStore(options Options, logger *zap.Logger) (ss.StrategyStore, error) { +// NewProvider creates a strategy store that holds static sampling strategies. +func NewProvider(options Options, logger *zap.Logger) (ss.Provider, error) { ctx, cancelFunc := context.WithCancel(context.Background()) - h := &strategyStore{ + h := &samplingProvider{ logger: logger, cancelFunc: cancelFunc, options: options, @@ -94,7 +94,7 @@ func NewStrategyStore(options Options, logger *zap.Logger) (ss.StrategyStore, er } // GetSamplingStrategy implements StrategyStore#GetSamplingStrategy. -func (h *strategyStore) GetSamplingStrategy(_ context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) { +func (h *samplingProvider) GetSamplingStrategy(_ context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) { ss := h.storedStrategies.Load().(*storedStrategies) serviceStrategies := ss.serviceStrategies if strategy, ok := serviceStrategies[serviceName]; ok { @@ -105,12 +105,12 @@ func (h *strategyStore) GetSamplingStrategy(_ context.Context, serviceName strin } // Close stops updating the strategies -func (h *strategyStore) Close() error { +func (h *samplingProvider) Close() error { h.cancelFunc() return nil } -func (h *strategyStore) downloadSamplingStrategies(url string) ([]byte, error) { +func (h *samplingProvider) downloadSamplingStrategies(url string) ([]byte, error) { h.logger.Info("Downloading sampling strategies", zap.String("url", url)) ctx, cx := context.WithTimeout(context.Background(), time.Second) @@ -149,7 +149,7 @@ func isURL(str string) bool { return err == nil && u.Scheme != "" && u.Host != "" } -func (h *strategyStore) samplingStrategyLoader(strategiesFile string) strategyLoader { +func (h *samplingProvider) samplingStrategyLoader(strategiesFile string) strategyLoader { if isURL(strategiesFile) { return func() ([]byte, error) { return h.downloadSamplingStrategies(strategiesFile) @@ -166,7 +166,7 @@ func (h *strategyStore) samplingStrategyLoader(strategiesFile string) strategyLo } } -func (h *strategyStore) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) { +func (h *samplingProvider) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) { lastValue := string(nullJSON) ticker := time.NewTicker(interval) defer ticker.Stop() @@ -180,7 +180,7 @@ func (h *strategyStore) autoUpdateStrategies(ctx context.Context, interval time. } } -func (h *strategyStore) reloadSamplingStrategy(loadFn strategyLoader, lastValue string) string { +func (h *samplingProvider) reloadSamplingStrategy(loadFn strategyLoader, lastValue string) string { newValue, err := loadFn() if err != nil { h.logger.Error("failed to re-load sampling strategies", zap.Error(err)) @@ -196,7 +196,7 @@ func (h *strategyStore) reloadSamplingStrategy(loadFn strategyLoader, lastValue return string(newValue) } -func (h *strategyStore) updateSamplingStrategy(bytes []byte) error { +func (h *samplingProvider) updateSamplingStrategy(bytes []byte) error { var strategies strategies if err := json.Unmarshal(bytes, &strategies); err != nil { return fmt.Errorf("failed to unmarshal sampling strategies: %w", err) @@ -220,7 +220,7 @@ func loadStrategies(loadFn strategyLoader) (*strategies, error) { return strategies, nil } -func (h *strategyStore) parseStrategies_deprecated(strategies *strategies) { +func (h *samplingProvider) parseStrategies_deprecated(strategies *strategies) { newStore := defaultStrategies() if strategies.DefaultStrategy != nil { newStore.defaultStrategy = h.parseServiceStrategies(strategies.DefaultStrategy) @@ -259,7 +259,7 @@ func (h *strategyStore) parseStrategies_deprecated(strategies *strategies) { h.storedStrategies.Store(newStore) } -func (h *strategyStore) parseStrategies(strategies *strategies) { +func (h *samplingProvider) parseStrategies(strategies *strategies) { newStore := defaultStrategies() if strategies.DefaultStrategy != nil { newStore.defaultStrategy = h.parseServiceStrategies(strategies.DefaultStrategy) @@ -314,7 +314,7 @@ func mergePerOperationSamplingStrategies( return a } -func (h *strategyStore) parseServiceStrategies(strategy *serviceStrategy) *api_v2.SamplingStrategyResponse { +func (h *samplingProvider) parseServiceStrategies(strategy *serviceStrategy) *api_v2.SamplingStrategyResponse { resp := h.parseStrategy(&strategy.strategy) if len(strategy.OperationStrategies) == 0 { return resp @@ -341,7 +341,7 @@ func (h *strategyStore) parseServiceStrategies(strategy *serviceStrategy) *api_v return resp } -func (h *strategyStore) parseOperationStrategy( +func (h *samplingProvider) parseOperationStrategy( strategy *operationStrategy, parent *api_v2.PerOperationSamplingStrategies, ) (s *api_v2.SamplingStrategyResponse, ok bool) { @@ -359,7 +359,7 @@ func (h *strategyStore) parseOperationStrategy( return s, true } -func (h *strategyStore) parseStrategy(strategy *strategy) *api_v2.SamplingStrategyResponse { +func (h *samplingProvider) parseStrategy(strategy *strategy) *api_v2.SamplingStrategyResponse { switch strategy.Type { case samplerTypeProbabilistic: return &api_v2.SamplingStrategyResponse{ diff --git a/plugin/sampling/strategystore/static/strategy_store_test.go b/plugin/sampling/strategyprovider/static/provider_test.go similarity index 81% rename from plugin/sampling/strategystore/static/strategy_store_test.go rename to plugin/sampling/strategyprovider/static/provider_test.go index f499baa5a7e..20997f78d9c 100644 --- a/plugin/sampling/strategystore/static/strategy_store_test.go +++ b/plugin/sampling/strategyprovider/static/provider_test.go @@ -40,7 +40,7 @@ const snapshotLocation = "./fixtures/" // Snapshots can be regenerated via: // -// REGENERATE_SNAPSHOTS=true go test -v ./plugin/sampling/strategystore/static/strategy_store_test.go +// REGENERATE_SNAPSHOTS=true go test -v ./plugin/sampling/strategyprovider/static/provider_test.go var regenerateSnapshots = os.Getenv("REGENERATE_SNAPSHOTS") == "true" // strategiesJSON returns the strategy with @@ -105,34 +105,34 @@ func mockStrategyServer(t *testing.T) (*httptest.Server, *atomic.Pointer[string] } func TestStrategyStoreWithFile(t *testing.T) { - _, err := NewStrategyStore(Options{StrategiesFile: "fileNotFound.json"}, zap.NewNop()) + _, err := NewProvider(Options{StrategiesFile: "fileNotFound.json"}, zap.NewNop()) assert.Contains(t, err.Error(), "failed to read strategies file fileNotFound.json") - _, err = NewStrategyStore(Options{StrategiesFile: "fixtures/bad_strategies.json"}, zap.NewNop()) + _, err = NewProvider(Options{StrategiesFile: "fixtures/bad_strategies.json"}, zap.NewNop()) require.EqualError(t, err, "failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies") // Test default strategy logger, buf := testutils.NewLogger() - store, err := NewStrategyStore(Options{}, logger) + provider, err := NewProvider(Options{}, logger) require.NoError(t, err) assert.Contains(t, buf.String(), "No sampling strategies source provided, using defaults") - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001), *s) // Test reading strategies from a file - store, err = NewStrategyStore(Options{StrategiesFile: "fixtures/strategies.json"}, logger) + provider, err = NewProvider(Options{StrategiesFile: "fixtures/strategies.json"}, logger) require.NoError(t, err) - s, err = store.GetSamplingStrategy(context.Background(), "foo") + s, err = provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s) - s, err = store.GetSamplingStrategy(context.Background(), "bar") + s, err = provider.GetSamplingStrategy(context.Background(), "bar") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5), *s) - s, err = store.GetSamplingStrategy(context.Background(), "default") + s, err = provider.GetSamplingStrategy(context.Background(), "default") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5), *s) } @@ -141,22 +141,22 @@ func TestStrategyStoreWithURL(t *testing.T) { // Test default strategy when URL is temporarily unavailable. logger, buf := testutils.NewLogger() mockServer, _ := mockStrategyServer(t) - store, err := NewStrategyStore(Options{StrategiesFile: mockServer.URL + "/service-unavailable"}, logger) + provider, err := NewProvider(Options{StrategiesFile: mockServer.URL + "/service-unavailable"}, logger) require.NoError(t, err) assert.Contains(t, buf.String(), "No sampling strategies found or URL is unavailable, using defaults") - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001), *s) // Test downloading strategies from a URL. - store, err = NewStrategyStore(Options{StrategiesFile: mockServer.URL}, logger) + provider, err = NewProvider(Options{StrategiesFile: mockServer.URL}, logger) require.NoError(t, err) - s, err = store.GetSamplingStrategy(context.Background(), "foo") + s, err = provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s) - s, err = store.GetSamplingStrategy(context.Background(), "bar") + s, err = provider.GetSamplingStrategy(context.Background(), "bar") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5), *s) } @@ -174,7 +174,7 @@ func TestPerOperationSamplingStrategies(t *testing.T) { for _, tc := range tests { logger, buf := testutils.NewLogger() - store, err := NewStrategyStore(tc.options, logger) + provider, err := NewProvider(tc.options, logger) assert.Contains(t, buf.String(), "Operation strategies only supports probabilistic sampling at the moment,"+ "'op2' defaulting to probabilistic sampling with probability 0.8") assert.Contains(t, buf.String(), "Operation strategies only supports probabilistic sampling at the moment,"+ @@ -183,7 +183,7 @@ func TestPerOperationSamplingStrategies(t *testing.T) { expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8) - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.Equal(t, api_v2.SamplingStrategyType_PROBABILISTIC, s.StrategyType) assert.Equal(t, *expected.ProbabilisticSampling, *s.ProbabilisticSampling) @@ -204,7 +204,7 @@ func TestPerOperationSamplingStrategies(t *testing.T) { expected = makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5) - s, err = store.GetSamplingStrategy(context.Background(), "bar") + s, err = provider.GetSamplingStrategy(context.Background(), "bar") require.NoError(t, err) assert.Equal(t, api_v2.SamplingStrategyType_RATE_LIMITING, s.StrategyType) assert.Equal(t, *expected.RateLimitingSampling, *s.RateLimitingSampling) @@ -224,7 +224,7 @@ func TestPerOperationSamplingStrategies(t *testing.T) { assert.Equal(t, "op7", os.PerOperationStrategies[4].Operation) assert.EqualValues(t, 1, os.PerOperationStrategies[4].ProbabilisticSampling.SamplingRate) - s, err = store.GetSamplingStrategy(context.Background(), "default") + s, err = provider.GetSamplingStrategy(context.Background(), "default") require.NoError(t, err) expectedRsp := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5) expectedRsp.OperationSampling = &api_v2.PerOperationSamplingStrategies{ @@ -256,13 +256,13 @@ func TestPerOperationSamplingStrategies(t *testing.T) { func TestMissingServiceSamplingStrategyTypes(t *testing.T) { logger, buf := testutils.NewLogger() - store, err := NewStrategyStore(Options{StrategiesFile: "fixtures/missing-service-types.json"}, logger) + provider, err := NewProvider(Options{StrategiesFile: "fixtures/missing-service-types.json"}, logger) assert.Contains(t, buf.String(), "Failed to parse sampling strategy") require.NoError(t, err) expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability) - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.Equal(t, api_v2.SamplingStrategyType_PROBABILISTIC, s.StrategyType) assert.Equal(t, *expected.ProbabilisticSampling, *s.ProbabilisticSampling) @@ -276,7 +276,7 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) { expected = makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability) - s, err = store.GetSamplingStrategy(context.Background(), "bar") + s, err = provider.GetSamplingStrategy(context.Background(), "bar") require.NoError(t, err) assert.Equal(t, api_v2.SamplingStrategyType_PROBABILISTIC, s.StrategyType) assert.Equal(t, *expected.ProbabilisticSampling, *s.ProbabilisticSampling) @@ -290,7 +290,7 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) { assert.Equal(t, "op5", os.PerOperationStrategies[1].Operation) assert.EqualValues(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate) - s, err = store.GetSamplingStrategy(context.Background(), "default") + s, err = provider.GetSamplingStrategy(context.Background(), "default") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5), *s) } @@ -316,17 +316,17 @@ func TestParseStrategy(t *testing.T) { }, } logger, buf := testutils.NewLogger() - store := &strategyStore{logger: logger} + provider := &samplingProvider{logger: logger} for _, test := range tests { tt := test t.Run("", func(t *testing.T) { - assert.EqualValues(t, tt.expected, *store.parseStrategy(&tt.strategy.strategy)) + assert.EqualValues(t, tt.expected, *provider.parseStrategy(&tt.strategy.strategy)) }) } assert.Empty(t, buf.String()) // Test nonexistent strategy type - actual := *store.parseStrategy(&strategy{Type: "blah", Param: 3.5}) + actual := *provider.parseStrategy(&strategy{Type: "blah", Param: 3.5}) expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability) assert.EqualValues(t, expected, actual) assert.Contains(t, buf.String(), "Failed to parse sampling strategy") @@ -371,21 +371,21 @@ func TestAutoUpdateStrategyWithFile(t *testing.T) { require.NoError(t, err) require.NoError(t, os.WriteFile(dstFile, srcBytes, 0o644)) - ss, err := NewStrategyStore(Options{ + ss, err := NewProvider(Options{ StrategiesFile: dstFile, ReloadInterval: time.Millisecond * 10, }, zap.NewNop()) require.NoError(t, err) - store := ss.(*strategyStore) - defer store.Close() + provider := ss.(*samplingProvider) + defer provider.Close() // confirm baseline value - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s) // verify that reloading is a no-op - value := store.reloadSamplingStrategy(store.samplingStrategyLoader(dstFile), string(srcBytes)) + value := provider.reloadSamplingStrategy(provider.samplingStrategyLoader(dstFile), string(srcBytes)) assert.Equal(t, string(srcBytes), value) // update file with new probability of 0.9 @@ -394,7 +394,7 @@ func TestAutoUpdateStrategyWithFile(t *testing.T) { // wait for reload timer for i := 0; i < 1000; i++ { // wait up to 1sec - s, err = store.GetSamplingStrategy(context.Background(), "foo") + s, err = provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) if s.ProbabilisticSampling != nil && s.ProbabilisticSampling.SamplingRate == 0.9 { break @@ -406,22 +406,22 @@ func TestAutoUpdateStrategyWithFile(t *testing.T) { func TestAutoUpdateStrategyWithURL(t *testing.T) { mockServer, mockStrategy := mockStrategyServer(t) - ss, err := NewStrategyStore(Options{ + ss, err := NewProvider(Options{ StrategiesFile: mockServer.URL, ReloadInterval: 10 * time.Millisecond, }, zap.NewNop()) require.NoError(t, err) - store := ss.(*strategyStore) - defer store.Close() + provider := ss.(*samplingProvider) + defer provider.Close() // confirm baseline value - s, err := store.GetSamplingStrategy(context.Background(), "foo") + s, err := provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s) // verify that reloading in no-op - value := store.reloadSamplingStrategy( - store.samplingStrategyLoader(mockServer.URL), + value := provider.reloadSamplingStrategy( + provider.samplingStrategyLoader(mockServer.URL), *mockStrategy.Load(), ) assert.Equal(t, *mockStrategy.Load(), value) @@ -434,7 +434,7 @@ func TestAutoUpdateStrategyWithURL(t *testing.T) { // wait for reload timer for i := 0; i < 1000; i++ { // wait up to 1sec - s, err = store.GetSamplingStrategy(context.Background(), "foo") + s, err = provider.GetSamplingStrategy(context.Background(), "foo") require.NoError(t, err) if s.ProbabilisticSampling != nil && s.ProbabilisticSampling.SamplingRate == 0.9 { break @@ -454,41 +454,41 @@ func TestAutoUpdateStrategyErrors(t *testing.T) { zapCore, logs := observer.New(zap.InfoLevel) logger := zap.New(zapCore) - s, err := NewStrategyStore(Options{ + s, err := NewProvider(Options{ StrategiesFile: "fixtures/strategies.json", ReloadInterval: time.Hour, }, logger) require.NoError(t, err) - store := s.(*strategyStore) - defer store.Close() + provider := s.(*samplingProvider) + defer provider.Close() // check invalid file path or read failure - assert.Equal(t, "blah", store.reloadSamplingStrategy(store.samplingStrategyLoader(tempFile.Name()+"bad-path"), "blah")) + assert.Equal(t, "blah", provider.reloadSamplingStrategy(provider.samplingStrategyLoader(tempFile.Name()+"bad-path"), "blah")) assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 1) // check bad file content require.NoError(t, os.WriteFile(tempFile.Name(), []byte("bad value"), 0o644)) - assert.Equal(t, "blah", store.reloadSamplingStrategy(store.samplingStrategyLoader(tempFile.Name()), "blah")) + assert.Equal(t, "blah", provider.reloadSamplingStrategy(provider.samplingStrategyLoader(tempFile.Name()), "blah")) assert.Len(t, logs.FilterMessage("failed to update sampling strategies").All(), 1) // check invalid url - assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader("bad-url"), "duh")) + assert.Equal(t, "duh", provider.reloadSamplingStrategy(provider.samplingStrategyLoader("bad-url"), "duh")) assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 2) // check status code other than 200 mockServer, _ := mockStrategyServer(t) - assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-status"), "duh")) + assert.Equal(t, "duh", provider.reloadSamplingStrategy(provider.samplingStrategyLoader(mockServer.URL+"/bad-status"), "duh")) assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 3) // check bad content from url - assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-content"), "duh")) + assert.Equal(t, "duh", provider.reloadSamplingStrategy(provider.samplingStrategyLoader(mockServer.URL+"/bad-content"), "duh")) assert.Len(t, logs.FilterMessage("failed to update sampling strategies").All(), 2) } func TestServiceNoPerOperationStrategies(t *testing.T) { - // given setup of strategy store with no specific per operation sampling strategies + // given setup of strategy provider with no specific per operation sampling strategies // and option "sampling.strategies.bugfix-5270=true" - store, err := NewStrategyStore(Options{ + provider, err := NewProvider(Options{ StrategiesFile: "fixtures/service_no_per_operation.json", IncludeDefaultOpStrategies: true, }, zap.NewNop()) @@ -496,7 +496,7 @@ func TestServiceNoPerOperationStrategies(t *testing.T) { for _, service := range []string{"ServiceA", "ServiceB"} { t.Run(service, func(t *testing.T) { - strategy, err := store.GetSamplingStrategy(context.Background(), service) + strategy, err := provider.GetSamplingStrategy(context.Background(), service) require.NoError(t, err) strategyJson, err := json.MarshalIndent(strategy, "", " ") require.NoError(t, err) @@ -520,15 +520,15 @@ func TestServiceNoPerOperationStrategiesDeprecatedBehavior(t *testing.T) { // test case to be removed along with removal of strategy_store.parseStrategies_deprecated, // see https://github.com/jaegertracing/jaeger/issues/5270 for more details - // given setup of strategy store with no specific per operation sampling strategies - store, err := NewStrategyStore(Options{ + // given setup of strategy provider with no specific per operation sampling strategies + provider, err := NewProvider(Options{ StrategiesFile: "fixtures/service_no_per_operation.json", }, zap.NewNop()) require.NoError(t, err) for _, service := range []string{"ServiceA", "ServiceB"} { t.Run(service, func(t *testing.T) { - strategy, err := store.GetSamplingStrategy(context.Background(), service) + strategy, err := provider.GetSamplingStrategy(context.Background(), service) require.NoError(t, err) strategyJson, err := json.MarshalIndent(strategy, "", " ") require.NoError(t, err) @@ -549,20 +549,20 @@ func TestServiceNoPerOperationStrategiesDeprecatedBehavior(t *testing.T) { } func TestSamplingStrategyLoader(t *testing.T) { - store := &strategyStore{logger: zap.NewNop()} + provider := &samplingProvider{logger: zap.NewNop()} // invalid file path - loader := store.samplingStrategyLoader("not-exists") + loader := provider.samplingStrategyLoader("not-exists") _, err := loader() assert.Contains(t, err.Error(), "failed to read strategies file not-exists") // status code other than 200 mockServer, _ := mockStrategyServer(t) - loader = store.samplingStrategyLoader(mockServer.URL + "/bad-status") + loader = provider.samplingStrategyLoader(mockServer.URL + "/bad-status") _, err = loader() assert.Contains(t, err.Error(), "receiving 404 Not Found while downloading strategies file") // should download content from URL - loader = store.samplingStrategyLoader(mockServer.URL + "/bad-content") + loader = provider.samplingStrategyLoader(mockServer.URL + "/bad-content") content, err := loader() require.NoError(t, err) assert.Equal(t, "bad-content", string(content)) diff --git a/plugin/sampling/strategystore/static/strategy.go b/plugin/sampling/strategyprovider/static/strategy.go similarity index 100% rename from plugin/sampling/strategystore/static/strategy.go rename to plugin/sampling/strategyprovider/static/strategy.go