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

cli: Enhance diagnostics endpoints json output #11889

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading