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

Backend: Refactor trace spans (query building + response processing) #257

Merged
merged 21 commits into from Nov 17, 2023

Conversation

idastambuk
Copy link
Contributor

@idastambuk idastambuk commented Sep 13, 2023

What this PR does / why we need it:
Implements #223

Support for trace spans on the backend, only in Explore, to follow our rollout stage plan.

Screenshot 2023-10-19 at 8 38 31 PM

Which issue(s) this PR fixes:

Fixes #223

Special notes for your reviewer:
I couldn't get the snapshot test to work, because in response processing I worked with a lot of maps, which makes the output not follow consistent order of fields. This doesn't matter when it comes to the trace visualization, as it needs specific named fields to display different parts of the UI. Therefore I decided I wouldn't change the original code in order to comply with tests (like sorting fields etc), but added a few utils int he tests to just check that all the fields are in the output, wherever.

@@ -188,8 +188,7 @@ function getStackTraces(events: OpenSearchSpanEvent[]): string[] | undefined {
const stackTraces = events
.filter(event => event.attributes.error)
.map(event => `${event.name}: ${event.attributes.error}`);
// if we return an empty array, Trace panel plugin shows "0"
return stackTraces.length > 0 ? stackTraces : undefined;
return stackTraces;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed this in the Trace plugin a while ago, so Im updating this.

@idastambuk idastambuk marked this pull request as ready for review October 19, 2023 19:01
@idastambuk idastambuk requested a review from a team as a code owner October 19, 2023 19:01
@idastambuk idastambuk requested review from iwysiu, kevinwcyu and fridgepoet and removed request for a team October 19, 2023 19:01
src/datasource.ts Outdated Show resolved Hide resolved
pkg/opensearch/client/models.go Outdated Show resolved Hide resolved
pkg/opensearch/lucene_handler.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/lucene_handler.go Show resolved Hide resolved
pkg/opensearch/response_parser.go Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
@idastambuk idastambuk linked an issue Nov 13, 2023 that may be closed by this pull request
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

The changes look good! I added a few more small comments.

As a heads up, if you rebase and force push a PR that already has comments on it, it messes up the history and breaks the links for all the old comments, which makes it harder to review. You can do a merge commit instead to fix the merge conflicts.

// QueryStringFilter represents a query string search filter
type QueryStringFilter struct {
Filter
Query string
AnalyzeWildcard bool
}

func (m MustTerm) MarshalJSON() ([]byte, error) {
root := map[string]interface{}{}
if m.Term != nil && m.Term.TraceId != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it necessarily make sense here (because of the possibility of Term being non-nil but TraceId being "") but as a fun fact, you can use the omitEmpty json flag to skip empty fields and set json names without having to write a custom 'MarshalJSON' function

"github.com/stretchr/testify/require"
)

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

Choose a reason for hiding this comment

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

The comment looks good! This file should have the same comment as lucene_trace_list_test.go

pkg/utils/utils.go Outdated Show resolved Hide resolved
Key string
Value any
}
func sortObjectsByKey(rawObject *data.Field) []KeyValue {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having panics in these helper functions, you can pass them a testing.T and call require in them. (You can mark them as helper functions with the line t.Helper() at the start of the function and test errors will be returned as the line that calls the function)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😲 Good to know!

pkg/opensearch/lucene_handler.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Nice work on all the go code! Approved with one incredibly nitpicky style comment.

if jsonRawMessage == nil {
panic("json.RawMessage is nil")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Deeply obnoxious style nit: To keep variables/requires in relevant code blocks, this could be:

jsonRawMessage, ok := rawObject.At(0).(*json.RawMessage)
require.True(t, ok)
require.NotNil(t, jsonRawMessage)

var sortedObject []KeyValue
err := json.Unmarshal(*jsonRawMessage, &sortedObject)
require.Nil(t, err)

(same for sortLogsByTimestamp)

@idastambuk idastambuk changed the title Refactor trace spans (query building + response processing) Backend: Refactor trace spans (query building + response processing) Nov 17, 2023
@idastambuk idastambuk merged commit 7cef142 into main Nov 17, 2023
4 checks passed
@idastambuk idastambuk deleted the refactor-trace-spans branch November 17, 2023 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants