-
Notifications
You must be signed in to change notification settings - Fork 36
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
Capture instance name #116
Conversation
@hermunn , I could use your opinion on this. My knee-jerk reaction would be to run |
I think @gquintard has a good point. I think maybe a combination of the ideas would be the following:
In short, I think that the idea of figuring out the right |
@zackmay, bump |
…comment in github
I believe I addressed the concerns. I've tested it on my test box, I am not sure on one piece. Which is. If someone provide the incorrect name, should we allow that which would result in the incorrect name represented in the file output. I went ahead and fixed that to use the valid name, I think that is best. Can you guy please check my work? |
varnishgather
Outdated
@@ -393,6 +401,10 @@ _EOF_ | |||
exit $1 | |||
} | |||
|
|||
suggest_n_values() { |
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 looks like an unnecessary level of indirection? If you want to use get_varnishd_instances
, just use get_varnishd_instances
varnishgather
Outdated
@@ -428,6 +440,46 @@ done | |||
|
|||
shift $((OPTIND - 1)) | |||
|
|||
if [ -z "$NAME" ]; then | |||
VARNISHD_CMD=$(ps -o cmd= -p $(pgrep varnishd)) |
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 would generate multiple values when multiple varnishd
processes are running, wouldn't it?
also, you wrote get_varnishd_instances
, it feels like a shame to not use it?
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 changed this entire block to tighten up sloppy work on my part.
varnishgather
Outdated
fi | ||
fi | ||
|
||
if [ -n "$NAME" ] && [ -z "$RELDIR" ]; then |
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 block feels overkill for me, I have the impression that you just need to do
RELDIR="$RELDIR-$NEWLYFIGUREDOUTNAME"
ID="$ID-$NEWLYFIGUREDOUTNAME"
if NAME
wasn't specified
if
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 moved this into the block if block 439-452 after thinking about it I just reused INSTANCE_NAME set from get_varnishd_instance
varnishgather
Outdated
if [ -n "$INSTANCE_NAME" ]; then | ||
NAME="-n $INSTANCE_NAME" | ||
else | ||
INSTANCE_NAME=$(suggest_n_values) |
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.
why not start with that?
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.
Covered in the previous two updates I hope.
sorry I'm old, and old dogs + new tricks. :) Co-authored-by: guillaume quintard <[email protected]>
varnishgather
Outdated
if [ -n "$NAME" ] && ! validate_instance; then | ||
INSTANCE_NAME=$(get_varnishd_instance) | ||
[ -n "$INSTANCE_NAME" ] && NAME="-n $INSTANCE_NAME" || NAME="" | ||
fi |
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.
Pål wrote:
If there is a -n argument, but varnishadm ping -n does not work, report that and suggest other -n values that might be better, but run the rest of the script.
I don't think this code is doing that
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.
you are right, I did not go back to your original comments I focused on fixing my laziness before updating. I'll work make sure to add a varnishadm ping check in here, my bad
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.
after re-reading your original statement. I completely skipped over what you wanted. I focused on just ensuring the name was included in the script execution with or without the client adding it, or even if they add the wrong name it picks the proper name. A new day and a revisit to your comment Pal has me feeling you would rather have the following.
- script executed, check provided -n value (if correct it goes on about it's marry way)
- script executed, no -n provided but there is a name, so we spit out to the client they should rerun the script with -n $propername (exit script)
3.. script executed with -n and wrong name, return the potential proper names we gather and present that to the client with the NAME's we found with echo statements to run the script properly but then exit script.
I went about this task thinking I should just do the -n work for them. There is a potential for compromise here. I could go do the -n capture and then also, print out to the client that we had to do this because they failed to provide the information. Even warning we chose the first -n process we found, therefore if they meant X/Y/Z then they should re-run the script with the proper name?
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.
to be completely exhaustive, I think this is the proper logic:
-n
givenvarnishadm ping
works- proceed as usual
varnishadm ping
doesn't work- warn that the name may be wrong, print out a list of candidates if any, then proceed
- no
-n
varnishadm ping
works- proceed as usual
- if there's exactly one candidate
- warn that we defaulted to that auto-selected name, proceed if
varnishadm ping
works, error out otherwise
- warn that we defaulted to that auto-selected name, proceed if
- there is 0 candidate
- warn that
varnishd
may not be running
- warn that
- there are more than 1 candidate
- list the candidates, error out
varnishgather
Outdated
[ -n "$INSTANCE_NAME" ] && NAME="-n $INSTANCE_NAME" || NAME="" | ||
fi | ||
|
||
ID="$(cat /etc/hostname)-$(date +'%Y%m%d-%H%M%S')${INSTANCE_NAME:+-$(n_opt "$INSTANCE_NAME")}" |
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.
isn't that just?
ID="$(cat /etc/hostname)-$(date +'%Y%m%d-%H%M%S')$(n_opt "$INSTANCE_NAME")"
since n_opt
will be a noop if INSTANCE_NAME
is empty?
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 reason I have it the way it is. When using just ID="$(cat /etc/hostname)-$(date +'%Y%m%d-%H%M%S')$(n_opt "$INSTANCE_NAME")"
the results from a named instance output look like below.
Please submit the file: varnishgather.varnish-wrk-20241101-184253varnish1.tar.gz
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.
what I'm saying is that $(n_opt "$INSTANCE_NAME")"
is a shorter equivalent to ${INSTANCE_NAME:+-$(n_opt "$INSTANCE_NAME")}"
I've pushed the latest adoption to the script to address your concerns.
Tests I ran
To note, there was no varnishping processing in the original script, which is why I proceeded in this direction of capturing the unnamed instance as primary if -n was not provided. If -n, new logic is processed. I hope that addresses your concerns. I also commented above on your n_opt usage. |
if [ -n "$NAME" ]; then | ||
INSTANCE_NAME="${NAME#-n }" | ||
|
||
if ! echo "$INSTANCE_NAMES" | grep -qx "$INSTANCE_NAME"; then |
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 is sketchy because an unnamed instance can still be pinged using -n
, and you can use an absolute -n
to ping a relatively named instance. As long as the workdir can be fine it work.
However, I don't foresee users doing twisted things like that, this is fine
One Karnaugh map later and I realized that #116 (comment) could have been expressed more simply. If `varnishadm ping` is successful with the current NAME argument, no question asked, go for it: ``` Info: Working directory: /tmp/varnishgather.Z1LTcYva/varnishgather-flamp-20241106-214646 Info: Complete varnishadm command line deduced to: Task: 1: varnishd -V ... ``` If pinging failed, there are a few cases: If NAME was given, or if NAME wasn't given but there's no varnishd detected, issue a warning, pause a bit, then proceed: ``` Info: Working directory: /tmp/varnishgather.BBE414gf/varnishgather-flamp-20241106-221201 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? Info: Complete varnishadm command line deduced to: <PAUSE 10s> Task: 1: varnishd -V ... ``` if no NAME was given but there's exactly one candidate, and it's pingable, override NAME, warn about it, pause then proceed: ``` Info: Working directory: /tmp/varnishgather.ZeUDcfg7/varnishgather-flamp-20241106-222151 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? There's only one varnishd running and it's pingable. Overriding -n argument to /tmp/beepboop <PAUSE 10s> Info: Complete varnishadm command line deduced to: -n /tmp/beepboop Task: 1: varnishd -V ... ``` Finally, if there are no given NAME, and we have more than one candidate, we just propose a list of candidates and error out: ``` Info: Working directory: /tmp/varnishgather.dkGgfqHe/varnishgather-flamp-20241106-223210 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? We've also detected one or more varnishd that could possibly be pinged with these -n arguments: -n /tmp/beepboop -n /tmp/beepboop2 <EXIT> ```
One Karnaugh map later and I realized that #116 (comment) could have been expressed more simply. If `varnishadm ping` is successful with the current NAME argument, no question asked, go for it: ``` Info: Working directory: /tmp/varnishgather.Z1LTcYva/varnishgather-flamp-20241106-214646 Info: Complete varnishadm command line deduced to: Task: 1: varnishd -V ... ``` If pinging failed, there are a few cases: If NAME was given, or if NAME wasn't given but there's no varnishd detected, issue a warning, pause a bit, then proceed: ``` Info: Working directory: /tmp/varnishgather.BBE414gf/varnishgather-flamp-20241106-221201 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? Info: Complete varnishadm command line deduced to: <PAUSE 10s> Task: 1: varnishd -V ... ``` if no NAME was given but there's exactly one candidate, and it's pingable, override NAME, warn about it, pause then proceed: ``` Info: Working directory: /tmp/varnishgather.ZeUDcfg7/varnishgather-flamp-20241106-222151 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? There's only one varnishd running and it's pingable. Overriding -n argument to /tmp/beepboop <PAUSE 10s> Info: Complete varnishadm command line deduced to: -n /tmp/beepboop Task: 1: varnishd -V ... ``` If no NAME is given, and there's only one candidate but it's not pingable, just error out: ``` Info: Working directory: /tmp/varnishgather.eZSa78VU/varnishgather-flamp-20241106-224856 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? <EXIT> ``` Finally, if there are no given NAME, and we have more than one candidate, we just propose a list of candidates and error out: ``` Info: Working directory: /tmp/varnishgather.dkGgfqHe/varnishgather-flamp-20241106-223210 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? We've also detected one or more varnishd that could possibly be pinged with these -n arguments: -n /tmp/beepboop -n /tmp/beepboop2 <EXIT> ```
One Karnaugh map later and I realized that #116 (comment) could have been expressed more simply. If `varnishadm ping` is successful with the current NAME argument, no question asked, go for it: ``` Info: Working directory: /tmp/varnishgather.Z1LTcYva/varnishgather-flamp-20241106-214646 Info: Complete varnishadm command line deduced to: Task: 1: varnishd -V ... ``` If pinging failed, there are a few cases: If NAME was given, or if NAME wasn't given but there's no varnishd detected, issue a warning, pause a bit, then proceed: ``` Info: Working directory: /tmp/varnishgather.BBE414gf/varnishgather-flamp-20241106-221201 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? Info: Complete varnishadm command line deduced to: <PAUSE 10s> Task: 1: varnishd -V ... ``` if no NAME was given but there's exactly one candidate, and it's pingable, override NAME, warn about it, pause then proceed: ``` Info: Working directory: /tmp/varnishgather.ZeUDcfg7/varnishgather-flamp-20241106-222151 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? There's only one varnishd running and it's pingable. Overriding -n argument to /tmp/beepboop <PAUSE 10s> Info: Complete varnishadm command line deduced to: -n /tmp/beepboop Task: 1: varnishd -V ... ``` If no NAME is given, and there's only one candidate but it's not pingable, just error out: ``` Info: Working directory: /tmp/varnishgather.eZSa78VU/varnishgather-flamp-20241106-224856 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? <EXIT> ``` Finally, if there are no given NAME, and we have more than one candidate, we just propose a list of candidates and error out: ``` Info: Working directory: /tmp/varnishgather.dkGgfqHe/varnishgather-flamp-20241106-223210 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? We've also detected one or more varnishd that could possibly be pinged with these -n arguments: -n /tmp/beepboop -n /tmp/beepboop2 <EXIT> ```
One Karnaugh map later and I realized that #116 (comment) could have been expressed more simply. If `varnishadm ping` is successful with the current NAME argument, no question asked, go for it: ``` Info: Working directory: /tmp/varnishgather.Z1LTcYva/varnishgather-flamp-20241106-214646 Info: Complete varnishadm command line deduced to: Task: 1: varnishd -V ... ``` If pinging failed, there are a few cases: If NAME was given, or if NAME wasn't given but there's no varnishd detected, issue a warning, pause a bit, then proceed: ``` Info: Working directory: /tmp/varnishgather.BBE414gf/varnishgather-flamp-20241106-221201 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? Info: Complete varnishadm command line deduced to: <PAUSE 10s> Task: 1: varnishd -V ... ``` if no NAME was given but there's exactly one candidate, and it's pingable, override NAME, warn about it, pause then proceed: ``` Info: Working directory: /tmp/varnishgather.ZeUDcfg7/varnishgather-flamp-20241106-222151 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? There's only one varnishd running and it's pingable. Overriding -n argument to /tmp/beepboop <PAUSE 10s> Info: Complete varnishadm command line deduced to: -n /tmp/beepboop Task: 1: varnishd -V ... ``` If no NAME is given, and there's only one candidate but it's not pingable, just error out: ``` Info: Working directory: /tmp/varnishgather.eZSa78VU/varnishgather-flamp-20241106-224856 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? <EXIT> ``` Finally, if there are no given NAME, and we have more than one candidate, we just propose a list of candidates and error out: ``` Info: Working directory: /tmp/varnishgather.dkGgfqHe/varnishgather-flamp-20241106-223210 using: varnishadm ping, We couldn't ping varnishd, Is it running and is ./varnishgather running with the right permissions? We've also detected one or more varnishd that could possibly be pinged with these -n arguments: -n /tmp/beepboop -n /tmp/beepboop2 <EXIT> ```
added a safety net if folks forget to add varnish instance name.