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

processor/transform Add implementation of query processing #7129

Merged

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Jan 11, 2022

Description:

Adds the business logic for parsing queries

Link to tracking Issue: open-telemetry/opentelemetry-collector#4444

Testing: Unit tests

Documentation: README

@anuraaga anuraaga requested a review from bogdandrutu as a code owner January 11, 2022 07:18
@anuraaga anuraaga requested a review from a team January 11, 2022 07:18
@anuraaga anuraaga force-pushed the processor-expression-trace-impl branch from f68bb36 to 83a762b Compare January 11, 2022 07:19
@anuraaga anuraaga requested a review from punya January 13, 2022 00:16
@alolita
Copy link
Member

alolita commented Jan 13, 2022

@bogdandrutu @punya @Aneurysm9 - friendly ping for your reviews!

p, err := factory.CreateTracesProcessor(context.Background(), component.ProcessorCreateSettings{}, p0, consumertest.NewNop())
assert.NoError(t, err)

td := constructTraces()
Copy link
Member

Choose a reason for hiding this comment

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

Very hard to read the test since I have to jump in 5 places (random number) to understand what is the input and how the checks that you have later make sense.

I prefer tests to have clear "input" and "output" expectations in one place.

// limitations under the License.

// struct tags are special format so disable govet
// nolint:govet
Copy link
Member

Choose a reason for hiding this comment

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

I would disable this at the struct level, and let it run for the rest of the code.

},
})
assert.NoError(t, configtest.CheckConfigStruct(cfg))
}

func TestFactory_LoadConfig(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

The way how this is written, is more or less a test for the processor now. May consider to add a Equal method on the Query to simplify load config test?

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
)

var registry = make(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

We try to avoid global variables, may not be a bad idea to pass "availableFuncs" instead.

}
}

func constructTraces() pdata.Traces {
Copy link
Member

Choose a reason for hiding this comment

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


// Query holds a top level Query for processing trace data. A Query is a combination of a function
// invocation and the condition to match telemetry for invoking the function.
type Query struct {
Copy link
Member

Choose a reason for hiding this comment

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

Confused about multiple Query structs.

Comment on lines 78 to 82
function, err := newFunctionCall(parsed.Invocation)
if err != nil {
return err
}
condition, err := newConditionEvaluator(parsed.Condition)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is ok, if the "funcs" have state for example you force to have them shared across multiple instances of the processor. So I think you should parse the query here in common.Query(). then have a "Validate" to validate that funcs are registered/available (you can do that here as well). But the construction of the funcs probably need to happen in the constructor of the processor.

@bogdandrutu
Copy link
Member

@alolita very hard to find 1-2 hours block to do a 2500 lines code review, that is why I am keep saying that we need to split PRs. Here we could have easily have a simple PR that adds the query parser. then the registry, then plug everything.

@anuraaga
Copy link
Contributor Author

Here we could have easily have a simple PR that adds the query parser. then the registry, then plug everything.

Thanks @bogdandrutu - it's helpful to get a suggestion on how to split up the PR to make sure not to split it in unhelpful ways. I will split along these lines

@anuraaga anuraaga force-pushed the processor-expression-trace-impl branch from 83a762b to 9a4e8be Compare January 19, 2022 08:26
@anuraaga anuraaga changed the title processor/transform Add implementation of traces processing. processor/transform Add implementation of query processing Jan 19, 2022
@anuraaga
Copy link
Contributor Author

@bogdandrutu I split this down to only the parser logic

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

In general LGTM, only one question regarding the public parse API.

processor/transformprocessor/internal/common/parser.go Outdated Show resolved Hide resolved
Copy link
Member

@Aneurysm9 Aneurysm9 left a comment

Choose a reason for hiding this comment

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

I'm not as worried about exposing Participle since this is in an internal package, but now would probably be the easiest time to make that change if it is to be done.

@bogdandrutu bogdandrutu enabled auto-merge (squash) January 20, 2022 17:32
@bogdandrutu bogdandrutu added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jan 20, 2022
@bogdandrutu bogdandrutu merged commit 65e8df0 into open-telemetry:main Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants