Skip to content

Commit 31a5806

Browse files
authored
viz: Prohibit authority resource targets in stat commands (#13578)
There are plans to remove the authority label in inbound proxy metrics. When that happens we would not longer be able to use the viz stat/top commands to query by `authority`. This is a change to disable being able to invoke these commands with an `authority` resource target. Signed-off-by: Zahari Dichev <[email protected]>
1 parent a726757 commit 31a5806

File tree

14 files changed

+39
-421
lines changed

14 files changed

+39
-421
lines changed

pkg/k8s/k8s.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
// These constants are string representations of Kubernetes resource types.
1313
const (
1414
All = "all"
15-
Authority = "authority"
1615
ConfigMap = "configmap"
1716
CronJob = "cronjob"
1817
DaemonSet = "daemonset"
@@ -73,7 +72,6 @@ type resourceName struct {
7372

7473
// AllResources is a sorted list of all resources defined as constants above.
7574
var AllResources = []string{
76-
Authority,
7775
AuthorizationPolicy,
7876
CronJob,
7977
DaemonSet,
@@ -100,7 +98,6 @@ var StatAllResourceTypes = []string{
10098
ReplicationController,
10199
Pod,
102100
Service,
103-
Authority,
104101
CronJob,
105102
ReplicaSet,
106103
}
@@ -115,13 +112,11 @@ var CompletionResourceTypes = []string{
115112
ReplicationController,
116113
Pod,
117114
Service,
118-
Authority,
119115
CronJob,
120116
ReplicaSet,
121117
}
122118

123119
var resourceNames = []resourceName{
124-
{"au", "authority", "authorities"},
125120
{"cj", "cronjob", "cronjobs"},
126121
{"ds", "daemonset", "daemonsets"},
127122
{"deploy", "deployment", "deployments"},
@@ -190,8 +185,6 @@ func PluralResourceNameFromFriendlyName(friendlyName string) (string, error) {
190185
// Essentially the reverse of CanonicalResourceNameFromFriendlyName
191186
func ShortNameFromCanonicalResourceName(canonicalName string) string {
192187
switch canonicalName {
193-
case Authority:
194-
return "au"
195188
case CronJob:
196189
return "cj"
197190
case DaemonSet:

pkg/k8s/k8s_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ func TestCanonicalResourceNameFromFriendlyName(t *testing.T) {
3232
"pod": Pod,
3333
"deployment": Deployment,
3434
"deployments": Deployment,
35-
"au": Authority,
36-
"authorities": Authority,
3735
"cj": CronJob,
3836
"cronjob": CronJob,
3937
"serverauthz": ServerAuthorization,

test/integration/external/stat/stat_test.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"strconv"
87
"strings"
98
"testing"
109
"time"
@@ -37,7 +36,7 @@ func TestMain(m *testing.M) {
3736
// requesting, and the test will pass.
3837
func TestCliStatForLinkerdNamespace(t *testing.T) {
3938
ctx := context.Background()
40-
var prometheusPod, prometheusAuthority, prometheusNamespace, prometheusDeployment, metricsPod string
39+
var prometheusPod, prometheusNamespace, prometheusDeployment, metricsPod string
4140
// Get Metrics Pod
4241
pods, err := TestHelper.GetPodNamesForDeployment(ctx, TestHelper.GetVizNamespace(), "metrics-api")
4342
if err != nil {
@@ -62,13 +61,11 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
6261
testutil.Fatalf(t, "expected 1 pod for prometheus, got %d", len(pods))
6362
}
6463
prometheusPod = pods[0]
65-
prometheusAuthority = prometheusDeployment + "." + prometheusNamespace + ".svc.cluster.local:9090"
6664

6765
testCases := []struct {
6866
args []string
6967
expectedRows map[string]string
7068
status string
71-
isAuthority bool
7269
}{
7370
{
7471
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetLinkerdNamespace()},
@@ -103,35 +100,13 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
103100
"metrics-api": "1/1",
104101
},
105102
},
106-
{
107-
args: []string{"viz", "stat", "po", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("au/%s", prometheusAuthority), "--to-namespace", prometheusNamespace},
108-
expectedRows: map[string]string{
109-
metricsPod: "1/1",
110-
},
111-
status: "Running",
112-
},
113-
{
114-
args: []string{"viz", "stat", "au", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("po/%s", prometheusPod), "--to-namespace", prometheusNamespace},
115-
expectedRows: map[string]string{
116-
prometheusAuthority: "-",
117-
},
118-
isAuthority: true,
119-
},
120-
{
121-
args: []string{"viz", "stat", "au", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("po/%s", prometheusPod), "--to-namespace", prometheusNamespace},
122-
expectedRows: map[string]string{
123-
prometheusAuthority: "-",
124-
},
125-
isAuthority: true,
126-
},
127103
}
128104

129105
if !TestHelper.ExternalPrometheus() {
130106
testCases = append(testCases, []struct {
131107
args []string
132108
expectedRows map[string]string
133109
status string
134-
isAuthority bool
135110
}{
136111
{
137112
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetVizNamespace()},
@@ -162,7 +137,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
162137
args []string
163138
expectedRows map[string]string
164139
status string
165-
isAuthority bool
166140
}{
167141
{
168142
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetVizNamespace()},
@@ -212,7 +186,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
212186
args []string
213187
expectedRows map[string]string
214188
status string
215-
isAuthority bool
216189
}{
217190
{
218191
args: []string{"viz", "stat", "svc", "-n", prefixedNs},
@@ -244,9 +217,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
244217
}
245218

246219
expectedColumnCount := 8
247-
if tt.isAuthority {
248-
expectedColumnCount = 7
249-
}
250220
if tt.status != "" {
251221
expectedColumnCount++
252222
}
@@ -256,7 +226,7 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
256226
}
257227

258228
for name, meshed := range tt.expectedRows {
259-
if err := validateRowStats(name, meshed, tt.status, rowStats, tt.isAuthority); err != nil {
229+
if err := validateRowStats(name, meshed, tt.status, rowStats); err != nil {
260230
return err
261231
}
262232
}
@@ -271,7 +241,7 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
271241
})
272242
}
273243

274-
func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats map[string]*testutil.RowStat, isAuthority bool) error {
244+
func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats map[string]*testutil.RowStat) error {
275245
stat, ok := rowStats[name]
276246
if !ok {
277247
return fmt.Errorf("no stats found for [%s]", name)
@@ -313,12 +283,5 @@ func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats m
313283
name, stat.P99Latency)
314284
}
315285

316-
if stat.TCPOpenConnections != "-" && !isAuthority {
317-
_, err := strconv.Atoi(stat.TCPOpenConnections)
318-
if err != nil {
319-
return fmt.Errorf("error parsing number of TCP connections [%s]: %w", stat.TCPOpenConnections, err)
320-
}
321-
}
322-
323286
return nil
324287
}

test/integration/viz/stat/stat_test.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"os"
7-
"strconv"
87
"strings"
98
"testing"
109
"time"
@@ -37,7 +36,7 @@ func TestMain(m *testing.M) {
3736
// requesting, and the test will pass.
3837
func TestCliStatForLinkerdNamespace(t *testing.T) {
3938
ctx := context.Background()
40-
var prometheusPod, prometheusAuthority, prometheusNamespace, prometheusDeployment, metricsPod string
39+
var prometheusPod, prometheusNamespace, prometheusDeployment, metricsPod string
4140
// Get Metrics Pod
4241
pods, err := TestHelper.GetPodNamesForDeployment(ctx, TestHelper.GetVizNamespace(), "metrics-api")
4342
if err != nil {
@@ -62,13 +61,11 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
6261
testutil.Fatalf(t, "expected 1 pod for prometheus, got %d", len(pods))
6362
}
6463
prometheusPod = pods[0]
65-
prometheusAuthority = prometheusDeployment + "." + prometheusNamespace + ".svc.cluster.local:9090"
6664

6765
testCases := []struct {
6866
args []string
6967
expectedRows map[string]string
7068
status string
71-
isAuthority bool
7269
}{
7370
{
7471
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetLinkerdNamespace()},
@@ -103,35 +100,13 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
103100
"metrics-api": "1/1",
104101
},
105102
},
106-
{
107-
args: []string{"viz", "stat", "po", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("au/%s", prometheusAuthority), "--to-namespace", prometheusNamespace},
108-
expectedRows: map[string]string{
109-
metricsPod: "1/1",
110-
},
111-
status: "Running",
112-
},
113-
{
114-
args: []string{"viz", "stat", "au", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("po/%s", prometheusPod), "--to-namespace", prometheusNamespace},
115-
expectedRows: map[string]string{
116-
prometheusAuthority: "-",
117-
},
118-
isAuthority: true,
119-
},
120-
{
121-
args: []string{"viz", "stat", "au", "-n", TestHelper.GetVizNamespace(), "--to", fmt.Sprintf("po/%s", prometheusPod), "--to-namespace", prometheusNamespace},
122-
expectedRows: map[string]string{
123-
prometheusAuthority: "-",
124-
},
125-
isAuthority: true,
126-
},
127103
}
128104

129105
if !TestHelper.ExternalPrometheus() {
130106
testCases = append(testCases, []struct {
131107
args []string
132108
expectedRows map[string]string
133109
status string
134-
isAuthority bool
135110
}{
136111
{
137112
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetVizNamespace()},
@@ -162,7 +137,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
162137
args []string
163138
expectedRows map[string]string
164139
status string
165-
isAuthority bool
166140
}{
167141
{
168142
args: []string{"viz", "stat", "deploy", "-n", TestHelper.GetVizNamespace()},
@@ -212,7 +186,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
212186
args []string
213187
expectedRows map[string]string
214188
status string
215-
isAuthority bool
216189
}{
217190
{
218191
args: []string{"viz", "stat", "svc", "-n", prefixedNs},
@@ -244,9 +217,6 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
244217
}
245218

246219
expectedColumnCount := 8
247-
if tt.isAuthority {
248-
expectedColumnCount = 7
249-
}
250220
if tt.status != "" {
251221
expectedColumnCount++
252222
}
@@ -256,7 +226,7 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
256226
}
257227

258228
for name, meshed := range tt.expectedRows {
259-
if err := validateRowStats(name, meshed, tt.status, rowStats, tt.isAuthority); err != nil {
229+
if err := validateRowStats(name, meshed, tt.status, rowStats); err != nil {
260230
return err
261231
}
262232
}
@@ -271,7 +241,7 @@ func TestCliStatForLinkerdNamespace(t *testing.T) {
271241
})
272242
}
273243

274-
func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats map[string]*testutil.RowStat, isAuthority bool) error {
244+
func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats map[string]*testutil.RowStat) error {
275245
stat, ok := rowStats[name]
276246
if !ok {
277247
return fmt.Errorf("No stats found for [%s]", name)
@@ -313,12 +283,5 @@ func validateRowStats(name, expectedMeshCount, expectedStatus string, rowStats m
313283
name, stat.P99Latency)
314284
}
315285

316-
if stat.TCPOpenConnections != "-" && !isAuthority {
317-
_, err := strconv.Atoi(stat.TCPOpenConnections)
318-
if err != nil {
319-
return fmt.Errorf("Error parsing number of TCP connections [%s]: %w", stat.TCPOpenConnections, err)
320-
}
321-
}
322-
323286
return nil
324287
}

viz/cmd/edges_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestEdges(t *testing.T) {
6767
t.Run("Returns an error if request is for authority", func(t *testing.T) {
6868
options.outputFormat = tableOutput
6969
args := []string{"authority"}
70-
expectedError := "Resource type is not supported: authority"
70+
expectedError := "cannot find Kubernetes canonical name from friendly name [authority]"
7171

7272
_, err := buildEdgesRequests(args, options)
7373
if err == nil || err.Error() != expectedError {

viz/cmd/routes.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
pkgcmd "github.com/linkerd/linkerd2/pkg/cmd"
1616
"github.com/linkerd/linkerd2/pkg/healthcheck"
17-
"github.com/linkerd/linkerd2/pkg/k8s"
1817
pb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz"
1918
"github.com/linkerd/linkerd2/viz/metrics-api/util"
2019
"github.com/linkerd/linkerd2/viz/pkg/api"
@@ -379,7 +378,7 @@ func buildTopRoutesRequest(resource string, options *routesOptions) (*pb.TopRout
379378
LabelSelector: options.labelSelector,
380379
}
381380

382-
options.dstIsService = target.GetType() != k8s.Authority
381+
options.dstIsService = true
383382

384383
if options.toResource != "" {
385384
if options.toNamespace == "" {
@@ -390,7 +389,7 @@ func buildTopRoutesRequest(resource string, options *routesOptions) (*pb.TopRout
390389
return nil, err
391390
}
392391

393-
options.dstIsService = toRes.GetType() != k8s.Authority
392+
options.dstIsService = true
394393

395394
requestParams.ToName = toRes.Name
396395
requestParams.ToNamespace = toRes.Namespace

viz/cmd/stat.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func statHasRequestData(stat *pb.BasicStats) bool {
372372
}
373373

374374
func isPodOwnerResource(typ string) bool {
375-
return typ != k8s.Authority && typ != k8s.Service && typ != k8s.Server && typ != k8s.ServerAuthorization && typ != k8s.AuthorizationPolicy && typ != k8s.HTTPRoute
375+
return typ != k8s.Service && typ != k8s.Server && typ != k8s.ServerAuthorization && typ != k8s.AuthorizationPolicy && typ != k8s.HTTPRoute
376376
}
377377

378378
func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer, options *statOptions) {
@@ -433,7 +433,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
433433
statTables[resourceKey][key] = &row{}
434434
if resourceKey != k8s.Server && resourceKey != k8s.ServerAuthorization {
435435
meshedCount := fmt.Sprintf("%d/%d", r.MeshedPodCount, r.RunningPodCount)
436-
if resourceKey == k8s.Authority || resourceKey == k8s.Service {
436+
if resourceKey == k8s.Service {
437437
meshedCount = "-"
438438
}
439439
statTables[resourceKey][key] = &row{
@@ -503,7 +503,7 @@ func showTCPBytes(options *statOptions, resourceType string) bool {
503503
}
504504

505505
func showTCPConns(resourceType string) bool {
506-
return resourceType != k8s.Authority && resourceType != k8s.ServerAuthorization && resourceType != k8s.AuthorizationPolicy && resourceType != k8s.HTTPRoute
506+
return resourceType != k8s.ServerAuthorization && resourceType != k8s.AuthorizationPolicy && resourceType != k8s.HTTPRoute
507507
}
508508

509509
func printSingleStatTable(stats map[string]*row, resourceTypeLabel, resourceType string, w *tabwriter.Writer, maxNameLength, maxNamespaceLength, maxLeafLength, maxApexLength, maxDstLength, maxWeightLength int, options *statOptions) {

0 commit comments

Comments
 (0)