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

refactor: start dashmate services depending on status #503

Merged
merged 33 commits into from
Jul 12, 2023

Conversation

pshenmic
Copy link
Collaborator

@pshenmic pshenmic commented May 16, 2023

Issue being fixed or feature implemented

Start or restart dashmate services depending on the dashmate status and dashmate update command.

#513

What was done?

  • Added smart start / restart of dashmate services depending on service statuses, image updates, package version or config changes
  • Fixed config idempotency (on template render)

How Has This Been Tested?

On devnet

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@pshenmic pshenmic marked this pull request as draft May 16, 2023 16:52
@pshenmic pshenmic requested review from shumkov and strophy May 18, 2023 05:40
@pshenmic pshenmic marked this pull request as ready for review May 18, 2023 05:41
Copy link
Collaborator

@strophy strophy left a comment

Choose a reason for hiding this comment

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

What are the possible values for service_status other than up and stopped? Will the value still be stopped if we are on the initial run, the dashmate start command has never run yet and the containers don't exist? Should we add a fallback in case the status command crashes, or should deploy tool just exit in that case?

ansible/roles/dashmate/tasks/main.yml Outdated Show resolved Hide resolved
@strophy strophy added this to the v0.24.x milestone May 18, 2023
@pshenmic pshenmic requested a review from strophy May 18, 2023 06:02
strophy
strophy previously approved these changes May 18, 2023
@pshenmic pshenmic marked this pull request as draft May 18, 2023 07:00
@pshenmic pshenmic marked this pull request as ready for review May 18, 2023 07:00
ansible/roles/dashmate/tasks/main.yml Outdated Show resolved Hide resolved
@shumkov shumkov changed the title fix: start dashmate services depending on status refactor: start dashmate services depending on status May 18, 2023
@pshenmic pshenmic requested a review from shumkov May 18, 2023 08:21
(core_service_status != 'up' and core_service_status != 'stopped') or
(tenderdash_service_status != 'up' and tenderdash_service_status != 'stopped')

# start platform when (core is up and platform is down)
Copy link
Member

@shumkov shumkov May 18, 2023

Choose a reason for hiding this comment

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

Don't we need to restart Core as well? What if dashmate code is updated or config is changed?

We can do restart logic smarter:

  1. Images are changes: restart core if core image changed and restart platform if platform images are changed
  2. dashmate config is changed
  3. dashmate is changed

@pshenmic @strophy What do you think guys?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, yesterday I had difficulty updating from Platform 0.24.2 to 0.24.4 because docker compose restart does not pull and use newer images, docker compose up -d is necessary for this. We definitely need a way of ensuring the necessary containers are restarted (or stopped, updated and started) when config changes. But changing the dashmate version probably shouldn't cause core to restart - this usually changes at the same time as the platform version only.

Copy link
Member

@shumkov shumkov May 19, 2023

Choose a reason for hiding this comment

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

docker compose restart does not pull and use newer images

it's not, that's why we have dashmate update above

But changing the dashmate version probably shouldn't cause core to restart

We should because docker compose config could be changed.

Copy link
Member

@shumkov shumkov May 19, 2023

Choose a reason for hiding this comment

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

What do you think about this logic:

  • check services status
    • core is running
    • drive is running
  • start ALL when (core is down and platform is down)
  • start platform when (core is up and platform is down)
  • determine what's need to be restarted:
    • any of platform images are updated: platform
    • core / sentinel images are updated: all
    • dashmate is changed: all
    • dashmate config is changed: all
  • restart platform (platform is not down and platform needs to be restarted)
  • restart all (all needs to be restarted)

- name: Get service status
ansible.builtin.set_fact:
core_service_status: "{{ dashmate_status.stdout | from_json | json_query('core.serviceStatus') }}"
tenderdash_service_status: "{{ dashmate_status.stdout | from_json | json_query('platform.tenderdash.serviceStatus') }}"
Copy link
Member

Choose a reason for hiding this comment

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

It seems we need to get all platform service statuses otherwise it will be inconsistency and conflict with the check in dashmate https://github.com/dashpay/platform/blob/2e984df0302fa94bdf187bd893328ec58f390aa0/packages/dashmate/src/docker/DockerCompose.js#L75

We using this function in start and restart commands I believe

@pshenmic pshenmic requested review from shumkov and strophy July 5, 2023 08:33
@strophy
Copy link
Collaborator

strophy commented Jul 6, 2023

This looks really good, lots of useful changes here. Does it currently depend on a minimum version of dashmate for the restart platform commands to work properly? Or do we need to do a release still?

@pshenmic
Copy link
Collaborator Author

pshenmic commented Jul 6, 2023

No, required things are already included in the last release (v0.24.14).

We still could have some idempotency defects in rare cases, but they will be resolved once this dashpay/platform#1181 is done.

ansible/roles/dashmate/tasks/install.yml Show resolved Hide resolved
ansible/roles/dashmate/tasks/main.yml Outdated Show resolved Hide resolved

- name: Get service status
ansible.builtin.set_fact:
core_docker_status: "{{ dashmate_status.stdout | from_json | json_query('core.dockerStatus') }}"
Copy link
Member

Choose a reason for hiding this comment

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

What if tenderdash is stopped it Drive or DAPI is started?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean? Should I rather check by drive container?

Copy link
Member

@shumkov shumkov Jul 7, 2023

Choose a reason for hiding this comment

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

Check if one of them started?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm worried that it will add more fragility to the code. We actually don't have them stopped separately from each other. Tenderdash container will be either in not_started state or running. If there are any issues happening, it will remain in restarting, exited, or any other states, and tasks will be skipped

Copy link
Member

Choose a reason for hiding this comment

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

What will happen if tenderdash is stopped but any of platform services is running? DAPI for example?

ansible/roles/dashmate/tasks/main.yml Outdated Show resolved Hide resolved
ansible/roles/dashmate/tasks/main.yml Outdated Show resolved Hide resolved
@@ -1,5 +1,5 @@
{
"configFormatVersion": "{{ dashmate_version | default('999.0.0') }}",
"configFormatVersion": "{{ dashmate_version | default(dashmate_config_version | default('999.0.0')) }}",
Copy link
Member

Choose a reason for hiding this comment

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

Why do you we want to configure this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because when we install from branch, we don't have dashmate_version available and it will back off to 999.0.0 which will break template idempotency. On the first dashmate run, config version will be overwritten with the package default version.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Yes you right. Would it be better to get dashmate version form dashmate itself (dashmate --version or package.json) so you won't need to configure it manually. 999.0.0 workaround won't be necessary as well.

@pshenmic pshenmic requested a review from shumkov July 7, 2023 14:32

- name: Get service status
ansible.builtin.set_fact:
core_docker_status: "{{ dashmate_status.stdout | from_json | json_query('core.dockerStatus') }}"
Copy link
Member

Choose a reason for hiding this comment

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

What will happen if tenderdash is stopped but any of platform services is running? DAPI for example?

@pshenmic
Copy link
Collaborator Author

pshenmic commented Jul 7, 2023

What will happen if tenderdash is stopped but any of platform services is running? DAPI for example?

It will try to start platform services

@pshenmic pshenmic requested review from strophy and shumkov July 10, 2023 14:03
@shumkov shumkov merged commit edc035c into master Jul 12, 2023
@strophy strophy deleted the fix/dashmate-status branch August 9, 2023 08:21
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

Successfully merging this pull request may close these issues.

3 participants