Skip to content

Commit

Permalink
[refactor] Move sampling strategy providers to internal/sampling/samp…
Browse files Browse the repository at this point in the history
…lingstrategy (#6561)

## Which problem is this PR solving?
- Resolves #6411 

## Description of the changes
- Move sampling strategy providers from plugin/sampling/strategyprovider
to internal/sampling/samplingstrategy

## How was this change tested?
- Covered by existing

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `npm run lint` and `npm run test`

Signed-off-by: Aryan Goyal <[email protected]>
  • Loading branch information
ary82 authored Jan 17, 2025
1 parent 7f16f49 commit 74db9ce
Show file tree
Hide file tree
Showing 56 changed files with 56 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import (
queryApp "github.com/jaegertracing/jaeger/cmd/query/app"
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
v2querysvc "github.com/jaegertracing/jaeger/cmd/query/app/querysvc/v2/querysvc"
ss "github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/metafactory"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/jtracer"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/telemetry"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/pkg/version"
"github.com/jaegertracing/jaeger/plugin/metricstore"
ss "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider"
"github.com/jaegertracing/jaeger/plugin/storage"
"github.com/jaegertracing/jaeger/ports"
"github.com/jaegertracing/jaeger/storage_v2/depstore"
Expand Down
2 changes: 1 addition & 1 deletion cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
cmdFlags "github.com/jaegertracing/jaeger/cmd/internal/flags"
"github.com/jaegertracing/jaeger/cmd/internal/printconfig"
"github.com/jaegertracing/jaeger/cmd/internal/status"
ss "github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/metafactory"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/telemetry"
"github.com/jaegertracing/jaeger/pkg/tenancy"
"github.com/jaegertracing/jaeger/pkg/version"
ss "github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider"
"github.com/jaegertracing/jaeger/plugin/storage"
"github.com/jaegertracing/jaeger/ports"
"github.com/jaegertracing/jaeger/storage_v2/v1adapter"
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/env/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

ss "github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/metafactory"
"github.com/jaegertracing/jaeger/plugin/metricstore"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider"
"github.com/jaegertracing/jaeger/plugin/storage"
)

Expand Down Expand Up @@ -66,11 +66,11 @@ func Command() *cobra.Command {
"The type of backend used for service dependencies storage.",
)
fs.String(
strategyprovider.SamplingTypeEnvVar,
ss.SamplingTypeEnvVar,
"file",
fmt.Sprintf(
strings.ReplaceAll(samplingTypeDescription, "\n", " "),
strings.Join(strategyprovider.AllSamplingTypes, ", "),
strings.Join(ss.AllSamplingTypes, ", "),
),
)
fs.String(
Expand All @@ -79,7 +79,7 @@ func Command() *cobra.Command {
fmt.Sprintf(
strings.ReplaceAll(samplingStorageTypeDescription, "\n", " "),
strings.Join(storage.AllSamplingStorageTypes(), ", "),
strategyprovider.SamplingTypeEnvVar,
ss.SamplingTypeEnvVar,
),
)
fs.String(
Expand Down
2 changes: 1 addition & 1 deletion cmd/jaeger/internal/extension/remotesampling/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/featuregate"

"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions cmd/jaeger/internal/extension/remotesampling/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
samplinggrpc "github.com/jaegertracing/jaeger/internal/sampling/grpc"
samplinghttp "github.com/jaegertracing/jaeger/internal/sampling/http"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/file"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/static"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
"github.com/jaegertracing/jaeger/storage"
"github.com/jaegertracing/jaeger/storage/samplingstore"
Expand Down Expand Up @@ -164,7 +164,7 @@ func (ext *rsExtension) Shutdown(ctx context.Context) error {
}

func (ext *rsExtension) startFileBasedStrategyProvider(_ context.Context) error {
opts := static.Options{
opts := file.Options{
StrategiesFile: ext.cfg.File.Path,
ReloadInterval: ext.cfg.File.ReloadInterval,
IncludeDefaultOpStrategies: includeDefaultOpStrategies.IsEnabled(),
Expand All @@ -173,7 +173,7 @@ func (ext *rsExtension) startFileBasedStrategyProvider(_ context.Context) error

// contextcheck linter complains about next line that context is not passed.
//nolint
provider, err := static.NewProvider(opts, ext.telemetry.Logger)
provider, err := file.NewProvider(opts, ext.telemetry.Logger)
if err != nil {
return fmt.Errorf("failed to create the local file strategy store: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/plugin/storage/memory"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/jaeger/internal/extension/remotesampling/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/extension"

"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/static"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/file"
"github.com/jaegertracing/jaeger/ports"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func createDefaultConfig() component.Config {
},
File: &FileConfig{
Path: "", // path needs to be specified
DefaultSamplingProbability: static.DefaultSamplingProbability,
DefaultSamplingProbability: file.DefaultSamplingProbability,
},
Adaptive: &AdaptiveConfig{
SamplingStore: "", // storage name needs to be specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/remotesampling"
"github.com/jaegertracing/jaeger/internal/metrics/otelmetrics"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/storage_v2/v1adapter"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/jaegerstorage"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/extension/remotesampling"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/plugin/storage/memory"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/internal/leaderelection"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive/calculationstrategy"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

epmocks "github.com/jaegertracing/jaeger/internal/leaderelection/mocks"
"github.com/jaegertracing/jaeger/internal/metricstest"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive/calculationstrategy"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy"
smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,13 @@
package samplingstrategy

import (
"context"
"io"

"go.uber.org/zap"

"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

// Provider keeps track of service specific sampling strategies.
type Provider interface {
// Close() from io.Closer stops the processor from calculating probabilities.
io.Closer

// GetSamplingStrategy retrieves the sampling strategy for the specified service.
GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)
}

// Aggregator defines an interface used to aggregate operation throughput.
type Aggregator interface {
// Close() from io.Closer stops the aggregator from aggregating throughput.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"flag"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"flag"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

import (
"context"
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestStrategyStoreWithFile(t *testing.T) {

_, err = NewProvider(Options{StrategiesFile: "fixtures/bad_strategies.json", DefaultSamplingProbability: DefaultSamplingProbability}, zap.NewNop())
require.EqualError(t, err,
"failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies")
"failed to unmarshal strategies: json: cannot unmarshal string into Go value of type file.strategies")

// Test default strategy
logger, buf := testutils.NewLogger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package static
package file

// strategy defines a sampling strategy. Type can be "probabilistic" or "ratelimiting"
// and Param will represent "sampling probability" and "max traces per second" respectively.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package strategyprovider
package metafactory

import (
"errors"
Expand All @@ -12,10 +12,10 @@ import (
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/adaptive"
"github.com/jaegertracing/jaeger/internal/sampling/samplingstrategy/file"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/static"
"github.com/jaegertracing/jaeger/storage"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func NewFactory(config FactoryConfig) (*Factory, error) {
func (*Factory) getFactoryOfType(factoryType Kind) (samplingstrategy.Factory, error) {
switch factoryType {
case samplingTypeFile:
return static.NewFactory(), nil
return file.NewFactory(), nil
case samplingTypeAdaptive:
return adaptive.NewFactory(), nil
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package strategyprovider
package metafactory

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2018 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package strategyprovider
package metafactory

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) 2018 Uber Technologies, Inc.
// SPDX-License-Identifier: Apache-2.0

package strategyprovider
package metafactory

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package strategyprovider
package metafactory

import (
"testing"
Expand Down
20 changes: 20 additions & 0 deletions internal/sampling/samplingstrategy/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package samplingstrategy

import (
"context"
"io"

"github.com/jaegertracing/jaeger/proto-gen/api_v2"
)

// Provider keeps track of service specific sampling strategies.
type Provider interface {
// Close() from io.Closer stops the processor from calculating probabilities.
io.Closer

// GetSamplingStrategy retrieves the sampling strategy for the specified service.
GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)
}

0 comments on commit 74db9ce

Please sign in to comment.