From c322ff5f5dca404c9d99eed92eaddc6142389ed2 Mon Sep 17 00:00:00 2001 From: Andrew Seigner Date: Sat, 23 Feb 2019 23:59:14 -0800 Subject: [PATCH] lint: Enable unparam unparam reports unused function parameters: https://github.com/mvdan/unparam Part of #217 Signed-off-by: Andrew Seigner --- .golangci.yml | 2 +- cli/cmd/install-cni-plugin_test.go | 4 +- cli/cmd/stat.go | 4 +- cli/cmd/stat_test.go | 2 +- cli/cmd/top.go | 5 +- .../api/destination/endpoints_watcher_test.go | 14 +++--- .../api/destination/k8s_resolver_test.go | 2 +- controller/api/destination/test_helper.go | 4 +- controller/api/public/client_test.go | 5 +- controller/api/public/proto_over_http.go | 9 ++-- controller/api/public/proto_over_http_test.go | 47 ++++--------------- controller/api/public/stat_summary.go | 6 +-- controller/api/public/stat_summary_test.go | 38 +++++++-------- controller/api/public/top_routes.go | 11 ++--- controller/api/util/api_utils.go | 4 +- pkg/admin/admin.go | 8 ++-- pkg/version/channels.go | 4 +- pkg/version/channels_test.go | 2 +- 18 files changed, 66 insertions(+), 105 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fdf70471ba35a..4c2400d03b0bc 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,6 +25,7 @@ linters: - scopelint - typecheck - unconvert + - unparam - unused - varcheck # TODO: enable more linters! @@ -38,7 +39,6 @@ linters: # - maligned # - prealloc # - stylecheck - # - unparam disable: - errcheck - staticcheck diff --git a/cli/cmd/install-cni-plugin_test.go b/cli/cmd/install-cni-plugin_test.go index e3aab512a0734..c3dc263f0e943 100644 --- a/cli/cmd/install-cni-plugin_test.go +++ b/cli/cmd/install-cni-plugin_test.go @@ -69,7 +69,7 @@ func TestRenderCNIPlugin(t *testing.T) { for i, tc := range testCases { tc := tc // pin t.Run(fmt.Sprintf("%d: %s", i, tc.goldenFileName), func(t *testing.T) { - defer teardown(defaultControlPlaneNamespace, t) + defer teardown(defaultControlPlaneNamespace) controlPlaneNamespace = tc.namespace var buf bytes.Buffer @@ -84,6 +84,6 @@ func TestRenderCNIPlugin(t *testing.T) { controlPlaneNamespace = defaultControlPlaneNamespace } -func teardown(originalNamespace string, t *testing.T) { +func teardown(originalNamespace string) { controlPlaneNamespace = originalNamespace } diff --git a/cli/cmd/stat.go b/cli/cmd/stat.go index a83febc4637a8..4fdce494fdb12 100644 --- a/cli/cmd/stat.go +++ b/cli/cmd/stat.go @@ -130,7 +130,7 @@ If no resource name is specified, displays stats about all resources of the spec c := make(chan indexedResults, len(reqs)) for num, req := range reqs { go func(num int, req *pb.StatSummaryRequest) { - resp, err := requestStatsFromAPI(client, req, options) + resp, err := requestStatsFromAPI(client, req) rows := respToRows(resp) c <- indexedResults{num, rows, err} }(num, req) @@ -177,7 +177,7 @@ func respToRows(resp *pb.StatSummaryResponse) []*pb.StatTable_PodGroup_Row { return rows } -func requestStatsFromAPI(client pb.ApiClient, req *pb.StatSummaryRequest, options *statOptions) (*pb.StatSummaryResponse, error) { +func requestStatsFromAPI(client pb.ApiClient, req *pb.StatSummaryRequest) (*pb.StatSummaryResponse, error) { resp, err := client.StatSummary(context.Background(), req) if err != nil { return nil, fmt.Errorf("StatSummary API error: %v", err) diff --git a/cli/cmd/stat_test.go b/cli/cmd/stat_test.go index 030e8fa5921dd..46a0b456da517 100644 --- a/cli/cmd/stat_test.go +++ b/cli/cmd/stat_test.go @@ -148,7 +148,7 @@ func testStatCall(exp paramsExp, t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - resp, err := requestStatsFromAPI(mockClient, reqs[0], exp.options) + resp, err := requestStatsFromAPI(mockClient, reqs[0]) if err != nil { t.Fatalf("Unexpected error: %v", err) } diff --git a/cli/cmd/top.go b/cli/cmd/top.go index 6f85183ba7a88..08f4c0a7d869f 100644 --- a/cli/cmd/top.go +++ b/cli/cmd/top.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "os" "sort" "strconv" "strings" @@ -337,7 +336,7 @@ func newCmdTop() *cobra.Command { return err } - return getTrafficByResourceFromAPI(os.Stdout, cliPublicAPIClient(), req, table) + return getTrafficByResourceFromAPI(cliPublicAPIClient(), req, table) }, } @@ -363,7 +362,7 @@ func newCmdTop() *cobra.Command { return cmd } -func getTrafficByResourceFromAPI(w io.Writer, client pb.ApiClient, req *pb.TapByResourceRequest, table *topTable) error { +func getTrafficByResourceFromAPI(client pb.ApiClient, req *pb.TapByResourceRequest, table *topTable) error { rsp, err := client.TapByResource(context.Background(), req) if err != nil { return err diff --git a/controller/api/destination/endpoints_watcher_test.go b/controller/api/destination/endpoints_watcher_test.go index 237dbb7e4c1f7..7cfaeb758c0cb 100644 --- a/controller/api/destination/endpoints_watcher_test.go +++ b/controller/api/destination/endpoints_watcher_test.go @@ -101,9 +101,9 @@ status: serviceID{namespace: "ns", name: "name1"}: map[uint32]*servicePort{ 8989: { addresses: []*updateAddress{ - makeUpdateAddress("172.17.0.12", 8989, "ns", "name1-1"), - makeUpdateAddress("172.17.0.19", 8989, "ns", "name1-2"), - makeUpdateAddress("172.17.0.20", 8989, "ns", "name1-3"), + makeUpdateAddress("172.17.0.12", 8989, "name1-1"), + makeUpdateAddress("172.17.0.19", 8989, "name1-2"), + makeUpdateAddress("172.17.0.20", 8989, "name1-3"), }, targetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 8989}, endpoints: &corev1.Endpoints{ @@ -201,8 +201,8 @@ status: serviceID{namespace: "ns", name: "name1"}: map[uint32]*servicePort{ 8989: { addresses: []*updateAddress{ - makeUpdateAddress("10.233.66.239", 8990, "ns", "name1-f748fb6b4-hpwpw"), - makeUpdateAddress("10.233.88.244", 8990, "ns", "name1-f748fb6b4-6vcmw"), + makeUpdateAddress("10.233.66.239", 8990, "name1-f748fb6b4-hpwpw"), + makeUpdateAddress("10.233.88.244", 8990, "name1-f748fb6b4-6vcmw"), }, targetPort: intstr.IntOrString{Type: intstr.String, StrVal: ""}, endpoints: &corev1.Endpoints{ @@ -283,7 +283,7 @@ status: serviceID{namespace: "ns", name: "world"}: map[uint32]*servicePort{ 7778: { addresses: []*updateAddress{ - makeUpdateAddress("10.1.30.135", 7779, "ns", "world-575bf846b4-tp4hw"), + makeUpdateAddress("10.1.30.135", 7779, "world-575bf846b4-tp4hw"), }, targetPort: intstr.IntOrString{Type: intstr.String, StrVal: "app"}, endpoints: &corev1.Endpoints{ @@ -365,7 +365,7 @@ status: serviceID{namespace: "ns", name: "name1"}: map[uint32]*servicePort{ 8989: { addresses: []*updateAddress{ - makeUpdateAddress("172.17.0.25", 8989, "ns", "name1-3"), + makeUpdateAddress("172.17.0.25", 8989, "name1-3"), }, targetPort: intstr.IntOrString{Type: intstr.Int, IntVal: 8989}, endpoints: &corev1.Endpoints{ diff --git a/controller/api/destination/k8s_resolver_test.go b/controller/api/destination/k8s_resolver_test.go index 56c29b1ebd2d9..6660f76bc56c6 100644 --- a/controller/api/destination/k8s_resolver_test.go +++ b/controller/api/destination/k8s_resolver_test.go @@ -72,7 +72,7 @@ func TestGetState(t *testing.T) { serviceID{namespace: "ns", name: "name"}: map[uint32]*servicePort{ 8888: { addresses: []*updateAddress{ - makeUpdateAddress("10.1.30.135", 7779, "ns", "world-575bf846b4-tp4hw"), + makeUpdateAddress("10.1.30.135", 7779, "world-575bf846b4-tp4hw"), }, endpoints: &corev1.Endpoints{ ObjectMeta: metav1.ObjectMeta{ diff --git a/controller/api/destination/test_helper.go b/controller/api/destination/test_helper.go index 049ed1b8a0a95..258f805cabec1 100644 --- a/controller/api/destination/test_helper.go +++ b/controller/api/destination/test_helper.go @@ -112,13 +112,13 @@ func equalServicePorts(servicePorts1, servicePorts2 servicePorts) error { return nil } -func makeUpdateAddress(ipStr string, portNum uint32, ns string, name string) *updateAddress { +func makeUpdateAddress(ipStr string, portNum uint32, name string) *updateAddress { ip, _ := addr.ParseProxyIPV4(ipStr) return &updateAddress{ address: &proxyNet.TcpAddress{Ip: ip, Port: portNum}, pod: &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Namespace: ns, + Namespace: "ns", Name: name, }, }, diff --git a/controller/api/public/client_test.go b/controller/api/public/client_test.go index 2feea9ae5721d..9585926c18189 100644 --- a/controller/api/public/client_test.go +++ b/controller/api/public/client_test.go @@ -190,10 +190,7 @@ func bufferedReader(t *testing.T, msg proto.Message) *bufio.Reader { t.Fatalf("Unexpected error: %v", err) } - payload, err := serializeAsPayload(msgBytes) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } + payload := serializeAsPayload(msgBytes) return bufio.NewReader(bytes.NewReader(payload)) } diff --git a/controller/api/public/proto_over_http.go b/controller/api/public/proto_over_http.go index 9ce87e4e365b8..dfc262e34ca1c 100644 --- a/controller/api/public/proto_over_http.go +++ b/controller/api/public/proto_over_http.go @@ -89,10 +89,7 @@ func writeProtoToHTTPResponse(w http.ResponseWriter, msg proto.Message) error { return err } - fullPayload, err := serializeAsPayload(marshalledProtobufMessage) - if err != nil { - return err - } + fullPayload := serializeAsPayload(marshalledProtobufMessage) _, err = w.Write(fullPayload) return err } @@ -108,13 +105,13 @@ func newStreamingWriter(w http.ResponseWriter) (flushableResponseWriter, error) return flushableWriter, nil } -func serializeAsPayload(messageContentsInBytes []byte) ([]byte, error) { +func serializeAsPayload(messageContentsInBytes []byte) []byte { lengthOfThePayload := uint32(len(messageContentsInBytes)) messageLengthInBytes := make([]byte, numBytesForMessageLength) binary.LittleEndian.PutUint32(messageLengthInBytes, lengthOfThePayload) - return append(messageLengthInBytes, messageContentsInBytes...), nil + return append(messageLengthInBytes, messageContentsInBytes...) } func deserializePayloadFromReader(reader *bufio.Reader) ([]byte, error) { diff --git a/controller/api/public/proto_over_http_test.go b/controller/api/public/proto_over_http_test.go index 23f43b4f1ea99..0481690646136 100644 --- a/controller/api/public/proto_over_http_test.go +++ b/controller/api/public/proto_over_http_test.go @@ -248,11 +248,7 @@ func TestDeserializePayloadFromReader(t *testing.T) { t.Run("Can read message correctly based on payload size correct payload size to message", func(t *testing.T) { expectedMessage := "this is the message" - messageWithSize, err := serializeAsPayload([]byte(expectedMessage)) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - + messageWithSize := serializeAsPayload([]byte(expectedMessage)) messageWithSomeNoise := append(messageWithSize, []byte("this is noise and should not be read")...) actualMessage, err := deserializePayloadFromReader(bufio.NewReader(bytes.NewReader(messageWithSomeNoise))) @@ -276,15 +272,8 @@ func TestDeserializePayloadFromReader(t *testing.T) { expectedMessage2 = expectedMessage2 + fmt.Sprintf("tum (%d), ", i) } - messageWithSize1, err := serializeAsPayload([]byte(expectedMessage1)) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - - messageWithSize2, err := serializeAsPayload([]byte(expectedMessage2)) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } + messageWithSize1 := serializeAsPayload([]byte(expectedMessage1)) + messageWithSize2 := serializeAsPayload([]byte(expectedMessage2)) streamWithManyMessages := append(messageWithSize1, messageWithSize2...) reader := bufio.NewReader(bytes.NewReader(streamWithManyMessages)) @@ -320,10 +309,7 @@ func TestDeserializePayloadFromReader(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - serialized, err := serializeAsPayload(expectedReadArray) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } + serialized := serializeAsPayload(expectedReadArray) reader := bufio.NewReader(bytes.NewReader(serialized)) if err != nil { @@ -369,11 +355,7 @@ func TestDeserializePayloadFromReader(t *testing.T) { t.Fatalf("Test needs data larger than [%d] bytes, currently only [%d] bytes", goDefaultChunkSize, lengthOfInputData) } - payload, err := serializeAsPayload(expectedMessageAsBytes) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - + payload := serializeAsPayload(expectedMessageAsBytes) actualMessage, err := deserializePayloadFromReader(bufio.NewReader(bytes.NewReader(payload))) if err != nil { t.Fatalf("Unexpected error: %v", err) @@ -387,13 +369,9 @@ func TestDeserializePayloadFromReader(t *testing.T) { t.Run("Returns error when message has fewer bytes than declared message size", func(t *testing.T) { expectedMessage := "this is the message" - messageWithSize, err := serializeAsPayload([]byte(expectedMessage)) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - + messageWithSize := serializeAsPayload([]byte(expectedMessage)) messageMissingOneCharacter := messageWithSize[:len(expectedMessage)-1] - _, err = deserializePayloadFromReader(bufio.NewReader(bytes.NewReader(messageMissingOneCharacter))) + _, err := deserializePayloadFromReader(bufio.NewReader(bytes.NewReader(messageMissingOneCharacter))) if err == nil { t.Fatalf("Expecting error, got nothing") } @@ -454,11 +432,7 @@ func TestCheckIfResponseHasError(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - message, err := serializeAsPayload(protoInBytes) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - + message := serializeAsPayload(protoInBytes) response := &http.Response{ Header: make(http.Header), Body: ioutil.NopCloser(bytes.NewReader(message)), @@ -483,10 +457,7 @@ func TestCheckIfResponseHasError(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } - message, err := serializeAsPayload(protoInBytes) - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } + message := serializeAsPayload(protoInBytes) response := &http.Response{ Header: make(http.Header), diff --git a/controller/api/public/stat_summary.go b/controller/api/public/stat_summary.go index d8ed8fddec43c..86b83f105e1b5 100644 --- a/controller/api/public/stat_summary.go +++ b/controller/api/public/stat_summary.go @@ -442,8 +442,8 @@ func (s *grpcServer) getPodStats(obj runtime.Object) (*podStats, error) { } } - errors := checkContainerErrors(pod.Status.ContainerStatuses, k8s.ProxyContainerName) - errors = append(errors, checkContainerErrors(pod.Status.InitContainerStatuses, k8s.InitContainerName)...) + errors := checkContainerErrors(pod.Status.ContainerStatuses) + errors = append(errors, checkContainerErrors(pod.Status.InitContainerStatuses)...) if len(errors) > 0 { podErrors[pod.Name] = &pb.PodErrors{Errors: errors} @@ -466,7 +466,7 @@ func toPodError(container, image, reason, message string) *pb.PodErrors_PodError } } -func checkContainerErrors(containerStatuses []corev1.ContainerStatus, containerName string) []*pb.PodErrors_PodError { +func checkContainerErrors(containerStatuses []corev1.ContainerStatus) []*pb.PodErrors_PodError { errors := []*pb.PodErrors_PodError{} for _, st := range containerStatuses { if !st.Ready { diff --git a/controller/api/public/stat_summary_test.go b/controller/api/public/stat_summary_test.go index 6f47a8a7f37e7..5c21e38fbb787 100644 --- a/controller/api/public/stat_summary_test.go +++ b/controller/api/public/stat_summary_test.go @@ -19,13 +19,13 @@ type statSumExpected struct { expectedResponse pb.StatSummaryResponse // the stat response we expect } -func prometheusMetric(resName string, resType string, resNs string, classification string, isDst bool) model.Vector { +func prometheusMetric(resName string, resType string) model.Vector { return model.Vector{ - genPromSample(resName, resType, resNs, classification, isDst), + genPromSample(resName, resType, "emojivoto", false), } } -func genPromSample(resName string, resType string, resNs string, classification string, isDst bool) *model.Sample { +func genPromSample(resName string, resType string, resNs string, isDst bool) *model.Sample { labelName := model.LabelName(resType) namespaceLabel := model.LabelName("namespace") @@ -38,7 +38,7 @@ func genPromSample(resName string, resType string, resNs string, classification Metric: model.Metric{ labelName: model.LabelValue(resName), namespaceLabel: model.LabelValue(resNs), - "classification": model.LabelValue(classification), + "classification": model.LabelValue("success"), "tls": model.LabelValue("true"), }, Value: 123, @@ -185,7 +185,7 @@ status: phase: Completed `, }, - mockPromResponse: prometheusMetric("emoji", "deployment", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emoji", "deployment"), }, req: pb.StatSummaryRequest{ Selector: &pb.ResourceSelection{ @@ -261,7 +261,7 @@ status: phase: Completed `, }, - mockPromResponse: prometheusMetric("emoji", "daemonset", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emoji", "daemonset"), }, req: pb.StatSummaryRequest{ Selector: &pb.ResourceSelection{ @@ -356,7 +356,7 @@ status: phase: Running `, }, - mockPromResponse: prometheusMetric("redis", "statefulset", "emojivoto", success, false), + mockPromResponse: prometheusMetric("redis", "statefulset"), }, req: pb.StatSummaryRequest{ Selector: &pb.ResourceSelection{ @@ -397,7 +397,7 @@ status: phase: Running `, }, - mockPromResponse: prometheusMetric("emojivoto-1", "pod", "emojivoto", "success", false), + mockPromResponse: prometheusMetric("emojivoto-1", "pod"), expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="inbound", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, `histogram_quantile(0.95, sum(irate(response_latency_ms_bucket{direction="inbound", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, @@ -448,7 +448,7 @@ status: phase: Running `, }, - mockPromResponse: prometheusMetric("emojivoto-1", "pod", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emojivoto-1", "pod"), expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="inbound", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, `histogram_quantile(0.95, sum(irate(response_latency_ms_bucket{direction="inbound", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, @@ -495,7 +495,7 @@ status: phase: Running `, }, - mockPromResponse: prometheusMetric("emojivoto-2", "pod", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emojivoto-2", "pod"), expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="outbound", dst_namespace="emojivoto", dst_pod="emojivoto-1", namespace="emojivoto", pod="emojivoto-2"}[1m])) by (le, dst_namespace, dst_pod))`, `histogram_quantile(0.95, sum(irate(response_latency_ms_bucket{direction="outbound", dst_namespace="emojivoto", dst_pod="emojivoto-1", namespace="emojivoto", pod="emojivoto-2"}[1m])) by (le, dst_namespace, dst_pod))`, @@ -546,7 +546,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("emojivoto-1", "pod", "emojivoto", success, false), + genPromSample("emojivoto-1", "pod", "emojivoto", false), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="outbound", dst_namespace="emojivoto", dst_pod="emojivoto-2", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, @@ -602,7 +602,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("emojivoto-1", "pod", "emojivoto", success, false), + genPromSample("emojivoto-1", "pod", "emojivoto", false), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="outbound", dst_namespace="totallydifferent", dst_pod="emojivoto-2", namespace="emojivoto", pod="emojivoto-1"}[1m])) by (le, namespace, pod))`, @@ -669,7 +669,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("emojivoto-1", "pod", "emojivoto", success, true), + genPromSample("emojivoto-1", "pod", "emojivoto", true), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="outbound", pod="emojivoto-2"}[1m])) by (le, dst_namespace, dst_pod))`, @@ -736,7 +736,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("emojivoto-1", "pod", "emojivoto", success, true), + genPromSample("emojivoto-1", "pod", "emojivoto", true), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="outbound", dst_namespace="emojivoto", dst_pod="emojivoto-1", namespace="totallydifferent", pod="emojivoto-2"}[1m])) by (le, dst_namespace, dst_pod))`, @@ -827,7 +827,7 @@ status: phase: Running `, }, - mockPromResponse: prometheusMetric("emoji-deploy", "deployment", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emoji-deploy", "deployment"), }, req: pb.StatSummaryRequest{ Selector: &pb.ResourceSelection{ @@ -1248,7 +1248,7 @@ metadata: status: phase: Succeeded `}, - mockPromResponse: prometheusMetric("emoji", "deployment", "emojivoto", success, false), + mockPromResponse: prometheusMetric("emoji", "deployment"), }, req: pb.StatSummaryRequest{ Selector: &pb.ResourceSelection{ @@ -1290,7 +1290,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("10.1.1.239:9995", "authority", "linkerd", success, false), + genPromSample("10.1.1.239:9995", "authority", "linkerd", false), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{direction="inbound", namespace="linkerd"}[1m])) by (le, namespace, authority))`, @@ -1334,7 +1334,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("10.1.1.239:9995", "authority", "linkerd", success, false), + genPromSample("10.1.1.239:9995", "authority", "linkerd", false), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{deployment="emojivoto", direction="outbound"}[1m])) by (le, dst_namespace, authority))`, @@ -1385,7 +1385,7 @@ status: `, }, mockPromResponse: model.Vector{ - genPromSample("10.1.1.239:9995", "authority", "linkerd", success, false), + genPromSample("10.1.1.239:9995", "authority", "linkerd", false), }, expectedPrometheusQueries: []string{ `histogram_quantile(0.5, sum(irate(response_latency_ms_bucket{authority="10.1.1.239:9995", direction="inbound", namespace="linkerd"}[1m])) by (le, namespace, authority))`, diff --git a/controller/api/public/top_routes.go b/controller/api/public/top_routes.go index e10ebb6204420..d21dd1d71c0cb 100644 --- a/controller/api/public/top_routes.go +++ b/controller/api/public/top_routes.go @@ -233,10 +233,7 @@ func (s *grpcServer) getRouteMetrics(ctx context.Context, req *pb.TopRoutesReque dsts = append(dsts, p.GetName()) } - reqLabels, err := s.buildRouteLabels(req, dsts, resource) - if err != nil { - return nil, err - } + reqLabels := s.buildRouteLabels(req, dsts, resource) groupBy := "rt_route" queries := map[promType]string{ @@ -284,7 +281,7 @@ func (s *grpcServer) getRouteMetrics(ctx context.Context, req *pb.TopRoutesReque return table, nil } -func (s *grpcServer) buildRouteLabels(req *pb.TopRoutesRequest, dsts []string, resource *pb.Resource) (string, error) { +func (s *grpcServer) buildRouteLabels(req *pb.TopRoutesRequest, dsts []string, resource *pb.Resource) string { // labels: the labels for the resource we want to query for var labels model.LabelSet @@ -293,12 +290,12 @@ func (s *grpcServer) buildRouteLabels(req *pb.TopRoutesRequest, dsts []string, r case *pb.TopRoutesRequest_ToResource: labels = labels.Merge(promQueryLabels(resource)) labels = labels.Merge(promDirectionLabels("outbound")) - return renderLabels(labels, dsts), nil + return renderLabels(labels, dsts) default: labels = labels.Merge(promDirectionLabels("inbound")) labels = labels.Merge(promQueryLabels(resource)) - return renderLabels(labels, dsts), nil + return renderLabels(labels, dsts) } } diff --git a/controller/api/util/api_utils.go b/controller/api/util/api_utils.go index 9b4ffae1898ef..ee4f6157fa2cf 100644 --- a/controller/api/util/api_utils.go +++ b/controller/api/util/api_utils.go @@ -332,7 +332,7 @@ func BuildResources(namespace string, args []string) ([]pb.Resource, error) { } func parseResources(namespace string, resType string, args []string) ([]pb.Resource, error) { - if err := validateResources(resType, args); err != nil { + if err := validateResources(args); err != nil { return nil, err } resources := make([]pb.Resource, 0) @@ -346,7 +346,7 @@ func parseResources(namespace string, resType string, args []string) ([]pb.Resou return resources, nil } -func validateResources(resType string, args []string) error { +func validateResources(args []string) error { set := make(map[string]bool) all := false for _, arg := range args { diff --git a/pkg/admin/admin.go b/pkg/admin/admin.go index 38ce24623c4f9..965071f7b15d4 100644 --- a/pkg/admin/admin.go +++ b/pkg/admin/admin.go @@ -35,18 +35,18 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { case "/metrics": h.promHandler.ServeHTTP(w, req) case "/ping": - h.servePing(w, req) + h.servePing(w) case "/ready": - h.serveReady(w, req) + h.serveReady(w) default: http.NotFound(w, req) } } -func (h *handler) servePing(w http.ResponseWriter, req *http.Request) { +func (h *handler) servePing(w http.ResponseWriter) { w.Write([]byte("pong\n")) } -func (h *handler) serveReady(w http.ResponseWriter, req *http.Request) { +func (h *handler) serveReady(w http.ResponseWriter) { w.Write([]byte("ok\n")) } diff --git a/pkg/version/channels.go b/pkg/version/channels.go index aeb98a90a91e0..f72bfdd7b3f59 100644 --- a/pkg/version/channels.go +++ b/pkg/version/channels.go @@ -60,10 +60,10 @@ func (c Channels) Match(actualVersion string) error { // release channels. func GetLatestVersions(ctx context.Context, uuid string, source string) (Channels, error) { url := fmt.Sprintf(versionCheckURL, Version, uuid, source) - return getLatestVersions(ctx, http.DefaultClient, url, uuid, source) + return getLatestVersions(ctx, http.DefaultClient, url) } -func getLatestVersions(ctx context.Context, client *http.Client, url string, uuid string, source string) (Channels, error) { +func getLatestVersions(ctx context.Context, client *http.Client, url string) (Channels, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return Channels{}, err diff --git a/pkg/version/channels_test.go b/pkg/version/channels_test.go index d42788419f883..2c853244c5cfc 100644 --- a/pkg/version/channels_test.go +++ b/pkg/version/channels_test.go @@ -73,7 +73,7 @@ func TestGetLatestVersions(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - latest, err := getLatestVersions(ctx, ts.Client(), ts.URL, "uuid", "source") + latest, err := getLatestVersions(ctx, ts.Client(), ts.URL) if (err == nil && tc.err != nil) || (err != nil && tc.err == nil) || ((err != nil && tc.err != nil) && (err.Error() != tc.err.Error())) {