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

watcher keep alive even get 304 not modified #36

Merged
merged 15 commits into from
Sep 6, 2022

Conversation

kkdeok
Copy link
Contributor

@kkdeok kkdeok commented Aug 3, 2022

Hi all! I'm really happy to see this project. I'm working on some python project and it use central dogma so this is what I really want! I've test it in my project and I've found the repository watcher is dead after 304 response.

I think it because here. new_latest revision is None when 304 returned so schedule_watch is not triggered. So I moved schedule_watch out from if statement. Could you please check if it makes sense to you? I worried about stackeoverflow but, focused on keeping alive watcher for now.

I look forward to your reply. Thanks!

p.s 저는 한국 개발자입니다. 컨텍스트 공유를 위해 영어로 작성해봤어요. 수고에 진심으로 감사드립니다 :)

@ikhoon ikhoon added the defect label Aug 5, 2022
@ikhoon ikhoon added this to the 0.2.0 milestone Aug 5, 2022
@ikhoon
Copy link
Contributor

ikhoon commented Aug 5, 2022

I worried about stackeoverflow but, focused on keeping alive watcher for now.

Good point. It is possible. We can use a loop instead of recursion to avoid stack overflow.
For example:

def _schedule_watch(self, num_attempts_so_far: int) -> None:

    while num_attempts_so_far >= 0:
        if num_attempts_so_far == 0:
            delay = _DELAY_ON_SUCCESS_MILLIS if self._latest is None else 0
        else:
            delay = self._next_delay_millis(num_attempts_so_far)

        time.sleep(delay / 1000)
        num_attempts_so_far = self._watch(num_attempts_so_far)

def _watch(self, num_attempts_so_far: int) -> int:
    if self._is_stopped():
       return -1

    ...
    // return 0 to watch again
    // return num_attempts_so_far + 1 in case a error occur

Are you interested in fixing it as well?

@kkdeok
Copy link
Contributor Author

kkdeok commented Aug 7, 2022

I worried about stackeoverflow but, focused on keeping alive watcher for now.

Good point. It is possible. We can use a loop instead of recursion to avoid stack overflow. For example:

def _schedule_watch(self, num_attempts_so_far: int) -> None:

    while num_attempts_so_far >= 0:
        if num_attempts_so_far == 0:
            delay = _DELAY_ON_SUCCESS_MILLIS if self._latest is None else 0
        else:
            delay = self._next_delay_millis(num_attempts_so_far)

        time.sleep(delay / 1000)
        num_attempts_so_far = self._watch(num_attempts_so_far)

def _watch(self, num_attempts_so_far: int) -> int:
    if self._is_stopped():
       return -1

    ...
    // return 0 to watch again
    // return num_attempts_so_far + 1 in case a error occur

Are you interested in fixing it as well?

Sure! Thank you for your suggestion. I just updated the code based on your suggestion with some test code. Please take a look the commit

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @doubleknd26!
I'm looking forward to more feedback on centraldogma-python 😉

@codecov-commenter
Copy link

codecov-commenter commented Aug 8, 2022

Codecov Report

Merging #36 (05b645f) into main (1499b64) will increase coverage by 0.29%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   93.44%   93.74%   +0.29%     
==========================================
  Files          23       23              
  Lines         702      703       +1     
==========================================
+ Hits          656      659       +3     
+ Misses         46       44       -2     
Impacted Files Coverage Δ
centraldogma/dogma.py 100.00% <100.00%> (ø)
centraldogma/repository_watcher.py 94.11% <100.00%> (+0.78%) ⬆️
centraldogma/watcher.py 75.00% <0.00%> (ø)
centraldogma/data/entry.py 71.42% <0.00%> (ø)
centraldogma/exceptions.py 100.00% <0.00%> (ø)
centraldogma/data/revision.py 92.30% <0.00%> (ø)
centraldogma/query.py 96.29% <0.00%> (+3.70%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@kkdeok
Copy link
Contributor Author

kkdeok commented Aug 9, 2022

@hexoul @minwoox
I still cannot merge it and seems I need to get another approval. Anyone can help me to merge it? If you have any coments, please feel free to add :)

@ikhoon
Copy link
Contributor

ikhoon commented Aug 10, 2022

I still cannot merge

The permission to merge is granted to the maintainers of this project. It is normal that you can't merge this PR.
I'd like to wait for a review from our core maintainer @hexoul who may merge this PR after reviewing.

@minwoox
Copy link
Member

minwoox commented Aug 10, 2022

@syleeeee Do you mind adding CLA assistant bot to this repository? 😄

@kkdeok
Copy link
Contributor Author

kkdeok commented Aug 10, 2022

I still cannot merge

The permission to merge is granted to the maintainers of this project. It is normal that you can't merge this PR. I'd like to wait for a review from our core maintainer @hexoul who may merge this PR after reviewing.

Oh I see. Thanks for the detail :)

Copy link
Collaborator

@hexoul hexoul 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 your contribution. Please check comments.

tests/test_repository_watcher.py Outdated Show resolved Hide resolved
tests/test_repository_watcher.py Outdated Show resolved Hide resolved
tests/test_repository_watcher.py Outdated Show resolved Hide resolved


def create_watcher():
return RepositoryWatcher(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Changing AbstractWatcher._schedule_watch() affects not only RepositoryWatcher but also FileWatcher. It would be better to add tests at the same time. Furthermore, integration test seems proper to replay the case you reported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for FileWatcher.

I tried implements integration test for my case, but I faced that the dogma client returns either timeout exception or response 304 NOT_MODIFIED. Because the timeout exception is not related to the case I reported, I'm not sure the integration test can fully cover it. Nevertheless, I have thought about the integration test code like below. WDYT?

    def test_not_modified_repository_watcher(self, run_around_test):
        timeout_millis = 1000

        # we need to pass timeout_millis as a parameter.
        watcher: Watcher[Revision] = dogma.repository_watcher(
            project_name, repo_name, "/**", timeout_millis
        )

        # wait until watcher get NOT_MODIFIED at least one.
        time.sleep(5 * timeout_millis / 1000)

        commit = Commit("Upsert modify.txt")
        upsert_text = Change("/path/modify.txt", ChangeType.UPSERT_TEXT, "modified")
        result = dogma.push(project_name, repo_name, commit, [upsert_text])

        assert result.revision == watcher.latest.revision.major

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added tests for FileWatcher.

Looks good! Thanks for kind consideration. 🙏

I have thought about the integration test code like below. WDYT?

Makes sense for me. It would be better to check how many the number of calls of _watch() there is by scheduler, but okay. How about @ikhoon @minwoox ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Gentle ping @ikhoon @minwoox

@doubleknd26 By the way, the integration test you proposed is not included in changes. Could you add that?

Copy link
Contributor Author

@kkdeok kkdeok Aug 31, 2022

Choose a reason for hiding this comment

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

@hexoul Sure! I added it.

Copy link
Contributor

@ikhoon ikhoon Aug 31, 2022

Choose a reason for hiding this comment

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

The integration test code sounds good to me.
By the way, the code suggestion left above does not seem to be correctly applied.

    // return 0 to watch again
    // return num_attempts_so_far + 1 in case a error occur

centraldogma/repository_watcher.py Outdated Show resolved Hide resolved
centraldogma/repository_watcher.py Show resolved Hide resolved
centraldogma/repository_watcher.py Show resolved Hide resolved
@minwoox
Copy link
Member

minwoox commented Aug 17, 2022

@doubleknd26 Could you sign the CLA, please?
https://cla-assistant.io/line/centraldogma-python?pullRequest=36

@ikhoon ikhoon modified the milestones: 0.2.0, 0.3.0 Aug 17, 2022
@CLAassistant
Copy link

CLAassistant commented Aug 20, 2022

CLA assistant check
All committers have signed the CLA.

@kkdeok
Copy link
Contributor Author

kkdeok commented Aug 20, 2022

@doubleknd26 Could you sign the CLA, please? https://cla-assistant.io/line/centraldogma-python?pullRequest=36

Done. Thanks!

@hexoul
Copy link
Collaborator

hexoul commented Aug 22, 2022

Mostly LGTM 🎉 Please check broken tests.

@kkdeok
Copy link
Contributor Author

kkdeok commented Aug 29, 2022

Mostly LGTM 🎉 Please check broken tests.

Thanks for your comment! I fixed your point and confirmed it works in my forked repo. I hope it works well in here too.

centraldogma/repository_watcher.py Outdated Show resolved Hide resolved
centraldogma/repository_watcher.py Outdated Show resolved Hide resolved
result = dogma.push(project_name, repo_name, commit, [upsert_text])

# wait until watcher watch latest.
time.sleep(4 * timeout_second)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

tests/integration/test_watcher.py Outdated Show resolved Hide resolved
tests/integration/test_watcher.py Outdated Show resolved Hide resolved
centraldogma/repository_watcher.py Outdated Show resolved Hide resolved
Kideok and others added 3 commits September 1, 2022 16:34
Co-authored-by: Seunggon Kim <crosien@gmail.com>
Co-authored-by: Seunggon Kim <crosien@gmail.com>
Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks a lot! @doubleknd26 🚀❤️

@ikhoon
Copy link
Contributor

ikhoon commented Sep 1, 2022

Please check the lint failure which might be caused by applying suggestions in the comments.

Copy link
Collaborator

@hexoul hexoul left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@hexoul
Copy link
Collaborator

hexoul commented Sep 1, 2022

@syleeeee Could you check why CLA is pending?

@ikhoon
Copy link
Contributor

ikhoon commented Sep 2, 2022

Could you check why CLA is pending?

I didn't sign which blocks the CLA. 😱

@ikhoon
Copy link
Contributor

ikhoon commented Sep 2, 2022

@minwoox Would you like to review more?
It is a critical bug to use Watch API. I'll release a new version after merging this PR.

@ikhoon ikhoon merged commit b162f88 into line:main Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants