Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenancy for memory storage #3827

Merged
merged 6 commits into from
Jul 23, 2022
Merged

Conversation

esnible
Copy link
Contributor

@esnible esnible commented Jul 21, 2022

Signed-off-by: Ed Snible [email protected]

This PR adds tenancy support to the memory storage.

@esnible esnible requested a review from a team as a code owner July 21, 2022 17:34
@esnible esnible requested a review from albertteoh July 21, 2022 17:34
Signed-off-by: Ed Snible <[email protected]>
@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #3827 (ba841a6) into main (ddca3c8) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #3827      +/-   ##
==========================================
- Coverage   97.58%   97.57%   -0.01%     
==========================================
  Files         291      291              
  Lines       16913    16938      +25     
==========================================
+ Hits        16504    16527      +23     
- Misses        323      325       +2     
  Partials       86       86              
Impacted Files Coverage Δ
plugin/storage/memory/factory.go 100.00% <100.00%> (ø)
plugin/storage/memory/memory.go 100.00% <100.00%> (ø)
...lugin/sampling/strategystore/adaptive/processor.go 99.38% <0.00%> (-0.62%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ddca3c8...ba841a6. Read the comment docs.

Signed-off-by: Ed Snible <[email protected]>
"github.com/jaegertracing/jaeger/storage/spanstore"
)

// Store is an in-memory store of traces
type Store struct {
sync.RWMutex
config config.Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend keeping config at the Tenant struct level (copy the same one for now), because it seems very reasonable to want per-tenant quota settings rather than one global setting. Or maybe not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant was this:

type Store struct {
  // Each tenant gets a copy of default config.
  // In the future this can be extended to contain per-tenant configuration.
  defaultConfig config.Config
}
type Tenant struct {
  config config.Config
}

func (s *Store) newTenant() *Tenant {
  return &Tenant{
    config: s.defaultConfig
  }
}

}
}

// GetTenant returns the per-tenant storage. Note that tenantID has already been checked for by the collector or query
func (st *Store) GetTenant(tenantID string) *Tenant {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be public?

Signed-off-by: Ed Snible <[email protected]>
"github.com/jaegertracing/jaeger/storage/spanstore"
)

// Store is an in-memory store of traces
type Store struct {
sync.RWMutex
config config.Configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant was this:

type Store struct {
  // Each tenant gets a copy of default config.
  // In the future this can be extended to contain per-tenant configuration.
  defaultConfig config.Config
}
type Tenant struct {
  config config.Config
}

func (s *Store) newTenant() *Tenant {
  return &Tenant{
    config: s.defaultConfig
  }
}

func (st *Store) getTenant(tenantID string) *Tenant {
tenant, ok := st.perTenant[tenantID]
if !ok {
// We do the lookup twice to skip locking on retrieval of existing tenant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't really do this because you're doing unprotected read above that could cause a concurrency issue. Test with -race should catch this. If you're worried about locking, you can either use RWLock or use a sync.Map which is specifically designed for frequent reads / rare writes.


func (st *Store) newTenant() *Tenant {
return &Tenant{
ids: make([]*model.TraceID, st.defaultConfig.MaxTraces),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can decouple this func from the knowledge of defaultConfig:

// caller
newTenant(st.defaultConfig)

func (st *Store) newTenant(cfg config.Config) *Tenant {
  // ...
}

@@ -290,7 +330,7 @@ func (m *Store) validSpan(span *model.Span, query *spanstore.TraceQueryParameter
return true
}

func (m *Store) flattenTags(span *model.Span) model.KeyValues {
func flattenTags(span *model.Span) model.KeyValues {
retMe := span.Tags
retMe = append(retMe, span.Process.Tags...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like existing bug - it could mutate span.Tags

@@ -53,6 +54,32 @@ var testingSpan = &model.Span{
StartTime: time.Unix(300, 0).UTC(),
}

var traceID2 = model.NewTraceID(2, 3)

var testingSpan2 = &model.Span{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: turn testingSpan into a function that takes a few args distinguishing the traces (like trace id)

@yurishkuro yurishkuro enabled auto-merge (squash) July 23, 2022 19:21
@yurishkuro yurishkuro merged commit 7b33160 into jaegertracing:main Jul 23, 2022
@esnible esnible deleted the memory-tenancy branch July 24, 2022 00:26
albertteoh pushed a commit to albertteoh/jaeger that referenced this pull request Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants