Skip to content

Conversation

Manik2708
Copy link
Contributor

Which problem is this PR solving?

Fixes a part of: #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

Signed-off-by: Manik2708 <mehtamanik96@gmail.com>
@Manik2708 Manik2708 requested a review from a team as a code owner March 19, 2025 19:45
@Manik2708 Manik2708 requested a review from jkowall March 19, 2025 19:45
indexService.AssertNumberOfCalls(t, "Add", 1)
})
}

func TestNewSpanTags(t *testing.T) {
Copy link
Contributor Author

@Manik2708 Manik2708 Mar 19, 2025

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

@Manik2708 Manik2708 changed the title [ES] Separated the CoreSpanWriter from SpanWriter [ES] Separate the CoreSpanWriter from SpanWriter Mar 19, 2025
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.16%. Comparing base (d3f6682) to head (40360b2).
Report is 2 commits behind head on main.

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              
Flag Coverage Δ
badger_v1 10.21% <0.00%> (+<0.01%) ⬆️
badger_v2 2.12% <0.00%> (+<0.01%) ⬆️
cassandra-4.x-v1-manual 15.36% <0.00%> (+<0.01%) ⬆️
cassandra-4.x-v2-auto 2.11% <0.00%> (+<0.01%) ⬆️
cassandra-4.x-v2-manual 2.11% <0.00%> (+<0.01%) ⬆️
cassandra-5.x-v1-manual 15.36% <0.00%> (+<0.01%) ⬆️
cassandra-5.x-v2-auto 2.11% <0.00%> (+<0.01%) ⬆️
cassandra-5.x-v2-manual 2.11% <0.00%> (+<0.01%) ⬆️
elasticsearch-6.x-v1 20.12% <86.66%> (-0.03%) ⬇️
elasticsearch-7.x-v1 20.21% <86.66%> (-0.03%) ⬇️
elasticsearch-8.x-v1 20.38% <86.66%> (-0.03%) ⬇️
elasticsearch-8.x-v2 2.12% <0.00%> (+<0.01%) ⬆️
grpc_v1 11.28% <0.00%> (+<0.01%) ⬆️
grpc_v2 8.25% <0.00%> (+<0.01%) ⬆️
kafka-3.x-v1 10.51% <0.00%> (+<0.01%) ⬆️
kafka-3.x-v2 2.12% <0.00%> (+<0.01%) ⬆️
memory_v2 2.12% <0.00%> (+<0.01%) ⬆️
opensearch-1.x-v1 20.26% <86.66%> (-0.03%) ⬇️
opensearch-2.x-v1 20.26% <86.66%> (-0.03%) ⬇️
opensearch-2.x-v2 2.12% <0.00%> (+<0.01%) ⬆️
tailsampling-processor 0.57% <0.00%> (+<0.01%) ⬆️
unittests 94.91% <53.33%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Manik2708 <mehtamanik96@gmail.com>
spanWriter: NewSpanWriter(p),
spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement),
writerMetrics: spanWriterMetrics{
indexCreate: spanstoremetrics.NewWriter(p.MetricsFactory, "index_create"),
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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))

Copy link
Contributor Author

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",
Copy link
Member

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).

Copy link
Contributor Author

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

Signed-off-by: Manik2708 <mehtamanik96@gmail.com>
@Manik2708 Manik2708 requested a review from yurishkuro March 20, 2025 08:55
@@ -146,3 +146,58 @@ func TestConvertKeyValueValue(t *testing.T) {
})
}
}

func TestNewSpanTags(t *testing.T) {
Copy link
Contributor Author

@Manik2708 Manik2708 Mar 20, 2025

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

@Manik2708
Copy link
Contributor Author

@yurishkuro Please can you review this PR! As this is a blocker for the next PR.

@yurishkuro yurishkuro added the changelog:refactoring Internal code refactoring without functional changes label Mar 21, 2025
@yurishkuro
Copy link
Member

As this is a blocker for the next PR.

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.

@Manik2708
Copy link
Contributor Author

As this is a blocker for the next PR.

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 dbmodel to shared package and CoreSpanReader/Writer to v2, so implementing this is necessary.

@yurishkuro
Copy link
Member

No, my next PR will be moving dbmodel to shared package and CoreSpanReader/Writer to v2, so implementing this is necessary.

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.

Signed-off-by: Manik2708 <mehtamanik96@gmail.com>
@Manik2708 Manik2708 requested a review from yurishkuro March 21, 2025 17:23
Comment on lines +23 to +24
converter := dbmodel.NewFromDomain(true, []string{}, "-")
writerV1 := &SpanWriterV1{spanWriter: coreWriter, spanConverter: converter}
Copy link
Member

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()?

Copy link
Contributor Author

@Manik2708 Manik2708 Mar 21, 2025

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

We can't use the mocks by using the NewSpanWriterV1() (as it takes SpanWriterParams)

Copy link
Member

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?

Copy link
Contributor Author

@Manik2708 Manik2708 Mar 22, 2025

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.

Copy link
Member

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.

@yurishkuro yurishkuro enabled auto-merge March 22, 2025 17:17
@yurishkuro yurishkuro added this pull request to the merge queue Mar 22, 2025
auto-merge was automatically disabled March 22, 2025 17:33

Pull Request is not mergeable

Merged via the queue into jaegertracing:main with commit 23cf383 Mar 22, 2025
56 checks passed
Manik2708 added a commit to Manik2708/jaeger that referenced this pull request Mar 23, 2025
)

## 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>
@AnmolxSingh AnmolxSingh mentioned this pull request Apr 9, 2025
4 tasks
amilbcahat pushed a commit to amilbcahat/jaeger that referenced this pull request May 4, 2025
)

## 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>
amilbcahat pushed a commit to amilbcahat/jaeger that referenced this pull request May 4, 2025
)

## 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>
github-merge-queue bot pushed a commit that referenced this pull request May 12, 2025
## 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>
iypetrov pushed a commit to iypetrov/jaeger that referenced this pull request May 14, 2025
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:refactoring Internal code refactoring without functional changes storage/elasticsearch v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants