-
Notifications
You must be signed in to change notification settings - Fork 202
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
Wait for Plausible active state #3153
Wait for Plausible active state #3153
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works great! Added one note, otherwise this is good to merge IMO 🙂
@@ -59,7 +59,7 @@ up *flags: | |||
|
|||
# Wait for all profile services to be up | |||
wait-up: up | |||
echo "🚧 TODO" | |||
just wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be fine to move the contents of the wait
recipe here and remove the @wait
recipe below entirely!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is implemented this way for consistency with the API justfile which has both @wait
and wait-up
. I can get behind this, as this can make working in a Dockerised context locally easier in the future.
frontend/justfile
Outdated
@health host="localhost:50288": | ||
-curl -s -o /dev/null -w '%{http_code}' 'http://{{ host }}/api/health' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the name of this to health-plausible
so that it is clear which service it is checking (specifically, that it isn't checking for the "frontend" service, which doesn't exist).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the changes look good to me, and you're going in the right direction. Thanks for the contribution @ngken0995! But I some suggestions.
frontend/justfile
Outdated
# parent directory and so must be prefixed with `api/`. | ||
just ../_loop \ | ||
'"$(just frontend/health {{ host }})" != "200"' \ | ||
"Waiting for the frontend to be healthy..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along the same lines as @sarayourfriend's feedback, this should be updated as follows.
"Waiting for the frontend to be healthy..." | |
"Waiting for Plausible to be healthy..." |
frontend/justfile
Outdated
# Wait for the service to be healthy | ||
@wait host="localhost:50288": | ||
# The just command on the second line is executed in the context of the | ||
# parent directory and so must be prefixed with `api/`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# parent directory and so must be prefixed with `api/`. | |
# parent directory and so must be prefixed with `frontend/`. |
@@ -59,7 +59,7 @@ up *flags: | |||
|
|||
# Wait for all profile services to be up | |||
wait-up: up | |||
echo "🚧 TODO" | |||
just wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is implemented this way for consistency with the API justfile which has both @wait
and wait-up
. I can get behind this, as this can make working in a Dockerised context locally easier in the future.
frontend/justfile
Outdated
# The just command on the second line is executed in the context of the | ||
# parent directory and so must be prefixed with `api/`. | ||
just ../_loop \ | ||
'"$(just frontend/health {{ host }})" != "200"' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also check that the response contains 3 "ok"
s.
{
"clickhouse": "ok",
"postgres": "ok",
"sites_cache": "ok"
}
I haven't seen what the status code and response is when Plausible is not healthy so there is a possibility that it returns some "not ok" but with a HTTP 200 response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhruvkb I found two ways to parse the JSON object. First option, we can use a jq
which is a JSON parsing and transformation tool for linux and determine if the response contains 3 "ok"
s. Second options, we can create python to parse through the JSON object and determine if the response contains 3 "ok"
s. Let me know if there is better solution. What is the best option to take?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to add a dependency on jq
. Using Python might be fine 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that not adding jq as a dependency is good. We've avoided it in other instances as well, opting instead for Python then too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need something as complex as Python or jq or even JSON parsing. Looking at the plausible code for the healthcheck endpoint, we can just as easily do this and it would catch the unhealthy cases:
curl -s 'http://localhost:50288/api/health' --fail | grep -vq 'error'
-vq
inverts the match and suppresses grep output (stops it from printing matched lines, in this case all the ok
that don't match error
, inverted) so we just get the exit code. --fail
in curl causes it to fail if the response code is 500, bypassing grep entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarayourfriend your solves only require curl and grep which I would prefer.
In the loop for wait
, require a condition to stop the loop. I'm not sure what is the output or return for curl -s 'http://localhost:50288/api/health' --fail | grep -vq 'error'
. I change the grep to have a invert match count of the word error. curl -s 'http://localhost:50288/api/health' --fail | grep -v -c 'error'
which will return 1 when error doesn't exist and return 0 when it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhruvkb Please take a look at the suggested resolution to use grep and invert matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not responding here. You'd need to use the exit code for my original suggestion, which you can get with $?
. Your approach looks more conventional though, I always have to look up what $?
is 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried 'http://localhost:50288/api/health' --fail | grep -vq 'error' | echo $?
and getting this error:
--rpc-eval : RPC failed with reason :nodedown
error: Recipe `init` failed on line 66 with exit code 1
Also, I'm not sure how I can pass a exit code into a command substitution.
It seems like the curl -s 'http://localhost:50288/api/health' --fail | grep -v -c 'error'
is working as expected. Let me know if there could be any edge case.
What are the other API status result from clickhouse
, postgres
and sites_cache
beside "ok" and "error"?
@dhruvkb and @AetherUnbound I created a python file to check the JSON object response for the three |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script is good, and using try
-except
is not bad practice! But we can use it more effectively by returning a non-zero exit code when the status is not "ok".
frontend/plausible_health_check.py
Outdated
@@ -0,0 +1,22 @@ | |||
import sys | |||
|
|||
import requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requests
isn't standard library and not everyone will have it installed in their global python installation (I don't, for example). urlopen
is a better choice here, but less convenient, if we stick with a python script instead of a shell-based approach.
+1 to Dhruv's comment that try/except is just fine here, totally appropriate usage.
Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR: @obulat Excluding weekend1 days, this PR was ready for review 5 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2. @ngken0995, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, verified that this works. Thanks for the contribution @ngken0995! Will merge it in once CI has passed.
@plausible-health host="localhost:50288": | ||
-curl -s 'http://localhost:50288/api/health' --fail | grep -v -c 'error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified that this returns 0 for unhealthy and 1 for healthy.
Fixes
Fixes #2489 by @sarayourfriend
Description
Implement
wait
in justfile.Wait
will have host as localhost:50288 because it points to plausible localhost. There is a loop going through to check the activity of plausible. We can check the health of plausible API(https://plausible.io/docs/stats-api#breakdown-custom-event-by-custom-props).Testing Instructions
just down -v
just frontend/up
just frontend/init
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin