Skip to content

Lock cloud machines #24735

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

Merged
merged 68 commits into from
Mar 3, 2023
Merged

Lock cloud machines #24735

merged 68 commits into from
Mar 3, 2023

Conversation

moishce
Copy link
Contributor

@moishce moishce commented Feb 20, 2023

Status

  • In Progress
  • Ready
  • In Hold - (Reason for hold)

Related Issues

fixes: link to the issue

Description

Rewrite the “Lock XSIAM machines script” to Python according to this flowchart
Screen Shot 2023-02-23 at 9 56 33

Screenshots

Paste here any images that will help the reviewer

Minimum version of Cortex XSOAR

  • 6.0.0
  • 6.1.0
  • 6.2.0
  • 6.5.0

Does it break backward compatibility?

  • Yes
    • Further details:
  • No

Must have

  • Tests
  • Documentation

Copy link
Contributor

@ShahafBenYakir ShahafBenYakir left a comment

Choose a reason for hiding this comment

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

Very good work!

  1. Go over all functions and make sure the docstring is good (in some we are missing arguments documentation and in others, the function explanation is missing/poor)
  2. I believe that when there are several confusing arguments, it is a better practice to call a function using the named parameters. For example, do this: get_queue_locks_details(storage_client=storage_client, bucket_name='xsoar-ci-artifacts', prefix=f'{gcs_locks_path}/{QUEUE_REPO}/') instead of this: get_queue_locks_details(storage_client, 'xsoar-ci-artifacts', f'{gcs_locks_path}/{QUEUE_REPO}/'). Let's go over the code and functions and add the named parameters, where they add more clarity.
  3. Great work on adding intensive logging. I think we need to differentiate between info and debug logs such that info logs are for general operations so that the user can easily understand what's his stus, whereas debug logs are for more atomic operations which are usually less interesting unless I want to debug the process. For example, the following should be info logs:
    'Adding job_id to the queue'
    'Waiting for my turn in the queue'
    'My place in queue is 2'
    'My place in queue is 1'
    'starting to search for an empty machine'
    
    debug logs would be:
    'getting all builds in the queue'
    'There is a lock file for job id: 1234'
    'There is no a lock file for machine: bla bla'
    
  4. After adding the two functions I suggested in the main(), I want to add several use cases in the unit tests, (we can add mocking to the parts that were tested already by other unit tests if you think it is better)

@daryakoval
Copy link
Contributor

Are we have the option to lock more than one machine for the build?
In XSOAR we use more than one machine in the nightly, maybe we will want in the future to add the same functionality to XSOAR-NG.

@moishce
Copy link
Contributor Author

moishce commented Mar 1, 2023

@daryakoval Yes, the script has the option to lock several machines for a job.

@moishce moishce requested a review from ShahafBenYakir March 1, 2023 07:57
Copy link
Contributor

@ShahafBenYakir ShahafBenYakir left a comment

Choose a reason for hiding this comment

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

Great! How can we test?

@daryakoval daryakoval requested a review from tkatzir March 1, 2023 12:32
blobs = storage_client.list_blobs(bucket_name)
files = []
found = False
for blob in blobs:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you iterating for all these folders?
If yes why?

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not found another way that works in our Becket.
(there is an option to do it through an API call, which I will check)
In our case, our files are at the beginning of the list, so it doesn't actually go through the entire bucket (but it's obviously not the best way)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not putting both content-locks-xsiam and content-locks-xsoar-ng in content-locks?
also when we are done we need to delete the test folder.

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be easier to debug if we will have different folders.

Copy link
Contributor

@ShahafBenYakir ShahafBenYakir Mar 2, 2023

Choose a reason for hiding this comment

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

I didn't say NOT to have different folders, I said to put them both under content-locks. It should be separated from other artifacts (tests, content, etc...)

Copy link
Contributor

@ShahafBenYakir ShahafBenYakir left a comment

Choose a reason for hiding this comment

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

Great work, please address this
@daryakoval please review the fixes you requested and approve once you are ok.

Copy link
Contributor

@daryakoval daryakoval left a comment

Choose a reason for hiding this comment

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

Great!

@moishce moishce merged commit 6379f1b into master Mar 3, 2023
@moishce moishce deleted the Lock_cloud_machines branch March 3, 2023 10:56
israelpoli pushed a commit that referenced this pull request May 15, 2024
* added now python script

* test

* removed xsiam_server_ga for testing

* update wait_in_line script

* removed stop-running-pipelines for testing

* removed stop-running-pipelines for testing

* fixed GCS_LOCKS_PATH

* added loges

* added loges

* added loges

* testing

* testing

* testing

* added logs

* fixed check_job_status

* fixed get_machines_locks_details

* fixed get_machines_locks_details

* fixed get_machines_locks_details

* response by file

* response by file

* fixed get_machines_locks_details

* fixed get_machines_locks_details

* added comments

* added comments

* revert testing changes

* revert testing changes

* fixed flake8 errors

* fixed flake8 errors

* fixed typo

* added logs

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* changed GCS_LOCKS_PATH

* changed GCS_LOCKS_PATH

* added QUEUE_REPO, MACHINES_LOCKS_REPO

* fixed get_machines_locks_details

* fixed get_machines_locks_details

* fixed get_machines_locks_details

* reordered

* added unit test

* fixed flake8

* fixed coments

* fixed comments and added unittest

* fixed condition

* fixed unittest

* revert testing changes

* fixed shahaf/darya comments

* fixed unittest

* fixed file_path

* Comment out stop-running-pipelines for testing

* fixed file_path in remove a lock file

* added sleep before get_my_place_in_the_queue and revert testing changes

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

Successfully merging this pull request may close these issues.

4 participants