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

fix: skip sources when their parent source failed #396

Merged
merged 1 commit into from
Nov 29, 2021

Conversation

dduportal
Copy link
Contributor

@dduportal dduportal commented Nov 25, 2021

Fix #285

When a source, referenced through a template function {{ source `<source id>` }} on another source, is failing,
then the "children" sources are now skipped with an error message.

No worry for conditions: if any source fail, then the condition are never run.

Test

To test this pull request, you can run the following commands:

$ cat .tmp/updatecli.yaml
sources:
  parentSource:
    kind: shell
    spec:
      command: ls /titi
  childSource:
    kind: shell
    depends_on:
      - parentSource
    spec:
      command: echo CHILD-{{ source "parentSource" }}
target:
  printResult:
    kind: shell
    sourceID: childSource
    spec:
      command: echo

$ go build -o ./dist/updatecli && ./dist/updatecli --debug diff -c .tmp/updatecli.yaml

example of output:

SOURCES
=======

parentSource
------------
The shell 🐚 command "ls /titi" exited on error (exit code 1) with the following output:
----
----

command stderr output was:
----
ls: /titi: No such file or directory

----
ERROR: ✗ Shell command exited on error.
Pipeline "UPDATECLI.YAML" failed
Skipping due to:
        "sources stage:\t\"template: cfg:25:35: executing \\\"cfg\\\" at <source \\\"parentSource\\\">: error calling source: Parent source \\\"parentSource\\\" failed\"\n"
sources stage:  "template: cfg:25:35: executing \"cfg\" at <source \"parentSource\">: error calling source: Parent source \"parentSource\" failed"

=============================

REPORTS:


✗ UPDATECLI.YAML:
        Sources:
                - [childSource] (shell)
                ✗ [parentSource] (shell)
        Target:

Additional Information

Tradeoff

Potential improvement

@olblak
Copy link
Member

olblak commented Nov 26, 2021

I think you are solving half of the problem here. I see two scenarios that we need to cover

  1. Source B that depends on Source A with templating involved which is solved by this PR 🎉
  2. Source B that depends on Source A without templating.

In the second scenario, I think before executing a source, we need to validate that sources listed in the dependency list succeeded.
Just before this line

Something like

for _, dependedSource := range s.dependsOn {
    if p.Sources[dependencySource].Result == result.Failure {
    // skipping source as depended source already failed
   }
}

Copy link
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

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

I don't think that the pull request in the current stage, fully solve the problem

@dduportal
Copy link
Contributor Author

I think you are solving half of the problem here. I see two scenarios that we need to cover

1. Source B that depends on Source A with templating involved which is solved by this PR 🎉

2. Source B that depends on Source A without templating.

In the second scenario, I think before executing a source, we need to validate that sources listed in the dependency list succeeded. Just before this line

Something like

for _, dependedSource := range s.dependsOn {
    if p.Sources[dependencySource].Result == result.Failure {
    // skipping source as depended source already failed
   }
}

Good catch, thanks! Implemented (same idea with the loop, sligthly different if cases) WDYT?

@dduportal
Copy link
Contributor Author

Let me rebase @olblak (in the next 5 min)

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal
Copy link
Contributor Author

@olblak ready to review :)

for _, parentSource := range source.Config.DependsOn {
if p.Sources[parentSource].Result != result.SUCCESS {
logrus.Warningf("Parent source[%q] did not succeed. Skipping execution of the source[%q]", parentSource, id)
shouldRunSource = false
Copy link
Member

Choose a reason for hiding this comment

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

What do you think to break early if we identify that a "source" failed.

Suggested change
shouldRunSource = false
shouldRunSource = false
break

Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if we need to explicitly set the current source result to result.Failure if one of the dependency failed.
Such as

Suggested change
shouldRunSource = false
shouldRunSource = false
source.Result = result.FAILURE

Copy link
Contributor Author

@dduportal dduportal Nov 29, 2021

Choose a reason for hiding this comment

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

I am wondering if we need to explicitly set the current source result to result.Failure if one of the dependency failed.

That feels weird since the source was not run (e.g. skipped).
Do not forget that, as for today, the default state of a source is "skipped", which is the reason why no state change is done here (otherwise I would have set it to "skipped" instead of whatever default, because it's not run).
I vote for reporting "skipped, but I don't mind enforcing the "skipped" status here (even if it's the default), so a change of the default would not break it. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think to break early if we identify that a "source" failed.

Could be discussed, but not in the scope of this PR, because it would be a breaking change in the UX behavior. Do you mind raising an issue on that topicas enhancement?

Copy link
Member

@olblak olblak left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request, I made minor suggestions that I don't consider blocker for merging.
Feel free to proceed

@dduportal
Copy link
Contributor Author

@olblak thanks for the review. I've answered to your 2 elements: both are outside of the scope of the PR but are legit questions (and worth an issue).

I'm merging (as it's expected to be minor) since I got your approval, don't hesitate to open issues on the topic, or revert the PR if you see something we missed :)

@dduportal dduportal merged commit 3b424f1 into updatecli:main Nov 29, 2021
@dduportal dduportal deleted the fix/gh-285 branch November 29, 2021 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: source executed while their parent source failed
2 participants