Skip to content

Conversation

@kevinmessiaen
Copy link
Member

Description

Await for backend to be ready before showing link

Type of Change

  • 📚 Examples / docs / tutorials / dependencies update
  • 🔧 Bug fix (non-breaking change which fixes an issue)
  • 🥂 Improvement (non-breaking change which improves an existing feature)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🔐 Security fix

@linear
Copy link

linear bot commented Jun 13, 2023

GSK-1291 Waiting for backend to start message

Only print in CLI that server is started when all components are ready

Copy link
Member

@henchaves henchaves left a comment

Choose a reason for hiding this comment

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

I didn't manage to properly test it. It's necessary to build a new Docker image

proxy_read_timeout 360000s;
}

location /management {
Copy link
Contributor

Choose a reason for hiding this comment

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

good job using the existing API 👍

return False


def _await_backend_ready(port: int):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: await has an asynchronous connotation in python (async/await). There's also an async sleep counterpart that'd be used for it: await asyncio.sleep()
In order to remove the confusion I'd rename it to just _wait_backend_ready

Suggested change
def _await_backend_ready(port: int):
def _wait_backend_ready(port: int):

if response.status_code != 200:
return False

return "UP" == response.json()['components']['readinessState']['status']
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm testing on dev setup, but my json structure isn't the same, I don't have components readinessState

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I got a different format, will use status instead to be sure.

image

return False

return "UP" == response.json()['components']['readinessState']['status']
except OSError:
Copy link
Contributor

Choose a reason for hiding this comment

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

requests can throw other errors (ConnectTimeout for example), I think we can simply catch BaseException and return False if it happens. (make sure to handle KeyboardInterrupt separately and reraise click.Abort())

In this case you can even replace

        if response.status_code != 200:
            return False

with

response.raise_for_status()

since it'll be caught by the same BaseException handler

return None


def _backend_ready(endpoint) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

_is_backend_ready is a bit cleaner IMO

backoff_time = 2
up = False

while not up:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a waiting limit. Let's say we wait for 3 minutes and if _backend_ready still returns False we break the loop and print an explanation like:

Giskard backend takes unusually long time to start, please check the logs with `giskard server logs backend`

Also I think it's worth adding a feedback while waiting, for example printing dots every backoff_time seconds, like this it's clear that the process isn't frozen, but is actually checking the status

click.echo(".", nl=False)

should do the trick, because print(end='') won't work in the loop without explicit stdout flushing

Copy link
Contributor

@andreybavt andreybavt left a comment

Choose a reason for hiding this comment

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

Last batch of comments and then it looks good to me

else:
logger.warning(
"Giskard backend takes unusually long time to start, please check the logs with `giskard server "
"logs backend"
Copy link
Contributor

@andreybavt andreybavt Jun 19, 2023

Choose a reason for hiding this comment

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

looks like a missing closing ` after "backend"

Suggested change
"logs backend"
"logs backend`"

Copy link
Contributor

Choose a reason for hiding this comment

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

or perhaps to make it even more readable you can break the long line before the giskard server logs backend command, for example after the first comma

else:
logger.warning(
"Giskard backend takes unusually long time to start, please check the logs with `giskard server "
"logs backend"
Copy link
Contributor

Choose a reason for hiding this comment

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

or perhaps to make it even more readable you can break the long line before the giskard server logs backend command, for example after the first comma

@kevinmessiaen kevinmessiaen requested a review from andreybavt June 20, 2023 03:35
@andreybavt andreybavt merged commit 5aff5a3 into main Jun 20, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@Hartorn Hartorn deleted the feature/gsk-1291-waiting-for-backend-to-start-message branch September 13, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants