grafana / pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
https://grafana.com/oss/pyroscope/
GNU Affero General Public License v3.0
10.13k stars 614 forks source link

Add API and command to fetch information of about a Raft node #3544

Closed bryanhuhta closed 2 months ago

bryanhuhta commented 2 months ago

closes https://github.com/grafana/pyroscope-squad/issues/230

Adds a CLI command (and corresponding API) to fetch info about a raft node. The command provides a variety of information regarding the node's role, log state, peers, election state, and leader. It has two output modes, the default mode is to provide the data in JSON format, which is a direct copy from what the underlying API returns. The other mode (-H) prints the information in a slightly more tabular, human-readable format.

usage: profilecli admin raft info [<flags>]

Print info about a Raft node.

Flags:
  -h, --help              Show context-sensitive help (also try --help-long and --help-man).
      --version           Show application version.
  -v, --verbose           Enable verbose logging.
      --url="http://localhost:4040"  
                          URL of the profile store.
      --tenant-id=""      The tenant ID to be used for the X-Scope-OrgID header.
      --username=""       The username to be used for basic auth.
      --password=""       The password to be used for basic auth.
      --protocol=connect  The protocol to be used for communicating with the server.
  -H, --human             Human readable output

Sample output:

{
  "id": "pyroscope-metastore-1.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099",
  "state": "Follower",
  "leaderId": "pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099",
  "lastLeaderContact": "1725564476270",
  "term": "40",
  "suffrage": "Voter",
  "log": {
    "commitIndex": "357591",
    "appliedIndex": "357591",
    "lastIndex": "357591",
    "fsmPendingLength": "0"
  },
  "snapshot": {
    "lastIndex": "0",
    "lastTerm": "36"
  },
  "protocol": {
    "version": "3",
    "minVersion": "0",
    "maxVersion": "0",
    "minSnapshotVersion": "1",
    "maxSnapshotVersion": "0"
  },
  "peers": [
    {
      "id": "pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099",
      "address": "pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099",
      "suffrage": "Voter"
    },
    {
      "id": "pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.",
      "address": "pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099",
      "suffrage": "Voter"
    }
  ]
}

Sample output with -H:

ID:                  pyroscope-metastore-1.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
State:               Follower
Leader ID:           pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Last leader contact: 2024-09-05T12:28:32-07:00
Term:                40
Suffrage:            Voter
Log:
  Commit index:       357613
  Applied index:      357613
  Last index:         357613
  FSM pending length: 0
Snapshot:
  Last index: 0
  Last term:  36
Protocol:
  Version:              3
  Min version:          0
  Max version:          0
  Min snapshot version: 1
  Max snapshot version: 0
Peers:
  ID:       pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
  Address:  pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
  Suffrage: Voter

  ID:       pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.
  Address:  pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
  Suffrage: Voter