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

1405 [Transactions] Display parsed value when hovering over Interpolations#1405 #1447

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
99aa04c
1427 adding expression parse endpoint
xoscar Oct 28, 2022
84babfe
1427 fixing unit tests
xoscar Oct 28, 2022
3edc748
1427 improving validation checks and adding unit tests
xoscar Oct 31, 2022
9a5187d
Integrate environments
jorgeepc Oct 31, 2022
717e389
Merge branch '1436-integrate-environments' into 1405-transactions-dis…
xoscar Oct 31, 2022
129a3cd
Merge branch 'main' into 1427-transactions-create-parse-statement-ser…
xoscar Nov 1, 2022
8bfc3c5
1427 updating context request info and adding some validation checks
xoscar Nov 1, 2022
79902e0
Merge branch '1427-transactions-create-parse-statement-service' into …
xoscar Nov 1, 2022
6fd6914
1405 wiring up the parse expression service
xoscar Nov 1, 2022
a51fbd4
1405 minor fixes and cleanup
xoscar Nov 1, 2022
ced9a27
remove wildcard from parser rule
mathnogueira Nov 1, 2022
bbb9fe5
1427 improving naming
xoscar Nov 1, 2022
a0fb59c
Merge branch '1427-transactions-create-parse-statement-service' into …
xoscar Nov 1, 2022
3bf54bc
Merge branch '1427-transactions-create-parse-statement-service' of gi…
xoscar Nov 1, 2022
8495c9d
Merge branch '1427-transactions-create-parse-statement-service' into …
xoscar Nov 1, 2022
042786c
1405 accomoading naming changes
xoscar Nov 1, 2022
c815979
Merge branch 'main' into 1405-transactions-display-parsed-value-when-…
xoscar Nov 1, 2022
53bc98f
Merge branch 'main' into 1405-transactions-display-parsed-value-when-…
xoscar Nov 1, 2022
92c6648
1405 adding several minor ux improvements
xoscar Nov 1, 2022
d6a3bc7
Merge branch 'main' into 1405-transactions-display-parsed-value-when-…
xoscar Nov 1, 2022
37124bd
1405 adding context to output attribute editor
xoscar Nov 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1427 improving validation checks and adding unit tests
  • Loading branch information
xoscar committed Oct 31, 2022
commit 3edc748e949c13e5544dbdbe9cc0e95cc8d45b8c
136 changes: 136 additions & 0 deletions server/expression/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,139 @@ func executeTestCases(t *testing.T, testCases []executorTestCase) {
})
}
}

func TestBasicStatementExecution(t *testing.T) {
testCases := []executorTestCase{
{
Name: "should_parse_a_single_integer",
Query: `1`,
ShouldPass: true,
},
{
Name: "should_parse_double_quoted_strings",
Query: `"matheus"`,
ShouldPass: true,
},
}

executeParseStatementTestCases(t, testCases)
}

func TestParseStatementAttributeExecution(t *testing.T) {
testCases := []executorTestCase{
{
Name: "should_get_values_from_attributes",
Query: "attr:my_attribute",
ShouldPass: true,

AttributeDataStore: expression.AttributeDataStore{
Span: traces.Span{
Attributes: traces.Attributes{
"my_attribute": "42",
},
},
},
},
}

executeParseStatementTestCases(t, testCases)
}

func TestParseStatementVariableExecution(t *testing.T) {
testCases := []executorTestCase{
{
Name: "should_get_values_from_variables",
Query: "var:my_variable",
ShouldPass: true,

VariableDataStore: expression.VariableDataStore(map[string]string{
"my_variable": "42",
"other_variable": "41",
}),
},
}

executeParseStatementTestCases(t, testCases)
}

func TestParseStatementStringInterpolationExecution(t *testing.T) {
testCases := []executorTestCase{
{
Name: "should_interpolate_simple_values",
Query: `'this run took ${"25ms"}'`,
ShouldPass: true,
AttributeDataStore: expression.AttributeDataStore{
Span: traces.Span{
Attributes: traces.Attributes{
"text": "this run took 25ms",
},
},
},
},
{
Name: "should_interpolate_multiple_values",
Query: `'${1} is a number, ${"dog"} is a string, and ${1ms + 1ns} is a duration'`,
ShouldPass: true,
},
}

executeParseStatementTestCases(t, testCases)
}

func TestParseStatementFilterExecution(t *testing.T) {
testCases := []executorTestCase{
{
Name: "should_extract_id_from_json",
Query: `attr:tracetest.response.body`,
ShouldPass: true,
AttributeDataStore: expression.AttributeDataStore{
Span: traces.Span{
Attributes: traces.Attributes{
"tracetest.response.body": `{"id": 8, "name": "john doe"}`,
},
},
},
},
{
Name: "should_support_filters_with_arguments_containing_spaces",
Query: `'{ "name": "john", "age": 37 }' | regex_group '"age": (\d+)'`,
ShouldPass: true,
},
{
Name: "should_support_multiple_filters",
Query: `'{ "array": [{ "name": "john", "age": 37 }, { "name": "jonas", "age": 38 }]}' | regex_group '"age": (\d+)' | get_index 1`,
ShouldPass: true,
},
{
Name: "should_count_array_input",
Query: `'{ "array": [1, 2, 3] }' | json_path '$.array[*]' | length`,
ShouldPass: true,
},
{
Name: "should_get_last_item_from_list",
Query: `'{ "array": [1, 2, 5] }' | json_path '$.array[*]' | get_index 'last'`,
ShouldPass: true,
},
}

executeParseStatementTestCases(t, testCases)
}

func executeParseStatementTestCases(t *testing.T, testCases []executorTestCase) {
for _, testCase := range testCases {
t.Run(testCase.Name, func(t *testing.T) {
executor := expression.NewExecutor(
testCase.AttributeDataStore,
testCase.MetaAttributesDataStore,
testCase.VariableDataStore,
)
left, err := executor.ParseStatement(testCase.Query)
debugMessage := fmt.Sprintf("left value: %s", left)
if testCase.ShouldPass {
assert.NoError(t, err, debugMessage)
} else {
assert.Error(t, err, debugMessage)
}
})
}
}
20 changes: 11 additions & 9 deletions server/http/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func (c *controller) buildDataStores(ctx context.Context, info openapi.ParseRequ

ds := []expression.DataStore{}

if context.Attr.RunId != "" {
if context.Attr.RunId != "" && context.Attr.TestId != "" {
attr := context.Attr
runId, err := strconv.Atoi(attr.RunId)

Expand All @@ -669,17 +669,19 @@ func (c *controller) buildDataStores(ctx context.Context, info openapi.ParseRequ
return []expression.DataStore{}, err
}

spanId, err := trace.SpanIDFromHex(attr.SpanId)
if context.Attr.SpanId != "" {
spanId, err := trace.SpanIDFromHex(attr.SpanId)

if err != nil {
return []expression.DataStore{}, err
}
if err != nil {
return []expression.DataStore{}, err
}

span := run.Trace.Flat[spanId]
span := run.Trace.Flat[spanId]

ds = append([]expression.DataStore{expression.AttributeDataStore{
Span: *span,
}}, ds...)
ds = append([]expression.DataStore{expression.AttributeDataStore{
Span: *span,
}}, ds...)
}

if attr.Selector != "" {
selector, err := selectors.New(attr.Selector)
Expand Down