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

[ES] Refactor FindTraces and GetTrace of SpanReader to make them reusable for v2 APIs #6845

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Manik2708
Copy link
Contributor

Which problem is this PR solving?

Fixes a part of: #6458

Description of the changes

  • Refactoring of FindTraces and GetTrace to complete refactoring for ES Span Reader

How was this change tested?

  • Unit tests

Checklist

Signed-off-by: Manik2708 <[email protected]>
Signed-off-by: Manik2708 <[email protected]>
Signed-off-by: Manik2708 <[email protected]>
Signed-off-by: Manik2708 <[email protected]>
@Manik2708 Manik2708 requested a review from a team as a code owner March 12, 2025 19:11
@Manik2708 Manik2708 requested a review from mahadzaryab1 March 12, 2025 19:11
@Manik2708
Copy link
Contributor Author

Fixing tests!

Copy link

codecov bot commented Mar 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.00%. Comparing base (09d3484) to head (579212e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6845      +/-   ##
==========================================
- Coverage   96.06%   96.00%   -0.06%     
==========================================
  Files         367      368       +1     
  Lines       20787    20839      +52     
==========================================
+ Hits        19969    20007      +38     
- Misses        624      634      +10     
- Partials      194      198       +4     
Flag Coverage Δ
badger_v1 9.76% <0.00%> (-0.06%) ⬇️
badger_v2 1.96% <0.00%> (-0.02%) ⬇️
cassandra-4.x-v1-manual 14.72% <0.00%> (-0.08%) ⬇️
cassandra-4.x-v2-auto 1.95% <0.00%> (-0.02%) ⬇️
cassandra-4.x-v2-manual 1.95% <0.00%> (-0.02%) ⬇️
cassandra-5.x-v1-manual 14.72% <0.00%> (-0.08%) ⬇️
cassandra-5.x-v2-auto 1.95% <0.00%> (-0.02%) ⬇️
cassandra-5.x-v2-manual 1.95% <0.00%> (-0.02%) ⬇️
elasticsearch-6.x-v1 19.86% <82.24%> (+0.32%) ⬆️
elasticsearch-7.x-v1 19.94% <82.24%> (+0.32%) ⬆️
elasticsearch-8.x-v1 20.10% <82.24%> (+0.32%) ⬆️
elasticsearch-8.x-v2 1.96% <0.00%> (-0.02%) ⬇️
grpc_v1 10.79% <0.00%> (-0.06%) ⬇️
grpc_v2 7.87% <0.00%> (-0.05%) ⬇️
kafka-3.x-v1 10.05% <0.00%> (-0.06%) ⬇️
kafka-3.x-v2 1.96% <0.00%> (-0.02%) ⬇️
memory_v2 1.96% <0.00%> (-0.02%) ⬇️
opensearch-1.x-v1 19.99% <82.24%> (+0.32%) ⬆️
opensearch-2.x-v1 19.99% <82.24%> (+0.32%) ⬆️
opensearch-2.x-v2 1.96% <0.00%> (-0.02%) ⬇️
tailsampling-processor 0.47% <0.00%> (-0.01%) ⬇️
unittests 94.82% <95.32%> (-0.12%) ⬇️

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.

type Trace map[TraceID][]*Span

// LegacyTraceID is a type extracted from trace id model
type LegacyTraceID string
Copy link
Member

Choose a reason for hiding this comment

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

how is this different from TraceID type?

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 id is used in the query buildTraceByIDQuery. The logic of this getting this id from model.TraceID is this:

func getLegacyTraceID(traceID model.TraceID) dbmodel.LegacyTraceID {
	var legacyTraceID string
	if traceID.High == 0 {
		legacyTraceID = strconv.FormatUint(traceID.Low, 16)
	} else {
		legacyTraceID = fmt.Sprintf("%x%016x", traceID.High, traceID.Low)
	}
	return dbmodel.LegacyTraceID(legacyTraceID)
}

Please see that this is not something new, it was already in the codebase and since it is a refactor so I decided not to change it.

Copy link
Member

Choose a reason for hiding this comment

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

This logic is relevant to v1 reader only. Why does dbmodel and core reader need to know about it?

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 logic is in v1 only but the buildTraceByIDQuery needs legacy trace id, therefore a type is created and accepted as a parameter in FindTraces of core reader: type GetTraceAndLegacyTraceIdFn func(ctx context.Context, traceQuery *TraceQueryParameters) (map[TraceID]LegacyTraceID, error) and called in this way:

func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *dbmodel.TraceQueryParameters, getLegacyIdsFn dbmodel.GetTraceAndLegacyTraceIdFn) (dbmodel.Trace, error) {
	ctx, span := s.tracer.Start(ctx, "FindTraces")
	defer span.End()

	uniqueTraceIDs, err := getLegacyIdsFn(ctx, traceQuery)
	if err != nil {
		return nil, es.DetailedError(err)
	}
	return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax)
}

Copy link
Member

Choose a reason for hiding this comment

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

First, given how long ago the "legacy ID" logic was introduced (in 2019), we should introduce a feature gate that by default turns off support for these legacy IDs (allowing users to turn it on for a couple of release). Please make a separate PR for that.

Second, the actual "legacy" logic is simply padding shorter strings with 0s, so such logic (protected by above feature gate) can reside in the core reader without introducing this "legacy ID" duality in the API.

Copy link
Contributor Author

@Manik2708 Manik2708 Mar 13, 2025

Choose a reason for hiding this comment

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

That means, we have these two things to do:

  1. Remove the legacy ids and implement feature gate.
  2. Extract the legacy trace id from dbmodel.TraceID (string) itself.

Am I understanding right?

github-merge-queue bot pushed a commit that referenced this pull request Mar 14, 2025
## Which problem is this PR solving?
Fixes a part of #6458 

## Description of the changes
- As discussed in the comment
#6845 (comment),
legacy trace id is moved to feature gate

## How was this change tested?
- Unit and Integration 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants