-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[ES] Separate the CoreSpanWriter
from SpanWriter
#6883
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
Conversation
Signed-off-by: Manik2708 <mehtamanik96@gmail.com>
indexService.AssertNumberOfCalls(t, "Add", 1) | ||
}) | ||
} | ||
|
||
func TestNewSpanTags(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is moved to from_domain_test.go
CoreSpanWriter
from SpanWriter
CoreSpanWriter
from SpanWriter
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6883 +/- ##
==========================================
- Coverage 96.17% 96.16% -0.02%
==========================================
Files 341 342 +1
Lines 19738 19735 -3
==========================================
- Hits 18983 18978 -5
- Misses 571 573 +2
Partials 184 184
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
spanWriter: NewSpanWriter(p), | ||
spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement), | ||
writerMetrics: spanWriterMetrics{ | ||
indexCreate: spanstoremetrics.NewWriter(p.MetricsFactory, "index_create"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you pull metrics away from core writer? it's a reusable functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done to make CoreSpanWriter
independent of api/v1/spanstore
. If metrics factory is gonna remain same then I think we should move it to either shared pkg
or v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these metrics were used to be called from inside the business logic of the writer (last line below). So you cannot have them at the v1 writer level, then need to be internal to the core writer. In what sense is there a dependency on api/v1/spanstore
? spanstoremetrics
is an independent package.
func (s *SpanWriter) createIndex(indexName string, mapping string, jsonSpan *jModel.Span) error {
if !keyInCache(indexName, s.indexCache) {
start := time.Now()
exists, _ := s.client.IndexExists(indexName).Do(s.ctx) // don't need to check the error because the exists variable will be false anyway if there is an error
if !exists {
// if there are multiple collectors writing to the same elasticsearch host a race condition can occur - create the index multiple times
// we check for the error type to minimize errors
_, err := s.client.CreateIndex(indexName).Body(s.fixMapping(mapping)).Do(s.ctx)
s.writerMetrics.indexCreate.Emit(err, time.Since(start))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I tried to remove:
"github.com/jaegertracing/jaeger/internal/storage/v1/api/spanstore/spanstoremetrics"
spanstoremetrics
lie in spanstore
Tag: map[string]any{"foo": "bar"}, Tags: []dbmodel.KeyValue{}, | ||
Process: dbmodel.Process{Tag: map[string]any{"bar": "baz"}, Tags: []dbmodel.KeyValue{}}, | ||
}, | ||
name: "allTagsAsFields", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which functionality is being tested the most here, core writer or v1 wrapper? I think it's core writer, and the test should stay with it. A simple way to validate - if you delete this test and the code coverage of the core writer drops, then the test is in the wrong place (because we will delete it in a year).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now realized that, this test should be in from_domain_test.go
as it is only testing FromDomainEmbedProcess
@@ -146,3 +146,58 @@ func TestConvertKeyValueValue(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestNewSpanTags(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was previously present in writer_test.go
, it was testing FromDomainEmbedProcess
via reader, for example this is how it was testing in writer: test.writer.spanWriter.spanConverter.FromDomainEmbedProcess(s)
. If it's only aim is to test a method of FromDomain, then it should be present in from_domain
not in writer
@yurishkuro Please can you review this PR! As this is a blocker for the next PR. |
internal/storage/v1/elasticsearch/spanstore/internal/dbmodel/from_domain_test.go
Outdated
Show resolved
Hide resolved
why is it a blocker? Your next PR is introducing v2 writer, correct? It's a minor adjustment to that PR where the core writer is located. |
No, my next PR will be moving |
I think you're taking this too literally. You can start work on implementing v2 writer, it doesn't matter where the core writer is currently located. We can always move it later. |
converter := dbmodel.NewFromDomain(true, []string{}, "-") | ||
writerV1 := &SpanWriterV1{spanWriter: coreWriter, spanConverter: converter} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you not using NewSpanWriterV1()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more similar to
spanReader: spanReader, |
NewSpanWriterV1()
(as it takes SpanWriterParams
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use the mocks by using the NewSpanWriterV1() (as it takes SpanWriterParams)
why can't we use mocks with SpanWriterParams?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because SpanWriterParams
initializes span writer by creating CoreSpanWriter
in this way:
func NewSpanWriterV1(p SpanWriterParams) *SpanWriterV1 {
return &SpanWriterV1{
spanWriter: NewSpanWriter(p),
spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement),
}
}
Further NewSpanWriter(p)
initalizes this way:
func NewSpanWriter(p SpanWriterParams) *SpanWriter {
serviceCacheTTL := p.ServiceCacheTTL
if p.ServiceCacheTTL == 0 {
serviceCacheTTL = serviceCacheTTLDefault
}
writeAliasSuffix := ""
if p.UseReadWriteAliases {
if p.WriteAliasSuffix != "" {
writeAliasSuffix = p.WriteAliasSuffix
} else {
writeAliasSuffix = "write"
}
}
serviceOperationStorage := NewServiceOperationStorage(p.Client, p.Logger, serviceCacheTTL)
return &SpanWriter{
client: p.Client,
logger: p.Logger,
serviceWriter: serviceOperationStorage.Write,
spanServiceIndex: getSpanAndServiceIndexFn(p, writeAliasSuffix),
}
}
But in tests we need mocks.CoreSpanWriter
, therefore we can't use these methods to use mocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you can use mock Client. You need at least one unit test that invokes the constructor.
Pull Request is not mergeable
) ## Which problem is this PR solving? Fixes a part of: jaegertracing#6458 ## Description of the changes - We have to prepeare the writer to move to `v2` and for that we need to separate `SpanWriter` ## How was this change tested? - Unit Tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: Manik2708 <mehtamanik96@gmail.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
) ## Which problem is this PR solving? Fixes a part of: jaegertracing#6458 ## Description of the changes - We have to prepeare the writer to move to `v2` and for that we need to separate `SpanWriter` ## How was this change tested? - Unit Tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: Manik2708 <mehtamanik96@gmail.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
) ## Which problem is this PR solving? Fixes a part of: jaegertracing#6458 ## Description of the changes - We have to prepeare the writer to move to `v2` and for that we need to separate `SpanWriter` ## How was this change tested? - Unit Tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: Manik2708 <mehtamanik96@gmail.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Signed-off-by: amol-verma-allen <amol.verma@allen.in>
## Which problem is this PR solving? - Resolves #6891 ## Description of the changes - Reintroduced metrics which were lost during #6883 ## How was this change tested? - Ran writer tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: anmol7344 <anmol7344@gmail.com> Signed-off-by: Anmol <166167480+AnmolxSingh@users.noreply.github.com> Signed-off-by: Yuri Shkuro <github@ysh.us> Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <github@ysh.us>
## Which problem is this PR solving? - Resolves jaegertracing#6891 ## Description of the changes - Reintroduced metrics which were lost during jaegertracing#6883 ## How was this change tested? - Ran writer tests ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] 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: anmol7344 <anmol7344@gmail.com> Signed-off-by: Anmol <166167480+AnmolxSingh@users.noreply.github.com> Signed-off-by: Yuri Shkuro <github@ysh.us> Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com> Co-authored-by: Yuri Shkuro <github@ysh.us>
Which problem is this PR solving?
Fixes a part of: #6458
Description of the changes
v2
and for that we need to separateSpanWriter
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:npm run lint
andnpm run test