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

[feature request] introduce a life cycle phase that allows some error checking on definition #438

Closed
jonseymour opened this issue Apr 8, 2016 · 6 comments

Comments

@jonseymour
Copy link
Contributor

It'd be nice if the object model used to support pipeline construction supported a "validate" phase that could do sanity checking of a node's configuration at definition time in a well-defined manner.

As it stands, some checks can be done when a property method is called (and then, only if one resorts to calling panic()) but in other cases (such as the failure to call join.as() - see #331/#431) the checks can't be done until runtime. If the parse tree supported the ability to execute validations once the script has been parsed, there may be additional validations that could be applied during the definition phase. Performing such validations early, if possible, is usually better than letting them occur at runtime.

@nathanielc
Copy link
Contributor

@jonseymour I believe this line does what you are asking. https://github.com/influxdata/kapacitor/blob/master/services/task_store/service.go#L489

Basically on saving an Task we fully instantiate an executing task to catch any errors.

I see three levels were errors can occur.

  1. Parse errors, invalid syntax etc.
  2. Validation errors, join.as() etc.
  3. Runtime errors, these errors should only depend on the data or external dependencies. All other errors should be caught before this step

On task define both levels 1 and 2 are checked.

@jonseymour
Copy link
Contributor Author

Ok, I'll see if I can move one of the tests in #431 into a spot where it will be caught prior to runtime.

@jonseymour
Copy link
Contributor Author

Closed - already does exactly what I ask

@jonseymour
Copy link
Contributor Author

Actually, I am going to reopen this and use the revised implementation of #431 as an example of the feature that I think is needed.

In the current implementation of #431 there are two tests I need to perform. Currently these tests run during task start. One of them could be implemented as a panic in pipeline.JoinNode.As() (which was my previous implementation), the other currently needs to run at task start because it is the only place where I know the definition of the join node is complete. So, right now, the tests execute at runtime, rather than definition time (although, as I said, one of them good potentially be rewritten to execute as a panic at definition time).

It would be ideal if both tests could execute at definition time. What is needed, I think, is an optional Validate hook on each pipeline node that allows final validations to be applied to the fully constructed node, perhaps something like:

import "pipeline"

type Node interface {
      Validate() error // apply whole of node validations to the constructed node.
}

which is called to validate the node at the end of construction.

@jonseymour jonseymour reopened this Apr 9, 2016
@jonseymour
Copy link
Contributor Author

I've pushed a suggested implementation to #443. I have also modified the #431 implementation to make use of it. Note that I also pushed some other validations of join nodes currently done at runtime to build time. I'll re-roll #431 if this PR is accepted.

@jonseymour
Copy link
Contributor Author

Closed via #443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants