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

Health check on CLI on first start #256

Closed
wants to merge 2 commits into from

Conversation

gabrielbussolo
Copy link
Contributor

@gabrielbussolo gabrielbussolo commented Nov 30, 2022

Summary of this proposal

Depends on #300 to be aprovved

Screenshot 2022-12-02 at 10 36 38 AM

Notes for the reviewer

This runs on first execution of any CLI command.
We can also run it explicitly as calyptia config check.

Issue(s) number(s)

Disclaimer: Please do not create a Pull Request without creating an issue first.

Checklist for submitter

  • My PR has a related issue/bug number.
  • My PR provides tests
    • Integration tests are added/passes
    • Unit tests are added/passes
    • End-to-end tests added/passes
    • Static code check added/passes
    • Linting on documentation added/passes
    • Does not affect code coverage stats
  • My PR requires updating dependencies
  • My PR has the documentation changes required.

Checklist for reviewer

  • The proposal fixes a bug/issue or implements a new feature that is well described.
  • The proposal has sufficient test cases that covers the changes.
    • If changes an API, it does not break backwards compatibility (-1 major version).
  • If integration is required, the proposal has integration tests.
  • The proposal does not break coverage stats
  • The proposal has the required documentation changes.

Backport

  • Backport to the latest stable release.

@gabrielbussolo gabrielbussolo self-assigned this Nov 30, 2022
@gabrielbussolo gabrielbussolo linked an issue Nov 30, 2022 that may be closed by this pull request
2 tasks
@gabrielbussolo gabrielbussolo marked this pull request as draft November 30, 2022 14:39
@gabrielbussolo gabrielbussolo force-pushed the 229-cli-installation-check-report branch 3 times, most recently from bae5260 to 3d4acbe Compare February 2, 2023 08:34
@gabrielbussolo gabrielbussolo force-pushed the 229-cli-installation-check-report branch from 3d4acbe to cffac69 Compare February 2, 2023 15:13
@gabrielbussolo gabrielbussolo changed the title [wip] Health check on CLI on first start Health check on CLI on first start Feb 2, 2023
@gabrielbussolo gabrielbussolo marked this pull request as ready for review February 2, 2023 15:16
@gabrielbussolo gabrielbussolo added enhancement go Pull requests that update Go code cli labels Feb 2, 2023
@gabrielbussolo gabrielbussolo marked this pull request as draft February 2, 2023 15:17
@gabrielbussolo gabrielbussolo force-pushed the 229-cli-installation-check-report branch from cffac69 to d9ebf45 Compare February 21, 2023 11:52
@gabrielbussolo gabrielbussolo marked this pull request as ready for review February 21, 2023 11:53
cmd/calyptia/main.go Outdated Show resolved Hide resolved
Copy link
Contributor

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

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

Add option to remove colours and emojis as it causes issues sometimes

jasmingacic
jasmingacic previously approved these changes Mar 2, 2023
Copy link
Contributor

@jasmingacic jasmingacic left a comment

Choose a reason for hiding this comment

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

The code looks good. There is a single typo that Pat already pointed out

Otherwise, let's merge it.

Signed-off-by: Gabriel Bussolo <gabriel@calyptia.com>
@gabrielbussolo gabrielbussolo force-pushed the 229-cli-installation-check-report branch from 8cf7cbe to 7d8e47c Compare March 6, 2023 13:11
@gabrielbussolo
Copy link
Contributor Author

Add option to remove colours and emojis as it causes issues sometimes

the workaround to keep both was too big just for this pr, so I decided to just remove the emojis and colors.

Copy link
Contributor

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

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

Typo again
@vigneshcommits or @jasmingacic any good option for spell checking debug statements in Go?

cmd/config/config_check.go Outdated Show resolved Hide resolved
cmd/root.go Outdated Show resolved Hide resolved
@gabrielbussolo
Copy link
Contributor Author

gabrielbussolo commented Mar 6, 2023

Typo again @vigneshcommits or @jasmingacic any good option for spell checking debug statements in Go?
Screenshot 2023-03-06 at 17 03 06
in theory, I have it on my IDE, I just don't know why dint worked 😅

@jasmingacic
Copy link
Contributor

I've never used any of those tools

Copy link
Contributor

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

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

I'm reasonably happy with this, it needs follow on updates as we add more checks.
Plus @gabrielbussolo can you raise an issue to update the calyptia/core-images vm/install-core.sh script to invoke it as well?
@jasmingacic please approve if you're happy to he can merge

func checkUrl(c *cfg.Config) bool {
ctx := context.Background()
_, err := c.Cloud.Environments(ctx, c.ProjectID, types.EnvironmentsParams{})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This simple error check is not good enough. If the token is incorrect, or cloud is down for some reason, you will get the "internet connection issues" anyway. Which is not fair.

We should check if errors.Is(err, syscall.ECONNREFUSED) to detect if the URL is wrong.
And hit the /healthz endpoint to check if the server is up.

Copy link
Contributor Author

@gabrielbussolo gabrielbussolo Mar 13, 2023

Choose a reason for hiding this comment

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

Ensure the cloud API endpoint is reachable with the given token (this can be performed with any simple get/listing operation). (issue#229)

The idea is literally to test if we can do a GET with the given token, but I improved the message now including more causes of the connection not working.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gabrielbussolo after this URL check just do quick connect to it with the token just to check validity of the token. You can do that in checkToken() fn.

I don't think that checkUrl is acutally going to help us at all because chances are that by doing calyptia create core_instance k8s core will be installed in a remote cluster. What do you think?

@@ -75,6 +75,14 @@ func NewRootCmd(ctx context.Context) *cobra.Command {
Short: "Calyptia Cloud CLI",
SilenceErrors: true,
SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
if _, err = config.LocalData.Get(cnfg.KeyCliHealth); errors.Is(err, localdata.ErrNotFound) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we store the health indicator, this code won't run ever again. And health is something that changes over time, or if the user passes different arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to the original issue, the idea it's run once after a fresh install, after this, if the client wants to check the status he should run the proper command for it.

After brew install or installing the binary directly, a quick set of checks has to be performed
in the local machine to ensure further operations will work (issue#229)

Copy link
Contributor Author

@gabrielbussolo gabrielbussolo Mar 13, 2023

Choose a reason for hiding this comment

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

put it on the PreRun was a suggestion but can be moved to the main func again after the token and URL setup if you guys find it pertinent @jasmingacic @nicolasparada (i don't have a strong opinion about it)

Copy link
Contributor

Choose a reason for hiding this comment

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

PreRun was something else. This is rather preflight check.
So don't worry about it

Copy link
Contributor

@nicolasparada nicolasparada left a comment

Choose a reason for hiding this comment

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

Left some comments...

But I don't know what we are trying to accomplish here...

Having a global pre-run hook is an overkill, since it checks too many things. And have it to run only once, and then save that it's ok, and not run it ever again it's not good either 🤷‍♂️

Maybe reduce he scope and on the pre-run only check that that token is set, and /healthz. Checking kubernetes might be too much, besides not all commands of the CLI require k8s. Maybe you just want to get some info about your pipelines, this will block you if you don't have access to the cluster.

Signed-off-by: Gabriel Bussolo <gabriel@calyptia.com>
@gabrielbussolo gabrielbussolo force-pushed the 229-cli-installation-check-report branch from 475588f to 3112adb Compare March 13, 2023 10:43
@sonarcloud
Copy link

sonarcloud bot commented Mar 13, 2023

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 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@patrick-stephens
Copy link
Contributor

@gabrielbussolo I'm going to park this for now I'm afraid, good work so far but I think we need to reconsider.

@nicolasparada nicolasparada deleted the 229-cli-installation-check-report branch March 9, 2024 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: Installation check report.
5 participants