Skip to content

Commit

Permalink
cli: Enhance diagnostics endpoints json output (#11889)
Browse files Browse the repository at this point in the history
The 'endpoints' diagnostic command omits some interesting endpoint
metadata. This change adds weights and metric labels to JSON output.
  • Loading branch information
olix0r authored Jan 8, 2024
1 parent 9db42c5 commit 62dd6fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
9 changes: 9 additions & 0 deletions cli/cmd/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type (
name string
address string
ip string
weight uint32
labels map[string]string
}
)

Expand Down Expand Up @@ -200,6 +202,8 @@ func requestEndpointsFromAPI(client destinationPb.DestinationClient, authorities
name: labels["pod"],
address: tcpAddr.String(),
ip: getIP(tcpAddr),
weight: addr.GetWeight(),
labels: addr.GetMetricLabels(),
})
}
}
Expand Down Expand Up @@ -230,6 +234,9 @@ type rowEndpoint struct {
Port uint32 `json:"port"`
Pod string `json:"pod"`
Service string `json:"service"`
Weight uint32 `json:"weight"`

Labels map[string]string `json:"labels"`
}

func writeEndpointsToBuffer(endpoints endpointsInfo, w *tabwriter.Writer, options *endpointsOptions) {
Expand All @@ -255,6 +262,8 @@ func writeEndpointsToBuffer(endpoints endpointsInfo, w *tabwriter.Writer, option
Port: port,
Pod: name,
Service: serviceID,
Weight: pod.weight,
Labels: pod.labels,
}

endpointsTables[namespace] = append(endpointsTables[namespace], row)
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func TestEndpoints(t *testing.T) {
}

func testEndpointsCall(exp endpointsExp, t *testing.T) {
t.Helper()

updates := make([]pb.Update, 0)
for _, endpoint := range exp.endpoints {
addrSet := util.BuildAddrSet(endpoint)
Expand Down
12 changes: 10 additions & 2 deletions cli/cmd/testdata/endpoints_one_output_json.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions test/integration/deep/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ func createTestCaseTable(controlNs, endpointNs string) []testCase {
"namespace": "(\S*)",
"ip": "\d+\.\d+\.\d+\.\d+",
"port": 8086,
"pod": "linkerd\-destination\-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd\-dst\.\S*"
"pod": "linkerd-destination\-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd-dst\.\S*",
"weight": \d+,
"labels": \{(?s).*\}
\}
\]`,
ns: controlNs,
Expand All @@ -124,8 +126,10 @@ func createTestCaseTable(controlNs, endpointNs string) []testCase {
"namespace": "(\S*)",
"ip": "\d+\.\d+\.\d+\.\d+",
"port": 8080,
"pod": "linkerd\-identity\-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd\-identity\.\S*"
"pod": "linkerd-identity\-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd-identity\.\S*",
"weight": \d+,
"labels": \{(?s).*\}
\}
\]`,
ns: controlNs,
Expand All @@ -138,8 +142,10 @@ func createTestCaseTable(controlNs, endpointNs string) []testCase {
"namespace": "(\S*)",
"ip": "\d+\.\d+\.\d+\.\d+",
"port": 8443,
"pod": "linkerd\-proxy\-injector-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd\-proxy\-injector\.\S*"
"pod": "linkerd-proxy-injector-[a-f0-9]+\-[a-z0-9]+",
"service": "linkerd-proxy-injector\.\S*",
"weight": \d+,
"labels": \{(?s).*\}
\}
\]`,
ns: controlNs,
Expand All @@ -152,8 +158,10 @@ func createTestCaseTable(controlNs, endpointNs string) []testCase {
"namespace": "(\S*)",
"ip": "\d+\.\d+\.\d+\.\d+",
"port": 8080,
"pod": "nginx\-[a-f0-9]+\-[a-z0-9]+",
"service": "nginx\.\S*"
"pod": "nginx-[a-f0-9]+\-[a-z0-9]+",
"service": "nginx\.\S*",
"weight": \d+,
"labels": \{(?s).*\}
\}
\]`,
ns: endpointNs,
Expand Down

0 comments on commit 62dd6fb

Please sign in to comment.