-
Notifications
You must be signed in to change notification settings - Fork 493
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
Emit valid YAML for cachemgr:server_list #1735
base: master
Are you sure you want to change the base?
Conversation
Runtime test: master:
PR:
Delta: --- /tmp/before 2024-03-13 22:54:54
+++ /tmp/after 2024-03-13 22:54:53
@@ -3,14 +3,14 @@
Flags : default connection-auth=auto tls-disable
Address[0] : 127.0.0.1
Status : Down
-FETCHES : 0
-OPEN CONNS : 0
-AVG RTT : 0 msec
-LAST QUERY : 1710344842 seconds ago
+FETCHES : 0
+OPEN CONNS : 0
+AVG RTT : 0 msec
+LAST QUERY : none sent
LAST REPLY : none received
PINGS SENT : 0
PINGS ACKED: 0 0%
IGNORED : 0 0%
Histogram of PINGS ACKED:
-Last failed connect() at: 13/Mar/2024:15:47:16 +0000
+Last failed connect() at: 13/Mar/2024:15:54:31 +0000
keep-alive ratio: 0% |
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.
Thank you for posting sample output and the diff!
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Alex Rousskov <[email protected]>
Current sample output:
|
Current output format: cache_peers number: 2
cache_peers:
- name: localhost
type: sibling
http address: localhost:3129
options: default tls-disable
addresses: [ "[::1]" ]
status: Down
fetches: 0
open connections: 0
average RTT: 0 msec
pings sent: 0
pings acked: 0 0%
replies ignored: 0 0%
last failed connection at: 13/Apr/2024:18:01:11 +0700
keep-alive ratio: 0%
- name: localhost.localdomain
type: sibling
http address: localhost.localdomain:3130
options: default tls-disable
addresses: [ ]
status: Down
fetches: 0
open connections: 0
average RTT: 0 msec
pings sent: 0
pings acked: 0 0%
replies ignored: 0 0%
keep-alive ratio: 0% |
Possible thing to investigate: whether to have this action return |
FWIW, @rousskov vetoed the change to allow reports to have their own |
FWIW, I did not. |
That would be nice, but we cannot do that easily right now because this action (as a whole) does not return YAML in SMP Squids. To get to YAML, we need to fix1 how SMP Squids "bracket" from-kid output, replacing current
Bracketing changes do not belong to this PR. 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.
Great progress, thank you! This is an incomplete review that should still allow you to move forward. I will come back to this PR later.
src/neighbors.cc
Outdated
if (!peers) { | ||
storeAppendPrintf(sentry, "There are no neighbors installed.\n"); | ||
os << "There are no neighbors installed.\n"; | ||
return; | ||
} |
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 output format is now: ...
Looks good to me overall, thank you!
I would prefer "cache_peer directives:" to "cache_peers number:", but that is subjective, and I do not insist on that change.
If that does not break YAML, I would probably add an empty line between peers to improve readability, but that is rather subjective and I do not insist on that change.
|
||
#include "sbuf/SBuf.h" | ||
|
||
const SBuf spaces(size_t count); |
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.
FWIW, I will try to find the time to check whether this can become a constexpr (which may even improve some code in callers). If I succeed, I will fix the return type (extra/unwanted const
), the lack of documentation for this new global function, and NoNewGlobals implementation violation at that time.
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.
Based on our conversation, I'd hold off on this experiment; spaces (or its successor) will likely need to hold some state
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.
Sounds good. The current spaces() implementation is not something we can merge, but waiting for the decision regarding indentation/YAML formatting future is fine with me.
Current output: cache_peers number: 3
cache_peers:
- name: "localhost"
type: parent
HTTP address: localhost:3129
ICP address: localhost:3129
options: default tls-disable
addresses: [ "[::1]" ]
status: Down
fetches: 0
open connections: 0
average RTT: 0 msec
pings sent: 0
pings acked: 0 0%
replies ignored: 0 0%
last failed connection at: 17/Apr/2024:09:46:22 +0100
keep-alive ratio: 0%
- name: "127.0.0.1"
type: parent
HTTP address: 127.0.0.1:3130
ICP address: 127.0.0.1:3130
options: default tls-disable
addresses: [ "127.0.0.1" ]
status: Down
fetches: 0
open connections: 0
average RTT: 0 msec
pings sent: 0
pings acked: 0 0%
replies ignored: 0 0%
last failed connection at: 17/Apr/2024:09:46:22 +0100
keep-alive ratio: 0%
- name: "::1"
type: parent
HTTP address: ::1:3131
ICP address: ::1:3131
options: default tls-disable
addresses: [ "[::1]" ]
status: Down
fetches: 0
open connections: 0
average RTT: 0 msec
pings sent: 0
pings acked: 0 0%
replies ignored: 0 0%
last failed connection at: 17/Apr/2024:09:46:22 +0100
keep-alive ratio: 0% |
A simplistic (v1) solution is at In PR #1784 |
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.
Another incomplete review to help you make progress.
yaml << | ||
spaces(2) << "- name: \"" << name << "\"\n" << | ||
spaces(4) << "type: " << typeString() << '\n' << | ||
spaces(4) << "HTTP address: " << host << ':' << http_port << '\n'; |
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.
host
can be an IP address. I assume host
is bracketed when it is an IPv6 address (if not, that is another problem to fix in this or prerequisite PR because we print :port
after the host value).
We quote() IP addresses in the addresses
field below. I am guessing that we do that because :
and/or [
characters in an IPv6 address (if we are bracketing those addresses) must be quoted to remain YAML-compliant. Please adjust (this code and/or addresses printing code) to be consistent and YAML-compliant.
|
||
#if USE_CACHE_DIGESTS | ||
if (digest_url) | ||
os << " digest-url=" << digest_url; |
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.
Do we need to quote this URL to be YAML-compliant? If yes, I hope we can be both YAML- and squid.conf-compliant because this output is used for mgr:config reporting as well!
If you have a reference to YAML quoting rules, please share it.
@@ -20,7 +20,7 @@ enum fd_type { | |||
}; | |||
|
|||
typedef enum { | |||
PEER_NONE, | |||
PEER_NONE = 0, |
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.
C++ guarantees that, right? If yes, we do not want to start adjusting various enums to duplicate that guarantee, especially in a PR focusing on YAML conversion.
PEER_NONE = 0, | |
PEER_NONE, |
CachePeer::typeString() const | ||
{ | ||
static const char *typeNames[] { | ||
"non-peer", |
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 is a "non-peer" CachePeer? I do not think those things exist in current code. If this PR has reasons to change these strings, then let's do this instead:
"non-peer", | |
"unknown", |
P.S. I am also OK with replacing typeString() in various debugs() messages modified in this PR with cache_peer
to avoid questions of this "non-peer" or "unknown" string escaping into contexts where it does not "fit". The rationale for reporting the peer type in those contexts is rather weak AFAICT. I do not insist on such debugs() changes though.
Use PackableStream for CachePeer::reportStatistics and
update output format to well-formed YAML