mirror of https://github.com/linkerd/linkerd2.git
lint: Enable unparam (#2369)
unparam reports unused function parameters: https://github.com/mvdan/unparam Part of #217 Signed-off-by: Andrew Seigner <siggy@buoyant.io>
This commit is contained in:
parent
10d9b7e493
commit
9f748d2d2e
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
@ -1246,7 +1246,7 @@ metadata:
|
|||
status:
|
||||
phase: Succeeded
|
||||
`},
|
||||
mockPromResponse: prometheusMetric("emoji", "deployment", "emojivoto", success, false),
|
||||
mockPromResponse: prometheusMetric("emoji", "deployment"),
|
||||
},
|
||||
req: pb.StatSummaryRequest{
|
||||
Selector: &pb.ResourceSelection{
|
||||
|
|
@ -1288,7 +1288,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))`,
|
||||
|
|
@ -1332,7 +1332,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))`,
|
||||
|
|
@ -1383,7 +1383,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))`,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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())) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue