Skip to content

Commit

Permalink
[refactor] Move cmd/collector/app/sampling/model types to storage (#6531
Browse files Browse the repository at this point in the history
)

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

## Description of the changes
- Involves refactoring the `model` package in
`cmd/collector/app/sampling`
- Move specific `plugin/storage/cassandra/samplingstore` types to that
package as internal types
- Move the other types to `storage/samplingstore/model`

## 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 <137564277+ary82@users.noreply.github.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
  • Loading branch information
ary82 and yurishkuro authored Jan 12, 2025
1 parent 77c5f2a commit f60bd09
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plugin/sampling/strategyprovider/adaptive/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"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"
"github.com/jaegertracing/jaeger/plugin/sampling/leaderelection"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion plugin/sampling/strategyprovider/adaptive/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/samplingstrategy"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/distributedlock"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/jaegertracing/jaeger/plugin"
"github.com/jaegertracing/jaeger/storage/samplingstore"
smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/plugin/sampling/leaderelection"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/internal/metricstest"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
epmocks "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection/mocks"
"github.com/jaegertracing/jaeger/plugin/sampling/strategyprovider/adaptive/calculationstrategy"
smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func testThroughputs() []*model.Throughput {
Expand Down
2 changes: 1 addition & 1 deletion plugin/sampling/strategyprovider/adaptive/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/plugin/sampling/leaderelection"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const defaultFollowerProbabilityInterval = 20 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion plugin/sampling/strategyprovider/adaptive/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
epmocks "github.com/jaegertracing/jaeger/plugin/sampling/leaderelection/mocks"
"github.com/jaegertracing/jaeger/proto-gen/api_v2"
smocks "github.com/jaegertracing/jaeger/storage/samplingstore/mocks"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func TestProviderLoadProbabilities(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/badger/samplingstore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/dgraph-io/badger/v4"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
jaegermodel "github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/badger/samplingstore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/testutils"
samplemodel "github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func newTestSamplingStore(db *badger.DB) *SamplingStore {
Expand Down
22 changes: 16 additions & 6 deletions plugin/storage/cassandra/samplingstore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/gocql/gocql"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/cassandra"
casMetrics "github.com/jaegertracing/jaeger/pkg/cassandra/metrics"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const (
Expand All @@ -34,6 +34,16 @@ const (
getLatestProbabilities = `SELECT probabilities FROM sampling_probabilities WHERE bucket = ` + constBucketStr + ` LIMIT 1`
)

// probabilityAndQPS contains the sampling probability and measured qps for an operation.
type probabilityAndQPS struct {
Probability float64
QPS float64
}

// serviceOperationData contains the sampling probabilities and measured qps for all operations in a service.
// ie [service][operation] = ProbabilityAndQPS
type serviceOperationData map[string]map[string]*probabilityAndQPS

type samplingStoreMetrics struct {
operationThroughput *casMetrics.Table
probabilities *casMetrics.Table
Expand Down Expand Up @@ -127,8 +137,8 @@ func probabilitiesAndQPSToString(probabilities model.ServiceOperationProbabiliti
return buf.String()
}

func (s *SamplingStore) stringToProbabilitiesAndQPS(probabilitiesAndQPSStr string) model.ServiceOperationData {
probabilitiesAndQPS := make(model.ServiceOperationData)
func (s *SamplingStore) stringToProbabilitiesAndQPS(probabilitiesAndQPSStr string) serviceOperationData {
probabilitiesAndQPS := make(serviceOperationData)
appendFunc := s.appendProbabilityAndQPS(probabilitiesAndQPS)
s.parseString(probabilitiesAndQPSStr, 4, appendFunc)
return probabilitiesAndQPS
Expand Down Expand Up @@ -167,7 +177,7 @@ func (s *SamplingStore) stringToThroughput(throughputStr string) []*model.Throug
return throughput
}

func (s *SamplingStore) appendProbabilityAndQPS(svcOpData model.ServiceOperationData) func(csvFields []string) {
func (s *SamplingStore) appendProbabilityAndQPS(svcOpData serviceOperationData) func(csvFields []string) {
return func(csvFields []string) {
probability, err := strconv.ParseFloat(csvFields[2], 64)
if err != nil {
Expand All @@ -182,9 +192,9 @@ func (s *SamplingStore) appendProbabilityAndQPS(svcOpData model.ServiceOperation
service := csvFields[0]
operation := csvFields[1]
if _, ok := svcOpData[service]; !ok {
svcOpData[service] = make(map[string]*model.ProbabilityAndQPS)
svcOpData[service] = make(map[string]*probabilityAndQPS)
}
svcOpData[service][operation] = &model.ProbabilityAndQPS{
svcOpData[service][operation] = &probabilityAndQPS{
Probability: probability,
QPS: qps,
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/cassandra/samplingstore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/internal/metricstest"
"github.com/jaegertracing/jaeger/pkg/cassandra/mocks"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

var testTime = time.Date(2017, time.January, 24, 11, 15, 17, 12345, time.UTC)
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestStringToProbabilitiesAndQPS(t *testing.T) {
probabilities := s.stringToProbabilitiesAndQPS(testStr)

assert.Len(t, probabilities, 2)
assert.Equal(t, map[string]*model.ProbabilityAndQPS{
assert.Equal(t, map[string]*probabilityAndQPS{
http.MethodGet: {
Probability: 0.001,
QPS: 63.2,
Expand All @@ -358,7 +358,7 @@ func TestStringToProbabilitiesAndQPS(t *testing.T) {
QPS: 0.0,
},
}, probabilities["svc1"])
assert.Equal(t, map[string]*model.ProbabilityAndQPS{
assert.Equal(t, map[string]*probabilityAndQPS{
http.MethodGet: {
Probability: 0.5,
QPS: 34.2,
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/samplingstore/dbmodel/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package dbmodel

import (
"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func FromThroughputs(throughputs []*model.Throughput) []Throughput {
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/samplingstore/dbmodel/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func TestConvertDependencies(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/samplingstore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/olivere/elastic"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/plugin/storage/es/samplingstore/dbmodel"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/samplingstore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap"

samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/pkg/es/mocks"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/es/samplingstore/dbmodel"
samplemodel "github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

const defaultMaxDocCount = 10_000
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/storage/dependencystore"
"github.com/jaegertracing/jaeger/storage/samplingstore"
samplemodel "github.com/jaegertracing/jaeger/storage/samplingstore/model"
"github.com/jaegertracing/jaeger/storage/spanstore"
"github.com/jaegertracing/jaeger/storage_v2/depstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/memory/sampling.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

// SamplingStore is an in-memory store for sampling data
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/memory/sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

func withPopulatedSamplingStore(f func(samplingStore *SamplingStore)) {
Expand Down
2 changes: 1 addition & 1 deletion storage/samplingstore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package samplingstore
import (
"time"

"github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/storage/samplingstore/model"
)

// Store writes and retrieves sampling data to and from storage.
Expand Down
2 changes: 1 addition & 1 deletion storage/samplingstore/mocks/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,3 @@ type ServiceOperationProbabilities map[string]map[string]float64
// ServiceOperationQPS contains the qps for all operations in a service.
// ie [service][operation] = qps
type ServiceOperationQPS map[string]map[string]float64

// ProbabilityAndQPS contains the sampling probability and measured qps for an operation.
type ProbabilityAndQPS struct {
Probability float64
QPS float64
}

// ServiceOperationData contains the sampling probabilities and measured qps for all operations in a service.
// ie [service][operation] = ProbabilityAndQPS
type ServiceOperationData map[string]map[string]*ProbabilityAndQPS

0 comments on commit f60bd09

Please sign in to comment.