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

Emit valid YAML for cachemgr:server_list #1735

Open
wants to merge 101 commits into
base: master
Choose a base branch
from

Conversation

kinkie
Copy link
Contributor

@kinkie kinkie commented Mar 13, 2024

Use PackableStream for CachePeer::reportStatistics and
update output format to well-formed YAML

@kinkie
Copy link
Contributor Author

kinkie commented Mar 13, 2024

Runtime test:

master:

Sibling    : localhost
Host       : localhost/13128/0
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
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
keep-alive ratio: 0%

PR:

Sibling    : localhost
Host       : localhost/13128/0
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 : 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:54:31 +0000
keep-alive ratio: 0%

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%

yadij

This comment was marked as resolved.

Copy link
Contributor

@rousskov rousskov left a 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!

src/neighbors.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated Show resolved Hide resolved
@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Mar 13, 2024
rousskov

This comment was marked as outdated.

@kinkie

This comment was marked as resolved.

@kinkie
Copy link
Contributor Author

kinkie commented Mar 15, 2024

Current sample output:

Name       : 127.0.0.1
Type       : Sibling
Addresses  : 1
Host       : 127.0.0.1/13129/0
Flags      : default connection-auth=auto tls-disable
Address[0] : 127.0.0.1
Status     : Down
Fetches    : 0
Open conns : 0
Avg rtt    : 0 msec
Pings sent : 0
Pings acked: 0 0%
Ignored    : 0 0%
Histogram of pings acked:
Last failed connect() at: 15/Mar/2024:05:27:58 +0000
keep-alive ratio: 0%

@kinkie kinkie requested review from rousskov and yadij March 15, 2024 05:34
@kinkie kinkie added S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box and removed S-waiting-for-author author action is expected (and usually required) labels Mar 15, 2024
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
@kinkie kinkie removed S-waiting-for-author author action is expected (and usually required) S-waiting-for-PR Closure of other PR(s), current or future, is expected (and usually required) labels Apr 13, 2024
@kinkie
Copy link
Contributor Author

kinkie commented Apr 13, 2024

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%

@kinkie kinkie requested review from yadij and rousskov April 13, 2024 11:07
@kinkie
Copy link
Contributor Author

kinkie commented Apr 13, 2024

Possible thing to investigate: whether to have this action return application/yaml content type

@yadij
Copy link
Contributor

yadij commented Apr 13, 2024

FWIW, @rousskov vetoed the change to allow reports to have their own Content-Type.

@rousskov
Copy link
Contributor

FWIW, @rousskov vetoed the change to allow reports to have their own Content-Type.

FWIW, I did not.

@rousskov
Copy link
Contributor

Possible thing to investigate: whether to have this action return application/yaml content type

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 by kidN { ... } by kidN "brackets" with some YAML-compatible variation. Here is one option that limits bracketing modifications and mostly preserves their current advantages, but there may be better options:

by kid1: {
...
} # by kid1

by kid2: {
...
} # by kid2

Bracketing changes do not belong to this PR.

Footnotes

  1. More fixes may be necessary because each kid-specific blob may need to be adjusted as well to keep aggregated output valid; I have not investigated what exact changes, if any, are needed there. Ideally, we should check/decide before this PR goes in so that we do not have to modify non-SMP output twice. However, I cannot insist on that precondition.

Copy link
Contributor

@rousskov rousskov left a 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/CachePeer.cc Outdated Show resolved Hide resolved
src/neighbors.cc Outdated
Comment on lines 1359 to 1362
if (!peers) {
storeAppendPrintf(sentry, "There are no neighbors installed.\n");
os << "There are no neighbors installed.\n";
return;
}
Copy link
Contributor

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.

src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved
src/CachePeer.cc Outdated Show resolved Hide resolved

#include "sbuf/SBuf.h"

const SBuf spaces(size_t count);
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Apr 13, 2024
@kinkie kinkie mentioned this pull request Apr 14, 2024
@kinkie
Copy link
Contributor Author

kinkie commented Apr 17, 2024

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%

@kinkie
Copy link
Contributor Author

kinkie commented Apr 17, 2024

Possible thing to investigate: whether to have this action return application/yaml content type

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 by kidN { ... } by kidN "brackets" with some YAML-compatible variation. Here is one option that limits bracketing modifications and mostly preserves their current advantages, but there may be better options:

by kid1: {
...
} # by kid1

by kid2: {
...
} # by kid2

Bracketing changes do not belong to this PR.

Footnotes

  1. More fixes may be necessary because each kid-specific blob may need to be adjusted as well to keep aggregated output valid; I have not investigated what exact changes, if any, are needed there. Ideally, we should check/decide before this PR goes in so that we do not have to modify non-SMP output twice. However, I cannot insist on that precondition.

A simplistic (v1) solution is at In PR #1784

@kinkie kinkie requested a review from rousskov April 17, 2024 09:02
@kinkie kinkie removed the S-waiting-for-author author action is expected (and usually required) label Apr 17, 2024
@rousskov rousskov added the S-waiting-for-PR Closure of other PR(s), current or future, is expected (and usually required) label Apr 18, 2024
Copy link
Contributor

@rousskov rousskov left a 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';
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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.

Suggested change
PEER_NONE = 0,
PEER_NONE,

CachePeer::typeString() const
{
static const char *typeNames[] {
"non-peer",
Copy link
Contributor

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:

Suggested change
"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.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Apr 30, 2024
@kinkie kinkie added the M-ignored-by-merge-bots https://github.com/measurement-factory/anubis/blob/master/README.md#pull-request-labels label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-ignored-by-merge-bots https://github.com/measurement-factory/anubis/blob/master/README.md#pull-request-labels S-waiting-for-author author action is expected (and usually required) S-waiting-for-PR Closure of other PR(s), current or future, is expected (and usually required) S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box
Projects
None yet
6 participants